mittsu 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/mittsu.rb +8 -0
  4. data/lib/mittsu/core/face3.rb +1 -1
  5. data/lib/mittsu/core/geometry.rb +0 -4
  6. data/lib/mittsu/core/object_3d.rb +7 -6
  7. data/lib/mittsu/extras/helpers/camera_helper.rb +2 -2
  8. data/lib/mittsu/materials/material.rb +0 -4
  9. data/lib/mittsu/renderers/opengl/core/{opengl_geometry.rb → geometry.rb} +23 -32
  10. data/lib/mittsu/renderers/opengl/core/{opengl_object_3d.rb → object_3d.rb} +20 -24
  11. data/lib/mittsu/renderers/opengl/lights/{opengl_ambient_light.rb → ambient_light.rb} +4 -4
  12. data/lib/mittsu/renderers/opengl/lights/{opengl_directional_light.rb → directional_light.rb} +4 -4
  13. data/lib/mittsu/renderers/opengl/lights/{opengl_hemisphere_light.rb → hemisphere_light.rb} +4 -7
  14. data/lib/mittsu/renderers/opengl/lights/light.rb +55 -0
  15. data/lib/mittsu/renderers/opengl/lights/{opengl_point_light.rb → point_light.rb} +5 -5
  16. data/lib/mittsu/renderers/opengl/lights/{opengl_spot_light.rb → spot_light.rb} +8 -8
  17. data/lib/mittsu/renderers/opengl/materials/{opengl_line_basic_material.rb → line_basic_material.rb} +3 -3
  18. data/lib/mittsu/renderers/opengl/materials/{opengl_material.rb → material.rb} +55 -56
  19. data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +21 -0
  20. data/lib/mittsu/renderers/opengl/materials/{opengl_mesh_lambert_material.rb → mesh_lambert_material.rb} +9 -5
  21. data/lib/mittsu/renderers/opengl/materials/{opengl_mesh_phong_material.rb → mesh_phong_material.rb} +11 -7
  22. data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +57 -0
  23. data/lib/mittsu/renderers/opengl/materials/{opengl_shader_material.rb → shader_material.rb} +1 -1
  24. data/lib/mittsu/renderers/opengl/objects/group.rb +9 -0
  25. data/lib/mittsu/renderers/opengl/objects/line.rb +45 -0
  26. data/lib/mittsu/renderers/opengl/objects/{opengl_mesh.rb → mesh.rb} +15 -22
  27. data/lib/mittsu/renderers/opengl/opengl_buffer.rb +4 -0
  28. data/lib/mittsu/renderers/opengl/opengl_debug.rb +5 -4
  29. data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -4
  30. data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +2 -8
  31. data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +2 -1
  32. data/lib/mittsu/renderers/opengl/opengl_implementations.rb +24 -53
  33. data/lib/mittsu/renderers/opengl/opengl_lib.rb +62 -0
  34. data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +6 -6
  35. data/lib/mittsu/renderers/opengl/opengl_program.rb +3 -5
  36. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +11 -12
  37. data/lib/mittsu/renderers/opengl/scenes/scene.rb +9 -0
  38. data/lib/mittsu/renderers/opengl/textures/{opengl_compressed_texture.rb → compressed_texture.rb} +5 -6
  39. data/lib/mittsu/renderers/opengl/textures/{opengl_cube_texture.rb → cube_texture.rb} +23 -21
  40. data/lib/mittsu/renderers/opengl/textures/{opengl_data_texture.rb → data_texture.rb} +3 -5
  41. data/lib/mittsu/renderers/opengl/textures/{opengl_texture.rb → texture.rb} +29 -33
  42. data/lib/mittsu/renderers/opengl_render_target.rb +5 -6
  43. data/lib/mittsu/renderers/opengl_renderer.rb +35 -44
  44. data/lib/mittsu/textures/texture.rb +0 -4
  45. data/lib/mittsu/version.rb +1 -1
  46. metadata +26 -24
  47. data/lib/mittsu/renderers/opengl/lights/opengl_light.rb +0 -52
  48. data/lib/mittsu/renderers/opengl/materials/opengl_mesh_basic_material.rb +0 -69
  49. data/lib/mittsu/renderers/opengl/objects/opengl_group.rb +0 -8
  50. data/lib/mittsu/renderers/opengl/objects/opengl_line.rb +0 -54
  51. data/lib/mittsu/renderers/opengl/scenes/opengl_scene.rb +0 -8
