mittsu 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-workflow.yml +5 -44
  3. data/Gemfile +0 -4
  4. data/README.md +16 -130
  5. data/bin/console +0 -4
  6. data/lib/mittsu/cameras/cube_camera.rb +1 -1
  7. data/lib/mittsu/core/geometry.rb +3 -3
  8. data/lib/mittsu/core/object_3d.rb +29 -47
  9. data/lib/mittsu/core/uniform.rb +23 -0
  10. data/lib/mittsu/core.rb +1 -0
  11. data/lib/mittsu/loaders/obj_loader.rb +11 -5
  12. data/lib/mittsu/loaders/stl_loader.rb +186 -0
  13. data/lib/mittsu/loaders.rb +1 -0
  14. data/lib/mittsu/math/box3.rb +4 -4
  15. data/lib/mittsu/objects/line.rb +1 -3
  16. data/lib/mittsu/objects/mesh.rb +9 -12
  17. data/lib/mittsu/objects/point_cloud.rb +3 -3
  18. data/lib/mittsu/textures/render_target.rb +93 -0
  19. data/lib/mittsu/textures/render_target_cube.rb +8 -0
  20. data/lib/mittsu/textures/texture.rb +1 -1
  21. data/lib/mittsu/textures.rb +2 -0
  22. data/lib/mittsu/version.rb +1 -1
  23. data/lib/mittsu.rb +0 -1
  24. data/mittsu.gemspec +8 -12
  25. metadata +33 -204
  26. data/install-glfw.ps1 +0 -13
  27. data/lib/mittsu/renderers/generic_lib.rb +0 -122
  28. data/lib/mittsu/renderers/glfw_lib.rb +0 -62
  29. data/lib/mittsu/renderers/glfw_window.rb +0 -233
  30. data/lib/mittsu/renderers/opengl/core/buffer_geometry.rb +0 -11
  31. data/lib/mittsu/renderers/opengl/core/geometry.rb +0 -346
  32. data/lib/mittsu/renderers/opengl/core/object_3d.rb +0 -134
  33. data/lib/mittsu/renderers/opengl/lights/ambient_light.rb +0 -26
  34. data/lib/mittsu/renderers/opengl/lights/directional_light.rb +0 -35
  35. data/lib/mittsu/renderers/opengl/lights/hemisphere_light.rb +0 -39
  36. data/lib/mittsu/renderers/opengl/lights/light.rb +0 -55
  37. data/lib/mittsu/renderers/opengl/lights/point_light.rb +0 -36
  38. data/lib/mittsu/renderers/opengl/lights/spot_light.rb +0 -47
  39. data/lib/mittsu/renderers/opengl/materials/line_basic_material.rb +0 -16
  40. data/lib/mittsu/renderers/opengl/materials/material.rb +0 -274
  41. data/lib/mittsu/renderers/opengl/materials/mesh_basic_material.rb +0 -21
  42. data/lib/mittsu/renderers/opengl/materials/mesh_lambert_material.rb +0 -33
  43. data/lib/mittsu/renderers/opengl/materials/mesh_phong_material.rb +0 -44
  44. data/lib/mittsu/renderers/opengl/materials/opengl_material_basics.rb +0 -57
  45. data/lib/mittsu/renderers/opengl/materials/point_cloud_material.rb +0 -27
  46. data/lib/mittsu/renderers/opengl/materials/shader_material.rb +0 -11
  47. data/lib/mittsu/renderers/opengl/objects/group.rb +0 -9
  48. data/lib/mittsu/renderers/opengl/objects/line.rb +0 -45
  49. data/lib/mittsu/renderers/opengl/objects/mesh.rb +0 -70
  50. data/lib/mittsu/renderers/opengl/objects/point_cloud.rb +0 -39
  51. data/lib/mittsu/renderers/opengl/objects/sprite.rb +0 -12
  52. data/lib/mittsu/renderers/opengl/opengl_buffer.rb +0 -13
  53. data/lib/mittsu/renderers/opengl/opengl_debug.rb +0 -81
  54. data/lib/mittsu/renderers/opengl/opengl_default_target.rb +0 -50
  55. data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +0 -758
  56. data/lib/mittsu/renderers/opengl/opengl_geometry_like.rb +0 -132
  57. data/lib/mittsu/renderers/opengl/opengl_helper.rb +0 -161
  58. data/lib/mittsu/renderers/opengl/opengl_implementations.rb +0 -37
  59. data/lib/mittsu/renderers/opengl/opengl_lib.rb +0 -19
  60. data/lib/mittsu/renderers/opengl/opengl_light_renderer.rb +0 -43
  61. data/lib/mittsu/renderers/opengl/opengl_mittsu_params.rb +0 -53
  62. data/lib/mittsu/renderers/opengl/opengl_program.rb +0 -250
  63. data/lib/mittsu/renderers/opengl/opengl_shader.rb +0 -58
  64. data/lib/mittsu/renderers/opengl/opengl_state.rb +0 -205
  65. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +0 -417
  66. data/lib/mittsu/renderers/opengl/plugins/sprite_fragment.glsl +0 -38
  67. data/lib/mittsu/renderers/opengl/plugins/sprite_plugin.rb +0 -250
  68. data/lib/mittsu/renderers/opengl/plugins/sprite_vertex.glsl +0 -31
  69. data/lib/mittsu/renderers/opengl/scenes/scene.rb +0 -9
  70. data/lib/mittsu/renderers/opengl/textures/compressed_texture.rb +0 -20
  71. data/lib/mittsu/renderers/opengl/textures/cube_texture.rb +0 -77
  72. data/lib/mittsu/renderers/opengl/textures/data_texture.rb +0 -21
  73. data/lib/mittsu/renderers/opengl/textures/texture.rb +0 -107
  74. data/lib/mittsu/renderers/opengl_render_target.rb +0 -201
  75. data/lib/mittsu/renderers/opengl_renderer.rb +0 -1028
  76. data/lib/mittsu/renderers/shaders/rbsl_loader.rb +0 -166
  77. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +0 -5
  78. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +0 -5
  79. data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +0 -5
  80. data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +0 -40
  81. data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +0 -5
  82. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +0 -5
  83. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +0 -5
  84. data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +0 -5
  85. data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +0 -60
  86. data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +0 -15
  87. data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +0 -21
  88. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +0 -62
  89. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +0 -21
  90. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +0 -7
  91. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +0 -17
  92. data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +0 -26
  93. data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +0 -15
  94. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +0 -5
  95. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +0 -6
  96. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +0 -5
  97. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +0 -5
  98. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +0 -43
  99. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +0 -196
  100. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +0 -243
  101. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +0 -58
  102. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +0 -5
  103. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +0 -5
  104. data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +0 -2
  105. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +0 -5
  106. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +0 -12
  107. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +0 -11
  108. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +0 -15
  109. data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +0 -9
  110. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +0 -11
  111. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +0 -6
  112. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +0 -5
  113. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +0 -6
  114. data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +0 -5
  115. data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +0 -12
  116. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +0 -13
  117. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +0 -20
  118. data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +0 -27
  119. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +0 -216
  120. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +0 -19
  121. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +0 -6
  122. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +0 -9
  123. data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +0 -8
  124. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +0 -47
  125. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +0 -20
  126. data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +0 -20
  127. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +0 -12
  128. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +0 -5
  129. data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +0 -17
  130. data/lib/mittsu/renderers/shaders/shader_chunk.rb +0 -9
  131. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_fragment.rbsl +0 -37
  132. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_uniforms.rbslu +0 -3
  133. data/lib/mittsu/renderers/shaders/shader_lib/basic/basic_vertex.rbsl +0 -33
  134. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_fragment.rbsl +0 -12
  135. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_uniforms.rbslu +0 -2
  136. data/lib/mittsu/renderers/shaders/shader_lib/cube/cube_vertex.rbsl +0 -12
  137. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_fragment.rbsl +0 -26
  138. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_uniforms.rbslu +0 -0
  139. data/lib/mittsu/renderers/shaders/shader_lib/depth_rgba/depth_rgba_vertex.rbsl +0 -12
  140. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_fragment.rbsl +0 -56
  141. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_uniforms.rbslu +0 -7
  142. data/lib/mittsu/renderers/shaders/shader_lib/lambert/lambert_vertex.rbsl +0 -37
  143. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_fragment.rbsl +0 -27
  144. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_uniforms.rbslu +0 -2
  145. data/lib/mittsu/renderers/shaders/shader_lib/particle_basic/particle_basic_vertex.rbsl +0 -25
  146. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_fragment.rbsl +0 -45
  147. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_uniforms.rbslu +0 -11
  148. data/lib/mittsu/renderers/shaders/shader_lib/phong/phong_vertex.rbsl +0 -43
  149. data/lib/mittsu/renderers/shaders/shader_lib.rb +0 -43
  150. data/lib/mittsu/renderers/shaders/shader_templates/fragment.glsl.erb +0 -105
  151. data/lib/mittsu/renderers/shaders/shader_templates/vertex.glsl.erb +0 -143
  152. data/lib/mittsu/renderers/shaders/uniforms_lib.rb +0 -106
  153. data/lib/mittsu/renderers/shaders/uniforms_utils.rb +0 -31
  154. data/lib/mittsu/renderers.rb +0 -1
