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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mittsu.rb +8 -0
- data/lib/mittsu/core/face3.rb +1 -1
- data/lib/mittsu/core/geometry.rb +0 -4
- data/lib/mittsu/core/object_3d.rb +7 -6
- data/lib/mittsu/extras/helpers/camera_helper.rb +2 -2
- data/lib/mittsu/materials/material.rb +0 -4
- data/lib/mittsu/renderers/opengl/core/{opengl_geometry.rb → geometry.rb} +23 -32
- data/lib/mittsu/renderers/opengl/core/{opengl_object_3d.rb → object_3d.rb} +20 -24
- data/lib/mittsu/renderers/opengl/lights/{opengl_ambient_light.rb → ambient_light.rb} +4 -4
- data/lib/mittsu/renderers/opengl/lights/{opengl_directional_light.rb → directional_light.rb} +4 -4
- data/lib/mittsu/renderers/opengl/lights/{opengl_hemisphere_light.rb → hemisphere_light.rb} +4 -7
- data/lib/mittsu/renderers/opengl/lights/light.rb +55 -0
- data/lib/mittsu/renderers/opengl/lights/{opengl_point_light.rb → point_light.rb} +5 -5
- data/lib/mittsu/renderers/opengl/lights/{opengl_spot_light.rb → spot_light.rb} +8 -8
- data/lib/mittsu/renderers/opengl/materials/{opengl_line_basic_material.rb → line_basic_material.rb} +3 -3
- data/lib/mittsu/renderers/opengl/materials/{opengl_material.rb → material.rb} +55 -56
- data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +21 -0
- data/lib/mittsu/renderers/opengl/materials/{opengl_mesh_lambert_material.rb → mesh_lambert_material.rb} +9 -5
- data/lib/mittsu/renderers/opengl/materials/{opengl_mesh_phong_material.rb → mesh_phong_material.rb} +11 -7
- data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +57 -0
- data/lib/mittsu/renderers/opengl/materials/{opengl_shader_material.rb → shader_material.rb} +1 -1
- data/lib/mittsu/renderers/opengl/objects/group.rb +9 -0
- data/lib/mittsu/renderers/opengl/objects/line.rb +45 -0
- data/lib/mittsu/renderers/opengl/objects/{opengl_mesh.rb → mesh.rb} +15 -22
- data/lib/mittsu/renderers/opengl/opengl_buffer.rb +4 -0
- data/lib/mittsu/renderers/opengl/opengl_debug.rb +5 -4
- data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -4
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +2 -8
- data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +2 -1
- data/lib/mittsu/renderers/opengl/opengl_implementations.rb +24 -53
- data/lib/mittsu/renderers/opengl/opengl_lib.rb +62 -0
- data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +6 -6
- data/lib/mittsu/renderers/opengl/opengl_program.rb +3 -5
- data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +11 -12
- data/lib/mittsu/renderers/opengl/scenes/scene.rb +9 -0
- data/lib/mittsu/renderers/opengl/textures/{opengl_compressed_texture.rb → compressed_texture.rb} +5 -6
- data/lib/mittsu/renderers/opengl/textures/{opengl_cube_texture.rb → cube_texture.rb} +23 -21
- data/lib/mittsu/renderers/opengl/textures/{opengl_data_texture.rb → data_texture.rb} +3 -5
- data/lib/mittsu/renderers/opengl/textures/{opengl_texture.rb → texture.rb} +29 -33
- data/lib/mittsu/renderers/opengl_render_target.rb +5 -6
- data/lib/mittsu/renderers/opengl_renderer.rb +35 -44
- data/lib/mittsu/textures/texture.rb +0 -4
- data/lib/mittsu/version.rb +1 -1
- metadata +26 -24
- data/lib/mittsu/renderers/opengl/lights/opengl_light.rb +0 -52
- data/lib/mittsu/renderers/opengl/materials/opengl_mesh_basic_material.rb +0 -69
- data/lib/mittsu/renderers/opengl/objects/opengl_group.rb +0 -8
- data/lib/mittsu/renderers/opengl/objects/opengl_line.rb +0 -54
- data/lib/mittsu/renderers/opengl/scenes/opengl_scene.rb +0 -8
data/lib/mittsu/renderers/opengl/textures/{opengl_compressed_texture.rb → compressed_texture.rb}
RENAMED
@@ -1,16 +1,15 @@
|
|
1
1
|
module Mittsu
|
2
|
-
class
|
2
|
+
class CompressedTexture
|
3
3
|
def update_specific
|
4
|
-
gl_format = GL_MITTSU_PARAMS[
|
5
|
-
gl_type = GL_MITTSU_PARAMS[
|
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
|
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::
|
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
|
3
|
-
def set(slot)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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,
|
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 =
|
18
|
-
is_data_texture =
|
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(
|
26
|
+
cube_image[i] = clamp_to_max_size(image[i], @_max_cubemap_size)
|
25
27
|
else
|
26
|
-
cube_image[i] = is_data_texture ?
|
28
|
+
cube_image[i] = is_data_texture ? image[i].image : image[i];
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
is_image_power_of_two = Math.power_of_two?(
|
32
|
-
gl_format = GL_MITTSU_PARAMS[
|
33
|
-
gl_type = GL_MITTSU_PARAMS[
|
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
|
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
|
63
|
+
if generate_mipmaps && is_image_power_of_two
|
62
64
|
glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
|
63
65
|
end
|
64
66
|
|
65
|
-
|
67
|
+
self.needs_update = false
|
66
68
|
|
67
|
-
|
69
|
+
on_update.call if on_update
|
68
70
|
else
|
69
71
|
glActiveTexture(GL_TEXTURE0 + slot)
|
70
|
-
glBindTexture(GL_TEXTURE_CUBE_MAP,
|
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
|
2
|
+
class DataTexture
|
3
3
|
def update_specific
|
4
|
-
gl_format = GL_MITTSU_PARAMS[
|
5
|
-
gl_type = GL_MITTSU_PARAMS[
|
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
|
2
|
+
class Texture
|
3
3
|
attr_reader :opengl_texture
|
4
4
|
|
5
|
-
def
|
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
|
15
|
-
|
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
|
17
|
+
def update_opengl(renderer)
|
18
|
+
@renderer = renderer
|
19
|
+
|
22
20
|
if !@initted
|
23
21
|
@initted = true
|
24
|
-
|
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,
|
32
|
-
# glPixelStorei(GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL,
|
33
|
-
glPixelStorei(GL_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
|
-
|
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
|
41
|
+
if generate_mipmaps && is_image_power_of_two
|
44
42
|
glGenerateMipmap(GL_TEXTURE_2D)
|
45
43
|
end
|
46
44
|
|
47
|
-
|
45
|
+
self.needs_update = false
|
48
46
|
|
49
|
-
|
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[
|
57
|
-
glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_MITTSU_PARAMS[
|
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[
|
60
|
-
glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, GL_MITTSU_PARAMS[
|
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
|
66
|
-
puts "WARNING: Mittsu::
|
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(
|
70
|
-
glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(
|
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
|
73
|
-
puts "WARNING: Mittsu::
|
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[
|
91
|
-
gl_type = GL_MITTSU_PARAMS[
|
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
|
-
|
101
|
+
self.generate_mipmaps = false
|
106
102
|
else
|
107
|
-
glTexImage2D(GL_TEXTURE_2D, 0, gl_format,
|
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 <
|
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
|
-
|
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
|
-
|
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.
|
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.
|
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.
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 =
|
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
|
-
|
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 !
|
525
|
-
|
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 =
|
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.
|
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
|
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
|
-
|
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 && !
|
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(
|
621
|
+
load_uniforms_generic(material.uniforms_list)
|
627
622
|
end
|
628
623
|
|
629
|
-
object.
|
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
|
-
|
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.
|
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.
|
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
|
-
|
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
|
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
|
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
|