@@ -0,0 +1,9 @@
1
+ module Mittsu
2
+ class Scene
3
+ def project(renderer)
4
+ @renderer = renderer
5
+ return unless visible
6
+ project_children
7
+ end
8
+ end
9
+ end
@@ -1,16 +1,15 @@
1
1
  module Mittsu
2
- class OpenGLCompressedTexture < OpenGLTexture
2
+ class CompressedTexture
3
3
  def update_specific
4
- gl_format = GL_MITTSU_PARAMS[@texture.format]
5
- gl_type = GL_MITTSU_PARAMS[@texture.type]
6
- mipmaps = @texture.mipmaps
4
+ gl_format = GL_MITTSU_PARAMS[format]
5
+ gl_type = GL_MITTSU_PARAMS[type]
7
6
 
8
7
  mipmaps.each_with_index do |mipmap, i|
9
- if @texture.format != RGBAFormat && @texture.format != RGBFormat
8
+ if format != RGBAFormat && format != RGBFormat
10
9
  if @renderer.compressed_texture_formats.include?(gl_format)
11
10
  glCompressedTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, mipmap.data)
12
11
  else
13
- puts 'WARNING: Mittsu::OpenGLTexture: Attempt to load unsupported compressed texture format in #update_texture'
12
+ puts 'WARNING: Mittsu::Texture: Attempt to load unsupported compressed texture format in #update_texture'
14
13
  end
15
14
  else
16
15
  glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
@@ -1,36 +1,38 @@
1
1
  module Mittsu
2
- class OpenGLCubeTexture < OpenGLTexture
3
- def set(slot)
4
- if @texture.image.length == 6
5
- if @texture.needs_update?
6
- if !@texture.image[:_opengl_texture_cube]
7
- @texture.add_event_listener(:dispose, @renderer.method(:on_texture_dispose))
8
- @texture.image[:_opengl_texture_cube] = glCreateTexture
2
+ class CubeTexture
3
+ def set(slot, renderer)
4
+ @renderer = renderer
5
+
6
+ if image.length == 6
7
+ if needs_update?
8
+ if !image[:_opengl_texture_cube]
9
+ add_event_listener(:dispose, @renderer.method(:on_texture_dispose))
10
+ image[:_opengl_texture_cube] = glCreateTexture
9
11
  @renderer.info[:memory][:textures] += 1
10
12
  end
11
13
 
12
14
  glActiveTexture(GL_TEXTURE0 + slot)
13
- glBindTexture(GL_TEXTURE_CUBE_MAP, @texture.image[:_opengl_texture_cube])
15
+ glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube])
14
16
 
15
17
  # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, texture.flip_y)
16
18
 
17
- is_compressed = @texture.is_a?(CompressedTexture)
18
- is_data_texture = @texture.image[0].is_a?(DataTexture)
19
+ is_compressed = is_a?(CompressedTexture)
20
+ is_data_texture = image[0].is_a?(DataTexture)
19
21
 
20
22
  cube_image = [];
21
23
 
22
24
  6.times do |i|
23
25
  if @auto_scale_cubemaps && !is_compressed && !is_data_texture
24
- cube_image[i] = clamp_to_max_size(@texture.image[i], @_max_cubemap_size)
26
+ cube_image[i] = clamp_to_max_size(image[i], @_max_cubemap_size)
25
27
  else
26
- cube_image[i] = is_data_texture ? @texture.image[i].image : @texture.image[i];
28
+ cube_image[i] = is_data_texture ? image[i].image : image[i];
27
29
  end
28
30
  end
29
31
 
30
- image = cube_image[0]
31
- is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
32
- gl_format = GL_MITTSU_PARAMS[@texture.format]
33
- gl_type = GL_MITTSU_PARAMS[@texture.type]
32
+ img = cube_image[0]
33
+ is_image_power_of_two = Math.power_of_two?(img.width) && Math.power_of_two?(img.height)
34
+ gl_format = GL_MITTSU_PARAMS[format]
35
+ gl_type = GL_MITTSU_PARAMS[type]
34
36
 
35
37
  set_parameters(GL_TEXTURE_CUBE_MAP, is_image_power_of_two)
36
38
 
@@ -45,7 +47,7 @@ module Mittsu
45
47
  mipmaps = cube_image[i].mipmaps