@@ -1,38 +0,0 @@
1
- #version 330
2
-
3
- uniform vec3 color;
4
- uniform sampler2D map;
5
- uniform float opacity;
6
-
7
- uniform int fogType;
8
- uniform vec3 fogColor;
9
- uniform float fogDensity;
10
- uniform float fogNear;
11
- uniform float fogFar;
12
- uniform float alphaTest;
13
-
14
- in vec2 vUV;
15
- layout(location = 0) out vec4 fragColor;
16
-
17
- void main() {
18
- vec4 texture = texture( map, vUV );
19
-
20
- if ( texture.a < alphaTest ) discard;
21
-
22
- fragColor = vec4( color * texture.xyz, texture.a * opacity );
23
-
24
- if ( fogType > 0 ) {
25
- float depth = gl_FragCoord.z / gl_FragCoord.w;
26
- float fogFactor = 0.0;
27
-
28
- if ( fogType == 1 ) {
29
- fogFactor = smoothstep( fogNear, fogFar, depth );
30
- } else {
31
- const float LOG2 = 1.442695;
32
- float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );
33
- fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );
34
- }
35
-
36
- fragColor = mix( fragColor, vec4( fogColor, fragColor.w ), fogFactor );
37
- }
38
- }
@@ -1,250 +0,0 @@
1
- module Mittsu
2
- class SpritePlugin
3
- include OpenGLHelper
4
-
5
- VERTICES = [
6
- -0.5, -0.5, 0.0, 0.0,
7
- 0.5, -0.5, 1.0, 0.0,
8
- 0.5, 0.5, 1.0, 1.0,
9
- -0.5, 0.5, 0.0, 1.0
10
- ] # Float32Array
11
-
12
- FACES = [
13
- 0, 1, 2,
14
- 0, 2, 3
15
- ] # Uint16Array
16
-
17
- def initialize(renderer, sprites)
18
- @renderer = renderer
19
- @sprites = sprites
20
- @program = nil
21
-
22
- # for decomposing matrixWorld
23
- @sprite_position = Vector3.new
24
- @sprite_rotation = Quaternion.new
25
- @sprite_scale = Vector3.new
26
- end
27
-
28
- def render(scene, camera)
29
- return if @sprites.empty?
30
-
31
- init if @program.nil?
32
- setup_gl_for_render(camera)
33
- setup_fog(scene)
34
-
35
- update_positions_and_sort(camera)
36
-
37
- render_all_sprites(scene)
38
-
39
- glEnable(GL_CULL_FACE)
40
- @renderer.reset_gl_state
41
- end
42
-
43
- private
44
-
45
- def init
46
- create_vertex_array_object
47
- create_program
48
-
49
- init_attributes
50
- init_uniforms
51
-
52
- # TODO: canvas texture??
53
- end
54
-
55
- def create_vertex_array_object
56
- @vertex_array_object = glCreateVertexArray
57
- glBindVertexArray(@vertex_array_object)
58
-
59
- @vertex_buffer = glCreateBuffer
60
- @element_buffer = glCreateBuffer
61
-
62
- glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
63
- glBufferData_easy(GL_ARRAY_BUFFER, VERTICES, GL_STATIC_DRAW)
64
-
65
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @element_buffer)
66
- glBufferData_easy(GL_ELEMENT_ARRAY_BUFFER, FACES, GL_STATIC_DRAW)
67
- end
68
-
69
- def create_program
70
- @program = glCreateProgram
71
-
72
- vertex_shader = OpenGLShader.new(GL_VERTEX_SHADER, File.read(File.join(__dir__, 'sprite_vertex.glsl')))
73
- fragment_shader = OpenGLShader.new(GL_FRAGMENT_SHADER, File.read(File.join(__dir__, 'sprite_fragment.glsl')))
74
-
75
- glAttachShader(@program, vertex_shader.shader)
76
- glAttachShader(@program, fragment_shader.shader)
77
-
78
- glLinkProgram(@program)
79
- end
80
-
81
- def init_attributes
82
- @attributes = {
83
- position: glGetAttribLocation(@program, 'position'),
84
- uv: glGetAttribLocation(@program, 'uv')
85
- }
86
- end
87
-
88
- def init_uniforms
89
- @uniforms = {
90
- uvOffset: glGetUniformLocation(@program, 'uvOffset'),
91
- uvScale: glGetUniformLocation(@program, 'uvScale'),
92
-
93
- rotation: glGetUniformLocation(@program, 'rotation'),
94
- scale: glGetUniformLocation(@program, 'scale'),
95
-
96
- color: glGetUniformLocation(@program, 'color'),
97
- map: glGetUniformLocation(@program, 'map'),
98
- opacity: glGetUniformLocation(@program, 'opacity'),
99
-
100
- modelViewMatrix: glGetUniformLocation(@program, 'modelViewMatrix'),
101
- projectionMatrix: glGetUniformLocation(@program, 'projectionMatrix'),
102
-
103
- fogType: glGetUniformLocation(@program, 'fogType'),
104
- fogDensity: glGetUniformLocation(@program, 'fogDensity'),
105
- fogNear: glGetUniformLocation(@program, 'fogNear'),
106
- fogFar: glGetUniformLocation(@program, 'fogFar'),
107
- fogColor: glGetUniformLocation(@program, 'fogColor'),
108
-
109
- alphaTest: glGetUniformLocation(@program, 'alphaTest')
110
- }
111
- end
112
-
113
- def painter_sort_stable(a, b)
114
- if a.z != b.z
115
- b.z - a.z
116
- else
117
- b.id - a.id
118
- end
119
- end
120
-
121
- def setup_gl_for_render(camera)
122
- glUseProgram(@program)
123
-
124
- glDisable(GL_CULL_FACE)
125
- glEnable(GL_BLEND)
126
-
127
- glBindVertexArray(@vertex_array_object)
128
-
129
- glEnableVertexAttribArray(@attributes[:position])
130
- glEnableVertexAttribArray(@attributes[:uv])
131
-
132
- glBindBuffer(GL_ARRAY_BUFFER, @vertex_buffer)
133
-
134
- glVertexAttribPointer(@attributes[:position], 2, GL_FLOAT, GL_FALSE, 2 * 8, 0)
135
- glVertexAttribPointer(@attributes[:uv], 2, GL_FLOAT, GL_FALSE, 2 * 8, 8)
136
-
137
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, @element_buffer)
138
-
139
- glUniformMatrix4fv(@uniforms[:projectionMatrix], 1, GL_FALSE, array_to_ptr_easy(camera.projection_matrix.elements))
140
-
141
- glActiveTexture(GL_TEXTURE0)
142
- glUniform1i(@uniforms[:map], 0)
143
- end
144
-
145
- def setup_fog(scene)
146
- @old_fog_type = 0
147
- @scene_fog_type = 0
148
- fog = scene.fog
149
-
150
- if fog
151
- glUniform3f(@uniforms[:fogColor], fog.color.r, fog.color.g, fog.color.b)
152
-
153
- if fog.is_a?(Fog)
154
- glUniform1f(@uniforms[:fogNear], fog.near)
155
- glUniform1f(@uniforms[:fogFar], fog.far)
156
-
157
- glUniform1i(@uniforms[:fogType], 1)
158
- @old_fog_type = 1
159
- @scene_fog_type = 1
160
- elsif fog.is_a?(FogExp2)
161
- glUniform1f(@uniforms[:fogDensity], fog.density)
162
-
163
- glUniform1i(@uniforms[:fogType], 2)
164
- @old_fog_type = 2
165
- @scene_fog_type = 2
166
- end
167
- else
168
- glUniform1i(@uniforms[:fogType], 0)
169
- @old_fog_type = 0
170
- @scene_fog_type = 0
171
- end
172
- end
173
-
174
- def update_positions_and_sort(camera)
175
- @sprites.each do |sprite|
176
- sprite.model_view_matrix.multiply_matrices(camera.matrix_world_inverse, sprite.matrix_world)
177
- sprite.z = -sprite.model_view_matrix.elements[14]
178
- end
179
-
180
- @sprites.sort!(&self.method(:painter_sort_stable))
181
- end
182
-
183
- def render_all_sprites(scene)
184
- @sprites.each do |sprite|
185
- material = sprite.material
186
-
187
- set_fog_uniforms(material, scene)
188
- set_uv_uniforms(material)
189
- set_color_uniforms(material)
190
- set_transform_uniforms(sprite)
191
- set_blend_mode(material)
192
-
193
- # set texture
194
- if material.map && material.map.image && material.map.image.width
195
- material.map.set(0, @renderer)
196
- else
197
- # TODO: canvas texture?
198
- # texture.set(0, @renderer)
199
- end
200
-
201
- # draw elements
202
- glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0) # GL_UNSIGNED_SHORT
203
- end
204
- end
205
-
206
- def set_fog_uniforms(material, scene)
207
- fog_type = 0
208
-
209
- if scene.fog && material.fog
210
- fog_type = @scene_fog_type
211
- end
212
-
213
- if @old_fog_type != fog_type
214
- glUniform1(@uniforms[:fogType], fog_type)
215
- @old_fog_type = fog_type
216
- end
217
- end
218
-
219
- def set_uv_uniforms(material)
220
- if !material.map.nil?
221
- glUniform2f(@uniforms[:uvOffset], material.map.offset.x, material.map.offset.y)
222
- glUniform2f(@uniforms[:uvScale], material.map.repeat.x, material.map.repeat.y)
223
- else
224
- glUniform2f(@uniforms[:uvOffset], 0.0, 0.0)
225
- glUniform2f(@uniforms[:uvScale], 1.0, 1.0)
226
- end
227
- end
228
-
229
- def set_color_uniforms(material)
230
- glUniform1f(@uniforms[:opacity], material.opacity)
231
- glUniform3f(@uniforms[:color], material.color.r, material.color.g, material.color.b)
232
- glUniform1f(@uniforms[:alphaTest], material.alpha_test)
233
- end
234
-
235
- def set_transform_uniforms(sprite)
236
- glUniformMatrix4fv(@uniforms[:modelViewMatrix], 1, GL_FALSE, array_to_ptr_easy(sprite.model_view_matrix.elements))
237
-
238
- sprite.matrix_world.decompose(@sprite_position, @sprite_rotation, @sprite_scale)
239
-
240
- glUniform1f(@uniforms[:rotation], sprite.material.rotation)
241
- glUniform2fv(@uniforms[:scale], 1, array_to_ptr_easy([@sprite_scale.x, @sprite_scale.y]))
242
- end
243
-
244
- def set_blend_mode(material)
245
- @renderer.state.set_blending(material.blending, material.blend_equation, material.blend_src, material.blend_dst)
246
- @renderer.state.set_depth_test(material.depth_test)
247
- @renderer.state.set_depth_write(material.depth_write)
248
- end
249
- end
250
- end
@@ -1,31 +0,0 @@
1
- #version 330
2
-
3
- uniform mat4 modelViewMatrix;
4
- uniform mat4 projectionMatrix;
5
- uniform float rotation;
6
- uniform vec2 scale;
7
- uniform vec2 uvOffset;
8
- uniform vec2 uvScale;
9
-
10
- in vec2 position;
11
- in vec2 uv;
12
-
13
- out vec2 vUV;
14
-
15
- void main() {
16
- vUV = uvOffset + uv * uvScale;
17
-
18
- vec2 alignedPosition = position * scale;
19
-
20
- vec2 rotatedPosition;
21
- rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
22
- rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
23
-
24
- vec4 finalPosition;
25
-
26
- finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
27
- finalPosition.xy += rotatedPosition;
28
- finalPosition = projectionMatrix * finalPosition;
29
-
30
- gl_Position = finalPosition;
31
- }
@@ -1,9 +0,0 @@
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,20 +0,0 @@
1
- module Mittsu
2
- class CompressedTexture
3
- def update_specific
4
- gl_format = GL_MITTSU_PARAMS[format]
5
- gl_type = GL_MITTSU_PARAMS[type]
6
-
7
- mipmaps.each_with_index do |mipmap, i|
8
- if format != RGBAFormat && format != RGBFormat
9
- if @renderer.compressed_texture_formats.include?(gl_format)
10
- glCompressedTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, mipmap.data)
11
- else
12
- puts 'WARNING: Mittsu::Texture: Attempt to load unsupported compressed texture format in #update_texture'
13
- end
14
- else
15
- glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,77 +0,0 @@
1
- module Mittsu
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
11
- @renderer.info[:memory][:textures] += 1
12
- end
13
-
14
- glActiveTexture(GL_TEXTURE0 + slot)
15
- glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube])
16
-
17
- # glPixelStorei(GL_UNPACK_FLIP_Y_WEBGL, texture.flip_y)
18
-
19
- is_compressed = is_a?(CompressedTexture)
20
- is_data_texture = image[0].is_a?(DataTexture)
21
-
22
- cube_image = [];
23
-
24
- 6.times do |i|
25
- if @auto_scale_cubemaps && !is_compressed && !is_data_texture
26
- cube_image[i] = clamp_to_max_size(image[i], @_max_cubemap_size)
27
- else
28
- cube_image[i] = is_data_texture ? image[i].image : image[i];
29
- end
30
- end
31
-
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]
36
-
37
- set_parameters(GL_TEXTURE_CUBE_MAP, is_image_power_of_two)
38
-
39
- 6.times do |i|
40
- if !is_compressed
41
- if is_data_texture
42
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data)
43
- else
44
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl_format, cube_image[i].width, cube_image[i].height, 0, gl_format, gl_type, cube_image[i].data)
45
- end
46
- else
47
- mipmaps = cube_image[i].mipmaps
48
-
49
- mipmaps.each_with_index do |mipmap, j|
50
- if format != RGBAFormat && format != RGBFormat
51
- if @renderer.compressed_texture_formats.include?(gl_format)
52
- glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, mipmap.data)
53
- else
54
- puts "WARNING: Mittsu::OpenGLCubeTexture: Attempt to load unsupported compressed texture format in #set"
55
- end
56
- else
57
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, j, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
58
- end
59
- end
60
- end
61
- end
62
-
63
- if generate_mipmaps && is_image_power_of_two
64
- glGenerateMipmap(GL_TEXTURE_CUBE_MAP)
65
- end
66
-
67
- self.needs_update = false
68
-
69
- on_update.call if on_update
70
- else
71
- glActiveTexture(GL_TEXTURE0 + slot)
72
- glBindTexture(GL_TEXTURE_CUBE_MAP, image[:_opengl_texture_cube])
73
- end
74
- end
75
- end
76
- end
77
- end
@@ -1,21 +0,0 @@
1
- module Mittsu
2
- class DataTexture
3
- def update_specific
4
- gl_format = GL_MITTSU_PARAMS[format]
5
- gl_type = GL_MITTSU_PARAMS[type]
6
- is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
7
-
8
- # use manually created mipmaps if available
9
- # if there are no manual mipmaps
10
- # set 0 level mipmap and then use GL to generate other mipmap levels
11
-
12
- if !mipmaps.empty? && is_image_power_of_two
13
- mipmaps.each_with_index do |mipmap, i|
14
- glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
15
- end
16
- else
17
- glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data)
18
- end
19
- end
20
- end
21
- end
@@ -1,107 +0,0 @@
1
- module Mittsu
2
- class Texture
3
- attr_reader :opengl_texture
4
-
5
- def set(slot, renderer)
6
- @renderer = renderer
7
-
8
- glActiveTexture(GL_TEXTURE0 + slot)
9
-
10
- if needs_update?
11
- update_opengl(@renderer)
12
- else
13
- glBindTexture(GL_TEXTURE_2D, @opengl_texture)
14
- end
15
- end
16
-
17
- def update_opengl(renderer)
18
- @renderer = renderer
19
-
20
- if !@initted
21
- @initted = true
22
- add_event_listener(:dispose, @renderer.method(:on_texture_dispose))
23
- @opengl_texture = glCreateTexture
24
- @renderer.info[:memory][:textures] += 1
25
- end
26
-
27
- glBindTexture(GL_TEXTURE_2D, @opengl_texture)
28
-
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)
32
-
33
- self.image = @renderer.clamp_to_max_size(image)
34
-
35
- is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
36
-
37
- set_parameters(GL_TEXTURE_2D, is_image_power_of_two)
38
-
39
- update_specific
40
-
41
- if generate_mipmaps && is_image_power_of_two
42
- glGenerateMipmap(GL_TEXTURE_2D)
43
- end
44
-
45
- self.needs_update = false
46
-
47
- on_update.call if on_update
48
- end
49
-
50
- protected
51
-
52
- def set_parameters(texture_type, is_image_power_of_two)
53
- if is_image_power_of_two
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])
56
-
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])
59
- else
60
- glTexParameteri(texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
61
- glTexParameteri(texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
62
-
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. (#{source_file})"
65
- end
66
-
67
- glTexParameteri(texture_type, GL_TEXTURE_MAG_FILTER, filter_fallback(mag_filter))
68
- glTexParameteri(texture_type, GL_TEXTURE_MIN_FILTER, filter_fallback(min_filter))
69
-
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. (#{source_file})"
72
- end
73
-
74
- # TODO: anisotropic extension ???
75
- end
76
- end
77
-
78
- # Fallback filters for non-power-of-2 textures
79
- def filter_fallback(filter)
80
- if filter == NearestFilter || filter == NearestMipMapNearestFilter || filter == NearestMipMapLinearFilter
81
- GL_NEAREST
82
- end
83
-
84
- GL_LINEAR
85
- end
86
-
87
- def update_specific
88
- gl_format = GL_MITTSU_PARAMS[format]
89
- gl_type = GL_MITTSU_PARAMS[type]
90
- is_image_power_of_two = Math.power_of_two?(image.width) && Math.power_of_two?(image.height)
91
-
92
- # use manually created mipmaps if available
93
- # if there are no manual mipmaps
94
- # set 0 level mipmap and then use GL to generate other mipmap levels
95
-
96
- if !mipmaps.empty? && is_image_power_of_two
97
- mipmaps.each_with_index do |mipmap, i|
98
- glTexImage2D(GL_TEXTURE_2D, i, gl_format, mipmap.width, mipmap.height, 0, gl_format, gl_type, mipmap.data)
99
- end
100
-
101
- self.generate_mipmaps = false
102
- else
103
- glTexImage2D(GL_TEXTURE_2D, 0, gl_format, image.width, image.height, 0, gl_format, gl_type, image.data)
104
- end
105
- end
106
- end
107
- end