46
48
 
47
49
  mipmaps.each_with_index do |mipmap, j|
48
- if @texture.format != RGBAFormat && @texture.format != RGBFormat
50
+ if format != RGBAFormat && format != RGBFormat
49
51
  if @renderer.compressed_texture_formats.include?(gl_format)
50
52
  glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, mipmap.data)
51
53
  else
@@ -58,16 +60,16 @@ module Mittsu
58
60
  end
59
61
  end
60
62
 
61
- if @texture.generate_mipmaps && is_image_power_of_two
63
+ if generate_mipmaps && is_image_power_of_two
62
64
  glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
63
65
  end
64
66
 
65
- @texture.needs_update = false
67
+ self.needs_update = false
66
68
 
67
- @texture.on_update.call if @texture.on_update
69
+ on_update.call if on_update
68
70
  else
69
71
  glActiveTexture(GL_TEXTURE0 + slot)
70
- glBindTexture(GL_TEXTURE_CUBE_MAP, @texture.image[:_opengl_texture_cube])
72
+ glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube])
71
73
  end
72
74
  end
73
75
  end
@@ -1,10 +1,8 @@
1
1
  module Mittsu
2
- class OpenGLDataTexture < OpenGLTexture
2
+ class DataTexture
3
3
  def update_specific
4
- gl_format = GL_MITTSU_PARAMS[@texture.format]
5
- gl_type = GL_MITTSU_PARAMS[@texture.type]
6
- mipmaps = @texture.mipmaps
7
- image = @texture.image
4
+ gl_format = GL_MITTSU_PARAMS[format]
5
+ gl_type = GL_MITTSU_PARAMS[type]
8
6
  is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
9
7
 
10
8
  # use manually created mipmaps if available
@@ -1,38 +1,36 @@
1
1
  module Mittsu
2
- class OpenGLTexture
2
+ class Texture
3
3
  attr_reader :opengl_texture
4
4
 
5
- def initialize(texture, renderer)
6
- @texture = texture
5
+ def set(slot, renderer)
7
6
  @renderer = renderer
8
- @initted = false
9
- end
10
7
 
11
- def set(slot)
12
8
  glActiveTexture(GL_TEXTURE0 + slot)
13
9
 
14
- if @texture.needs_update?
15
- update
10
+ if needs_update?
11
+ update_opengl(@renderer)
16
12
  else
17
13
  glBindTexture(GL_TEXTURE_2D, @opengl_texture)
18
14
  end
19
15
  end
20
16
 
21
- def update
17
+ def update_opengl(renderer)
18
+ @renderer = renderer
19
+
22
20
  if !@initted
23
21
  @initted = true
24
- @texture.add_event_listener(:dispose, @renderer.method(:on_texture_dispose))
22
+ add_event_listener(:dispose, @renderer.method(:on_texture_dispose))
25
23
  @opengl_texture = glCreateTexture
26
24
  @renderer.info[:memory][:textures] += 1
27
25
  end
28
26
 
29
27
  glBindTexture(GL_TEXTURE_2D, @opengl_texture)
30
28
 
31
- # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, texture.flip_y) ???
32
- # glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiply_alpha) ???
33
- glPixelStorei(GL_UNPACK_ALIGNMENT, @texture.unpack_alignment)
29
+ # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, flip_y) ???
30
+ # glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiply_alpha) ???
31
+ glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment)
34
32
 
35
- image = @texture.image = @renderer.clamp_to_max_size(@texture.image)
33
+ self.image = @renderer.clamp_to_max_size(image)
36
34
 
37
35
  is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
38
36
 
@@ -40,37 +38,37 @@ module Mittsu
40
38
 
41
39
  update_specific
42
40
 
43
- if @texture.generate_mipmaps && is_image_power_of_two
41
+ if generate_mipmaps && is_image_power_of_two
44
42
  glGenerateMipmap(GL_TEXTURE_2D)
45
43
  end
46
44
 
47
- @texture.needs_update = false
45
+ self.needs_update = false
48
46
 
49
- @texture.on_update.call if @texture.on_update
47
+ on_update.call if on_update
50
48
  end
51
49
 
52
50
  protected
53
51
 
54
52
  def set_parameters(texture_type, is_image_power_of_two)
55
53
  if is_image_power_of_two
56
- glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_MITTSU_PARAMS[@texture.wrap_s])
57
- glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_MITTSU_PARAMS[@texture.wrap_t])
54
+ glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_MITTSU_PARAMS[wrap_s])
55
+ glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_MITTSU_PARAMS[wrap_t])
58
56
 
59
- glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_MITTSU_PARAMS[@texture.mag_filter])
60
- glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_MITTSU_PARAMS[@texture.min_filter])
57
+ glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, GL_MITTSU_PARAMS[mag_filter])
58
+ glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_MITTSU_PARAMS[min_filter])
61
59
  else
62
60
  glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
63
61
  glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
64
62
 
65
- if @texture.wrap_s != ClampToEdgeWrapping || @texture.wrap_t != ClampToEdgeWrapping
66
- puts "WARNING: Mittsu::OpenGLTexture: Texture is not power of two. Texture.wrap_s and Texture.wrap_t should be set to Mittsu::ClampToEdgeWrapping. (#{texture.source_file})"
63
+ if wrap_s != ClampToEdgeWrapping || wrap_t != ClampToEdgeWrapping
64
+ puts "WARNING: Mittsu::Texture: Texture is not power of two. Texture.wrap_s and Texture.wrap_t should be set to Mittsu::ClampToEdgeWrapping. (#{texture.source_file})"
67
65
  end
68
66
 
69
- glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter_fallback(@texture.mag_filter))
70
- glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(@texture.min_filter))
67
+ glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter_fallback(mag_filter))
68
+ glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(min_filter))
71
69
 
72
- if @texture.min_filter != NearestFilter && @texture.min_filter != LinearFilter
73
- puts "WARNING: Mittsu::OpenGLTexture: Texture is not a power of two. Texture.min_filter should be set to Mittsu::NearestFilter or Mittsu::LinearFilter. (#{texture.source_file})"
70
+ if min_filter != NearestFilter && min_filter != LinearFilter
71
+ puts "WARNING: Mittsu::Texture: Texture is not a power of two. Texture.min_filter should be set to Mittsu::NearestFilter or Mittsu::LinearFilter. (#{texture.source_file})"
74
72
  end
75
73
 
76
74
  # TODO: anisotropic extension ???
@@ -87,10 +85,8 @@ module Mittsu
87
85
  end
88
86
 
89
87
  def update_specific
90
- gl_format = GL_MITTSU_PARAMS[@texture.format]
91
- gl_type = GL_MITTSU_PARAMS[@texture.type]
92
- mipmaps = @texture.mipmaps
93
- image = @texture.image
88
+ gl_format = GL_MITTSU_PARAMS[format]
89
+ gl_type = GL_MITTSU_PARAMS[type]
94
90
  is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
95
91
 
96
92
  # use manually created mipmaps if available
@@ -102,9 +98,9 @@ module Mittsu
102
98
  glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
103
99
  end
104
100
 
105
- @texture.generate_mipmaps = false
101
+ self.generate_mipmaps = false
106
102
  else
107
- glTexImage2D(GL_TEXTURE_2D, 0, gl_format, @texture.image.width, @texture.image.height, 0, gl_format, gl_type, @texture.image.data)
103
+ glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data)
108
104
  end
109
105
  end
110
106
  end
@@ -1,5 +1,5 @@
1
1
  module Mittsu
2
- class OpenGLRenderTarget < OpenGLTexture
2
+ class OpenGLRenderTarget < Texture
3
3
  include EventDispatcher
4
4
 
5
5
  attr_accessor :width,
@@ -20,6 +20,8 @@ module Mittsu
20
20
 
21
21
  attr_reader :framebuffer
22
22
 
23
+ attr_writer :renderer
24
+
23
25
  def initialize(width, height, options = {})
24
26
  super(self, nil)
25
27
 
@@ -59,6 +61,8 @@ module Mittsu
59
61
 
60
62
  def clone
61
63
  OpenGLRenderTarget.new(@width, @height).tap do |tmp|
64
+ tmp.renderer = @renderer
65
+
62
66
  tmp.wrap_s = @wrap_s
63
67
  tmp.wrap_t = @wrap_t
64
68
 
@@ -155,11 +159,6 @@ module Mittsu
155
159
  dispatch_event(type: :dispose)
156
160
  end
157
161
 
158
- def implementation(renderer)
159
- @renderer = renderer
160
- self
161
- end
162
-
163
162
  def update_mipmap
164
163
  return if !@generate_mipmaps || @min_filter == NearestFilter || @min_filter == LinearFilter
165
164
  # TODO: when OpenGLRenderTargetCube exists
@@ -2,7 +2,10 @@ require 'opengl'
2
2
  require 'glfw'
3
3
  require 'fiddle'
4
4
 
5
- OpenGL.load_lib
5
+
6
+ require 'mittsu/renderers/opengl/opengl_lib'
7
+ opengl_lib = OpenGLLib.discover
8
+ OpenGL.load_lib(opengl_lib.file, opengl_lib.path)
6
9
 
7
10
  require 'mittsu'
8
11
  require 'mittsu/renderers/glfw_window'
@@ -185,10 +188,8 @@ module Mittsu
185
188
  # TODO: when OpenGLRenderTargetCube exists
186
189
  # is_cube = render_target.is_a? OpenGLRenderTargetCube
187
190
 
188
- render_target_impl = render_target.implementation(self)
189
-
190
191
  # TODO framebuffer logic for render target cube
191
- render_target_impl.setup_buffers
192
+ render_target.setup_buffers
192
193
 
193
194
  if render_target != @_current_render_target
194
195
  render_target.use
@@ -207,7 +208,7 @@ module Mittsu
207
208
  update_skeleton_objects(scene)
208
209
 
209
210
  update_screen_projection(camera)
210
- scene.implementation(self).project
211
+ scene.project(self)
211
212
  sort_objects_for_render if @sort_objects
212
213
 
213
214
  render_custom_plugins_pre_pass(scene, camera)
@@ -220,7 +221,7 @@ module Mittsu
220
221
 
221
222
  render_custom_plugins_post_pass(scene, camera)
222
223
 
223
- render_target.implementation(self).update_mipmap
224
+ render_target.update_mipmap
224
225
 
225
226
  ensure_depth_buffer_writing
226
227
  end
@@ -231,8 +232,10 @@ module Mittsu
231
232
  end
232
233
 
233
234
  def render_buffer(camera, lights, fog, material, geometry_group, object)
235
+ puts "--- RENDER #{object.name}" if DEBUG
234
236
  return unless material.visible
235
237
 
238
+ geometry_group.renderer = self
236
239
  geometry_group.bind_vertex_array_object
237
240
 
238
241
  update_object(object)
@@ -256,7 +259,7 @@ module Mittsu
256
259
 
257
260
  @state.disable_unused_attributes
258
261
 
259
- object.implementation(self).render_buffer(camera, lights, fog, material, geometry_group, buffers_need_update)
262
+ object.render_buffer(camera, lights, fog, material, geometry_group, buffers_need_update)
260
263
 
261
264
  # TODO: render particles
262
265
  # when PointCloud
@@ -308,10 +311,6 @@ module Mittsu
308
311
  deallocate_material(material)
309
312
  end
310
313
 
311
- def create_implementation(thing)
312
- OPENGL_IMPLEMENTATIONS[thing.class].new(thing, self)
313
- end
314
-
315
314
  def clamp_to_max_size(image, max_size = @_max_texture_size)
316
315
  width, height = image.width, image.height
317
316
  if width > max_size || height > max_size
@@ -364,19 +363,18 @@ module Mittsu
364
363
  def render_objects(render_list, camera, lights, fog, override_material)
365
364
  material = nil
366
365
  render_list.each do |opengl_object|
366
+ puts "-- RENDER_OBJECT #{opengl_object.name}" if DEBUG
367
367
  object = opengl_object.object
368
368
  buffer = opengl_object.buffer
369
369
 
370
- object.implementation(self).setup_matrices(camera)
370
+ object.setup_matrices(camera)
371
371
 
372
372
  if override_material
373
373
  material = override_material
374
- material_impl = material.implementation(self)
375
374
  else
376
375
  material = opengl_object.material
377
376
  next unless material
378
- material_impl = material.implementation(self)
379
- material_impl.set
377
+ material.set(self)
380
378
  end
381
379
 
382
380
  set_material_faces(material)
@@ -384,7 +382,8 @@ module Mittsu
384
382
  # TODO
385
383
  # render_buffer_direct(camera, lights, fog, material, buffer, object)
386
384
  else
387
- render_buffer(camera, lights, fog, material, buffer.implementation(self), object)
385
+ puts "-- RENDER COLOR #{material.color}" if DEBUG
386
+ render_buffer(camera, lights, fog, material, buffer, object)
388
387
  end
389
388
  end
390
389
  end
@@ -403,8 +402,7 @@ module Mittsu
403
402
  else nil
404
403
  end
405
404
  next unless material
406
- material_impl = material.implementation(self)
407
- material_impl.set
405
+ material.set(self)
408
406
  end
409
407
  render_immediate_object(camera, lights, fog, material, object)
410
408
  end
@@ -439,6 +437,7 @@ module Mittsu
439
437
  material = object.material
440
438
 
441
439
  if material
440
+ puts "--- UNROLL #{opengl_object.name}" if DEBUG
442
441
  if material.is_a? MeshFaceMaterial
443
442
  material_index = geometry.is_a?(BufferGeometry) ? 0 : buffer.material_index
444
443
  material = material.materials[material_index]
@@ -457,7 +456,6 @@ module Mittsu
457
456
  # FIXME: refactor
458
457
  def update_object(object)
459
458
  geometry = object.geometry
460
- object_impl = object.implementation(self)
461
459
 
462
460
  if geometry.is_a? BufferGeometry
463
461
  # TODO: geometry vertex array ?????
@@ -488,12 +486,12 @@ module Mittsu
488
486
  end
489
487
  end
490
488
  else
491
- object_impl.update
489
+ object.update
492
490
  end
493
491
  # TODO: when PointCloud exists
494
492
  # elsif object.is_A? PointCloud
495
493
  # # TODO: glBindVertexArray ???
496
- # material = object_impl.buffer_material(geometry)
494
+ # material = object.buffer_material(geometry)
497
495
  # custom_attributes_dirty = material.attributes && are_custom_attributes_dirty(material)
498
496
  #
499
497
  # if geometry.vertices_need_update || geometry.colors_need_update || custom_attributes_dirty
@@ -510,19 +508,16 @@ module Mittsu
510
508
  # FIXME: refactor
511
509
  def set_program(camera, lights, fog, material, object)
512
510
  @_used_texture_units = 0
513
- material_impl = material.implementation(self)
514
- object_impl = object.implementation(self)
515
-
516
511
  if material.needs_update?
517
512
  deallocate_material(material) if material.program
518
513
 
519
- material_impl.init(lights, fog, object)
514
+ material.init(lights, fog, object, self)
520
515
  material.needs_update = false
521
516
  end
522
517
 
523
518
  if material.morph_targets
524
- if !object_impl.morph_target_influences
525
- object_impl.morph_target_influences = Array.new(@max_morph_targets) # Float32Array
519
+ if !object.morph_target_influences
520
+ object.morph_target_influences = Array.new(@max_morph_targets) # Float32Array
526
521
  end
527
522
  end
528
523
 
@@ -532,7 +527,7 @@ module Mittsu
532
527
 
533
528
  program = material.program
534
529
  program_uniforms = program.uniforms
535
- material_uniforms = material_impl.shader[:uniforms]
530
+ material_uniforms = material.shader[:uniforms]
536
531
 
537
532
  if program.id != @_current_program
538
533
  glUseProgram(program.program)
@@ -570,7 +565,7 @@ module Mittsu
570
565
  # texture_unit = get_texture_unit
571
566
  #
572
567
  # glUniform1i(program_uniforms['boneTexture'], texture_unit)
573
- # object.skeleton.bone_texture.implementation(self).set(texture_unit)
568
+ # object.skeleton.bone_texture.set(texture_unit, self)
574
569
  # end
575
570
  #
576
571
  # if !program_uniforms['boneTextureWidth'].nil?
@@ -591,7 +586,7 @@ module Mittsu
591
586
  # TODO: when fog is implemented
592
587
  # refresh_uniforms_fog(material_uniforms, fog) if fog && material.fog
593
588
 
594
- if material_impl.needs_lights?
589
+ if material.needs_lights?
595
590
  if @light_renderer.lights_need_update
596
591
  refresh_lights = true
597
592
  @light_renderer.setup(lights)
@@ -604,7 +599,7 @@ module Mittsu
604
599
  OpenGLHelper.mark_uniforms_lights_needs_update(material_uniforms, refresh_lights)
605
600
  end
606
601
 
607
- material_impl.refresh_uniforms(material_uniforms)
602
+ material.refresh_uniforms(material_uniforms)
608
603
 
609
604
  # TODO: when all of these things exist
610
605
  # when LineDashedMaterial
@@ -619,14 +614,14 @@ module Mittsu
619
614
  # when MeshNormalMaterial
620
615
  # material_uniforms.opactity.value = material.opacity
621
616
 
622
- if object.receive_shadow && !material_impl.shadow_pass
617
+ if object.receive_shadow && !material.shadow_pass
623
618
  OpenGLHelper.refresh_uniforms_shadow(material_uniforms, lights)
624
619
  end
625
620
 
626
- load_uniforms_generic(material_impl.uniforms_list)
621
+ load_uniforms_generic(material.uniforms_list)
627
622
  end
628
623
 
629
- object.implementation(self).load_uniforms_matrices(program_uniforms)
624
+ object.load_uniforms_matrices(program_uniforms)
630
625
 
631
626
  if !program_uniforms['modelMatrix'].nil?
632
627
  glUniformMatrix4fv(program_uniforms['modelMatrix'], 1, GL_FALSE, array_to_ptr_easy(object.matrix_world.elements))
@@ -731,8 +726,7 @@ module Mittsu
731
726
 
732
727
  next unless texture
733
728
 
734
- texture_impl = texture.implementation(self)
735
- texture_impl.set(texture_unit)
729
+ texture.set(texture_unit, self)
736
730
  # TODO: when OpenGLRenderTargetCube is defined
737
731
  # elsif texture.is_a?(OpenGLRenderTargetCube)
738
732
  # set_cube_texture_dynamic(texture, texture_unit)
@@ -751,7 +745,7 @@ module Mittsu
751
745
 
752
746
  next unless tex
753
747
 
754
- tex.implementation(self).set(tex_unit)
748
+ tex.set(tex_unit, self)
755
749
  end
756
750
  else
757
751
  puts "WARNING: Mittsu::OpenGLRenderer: Unknown uniform type: #{type}"
@@ -821,7 +815,7 @@ module Mittsu
821
815
  object = opengl_object.object
822
816
 
823
817
  if object.visible
824
- object.implementation(self).setup_matrices(camera)
818
+ object.setup_matrices(camera)
825
819
  unroll_immediate_buffer_material(opengl_object)
826
820
  end
827
821
  end
@@ -837,9 +831,8 @@ module Mittsu
837
831
 
838
832
  def render_with_override_material(scene, camera)
839
833
  override_material = scene.override_material
840
- material_impl = override_material.implementation(self)
841
834
 
842
- material_impl.set
835
+ override_material.set(self)
843
836
 
844
837
  render_objects(@opaque_objects, camera, @lights, scene.fog, override_material)
845
838
  render_objects(@transparent_objects, camera, @lights, scene.fog, override_material)
@@ -1030,20 +1023,18 @@ module Mittsu
1030
1023
  end
1031
1024
 
1032
1025
  def update_camera_uniforms(uniforms, camera, material)
1033
- material_impl = material.implementation(self)
1034
-
1035
1026
  glUniformMatrix4fv(uniforms['projectionMatrix'], 1, GL_FALSE, array_to_ptr_easy(camera.projection_matrix.elements))
1036
1027
 
1037
1028
  if @logarithmic_depth_buffer
1038
1029
  glUniform1f(uniforms['logDepthBuffFC'], 2.0 / Math.log(camera.far + 1.0) / Math::LN2)
1039
1030
  end
1040
1031
 
1041
- if material_impl.needs_camera_position_uniform? && !uniforms['cameraPosition'].nil?
1032
+ if material.needs_camera_position_uniform? && !uniforms['cameraPosition'].nil?
1042
1033
  @_vector3.set_from_matrix_position(camera.matrix_world)
1043
1034
  glUniform3f(uniforms['cameraPosition'], @_vector3.x, @_vector3.y, @_vector3.z)
1044
1035
  end
1045
1036
 
1046
- if material_impl.needs_view_matrix_uniform? && !uniforms['viewMatrix'].nil?
1037
+ if material.needs_view_matrix_uniform? && !uniforms['viewMatrix'].nil?
1047
1038
  glUniformMatrix4fv(uniforms['viewMatrix'], 1, GL_FALSE, array_to_ptr_easy(camera.matrix_world_inverse.elements))
1048
1039
  end
1049
1040
  end