Class: Mittsu::OpenGLRenderer
- Inherits:
-
Object
- Object
- Mittsu::OpenGLRenderer
- Defined in:
- lib/mittsu/renderers/opengl_renderer.rb
Instance Attribute Summary collapse
-
#auto_clear ⇒ Object
Returns the value of attribute auto_clear.
-
#auto_clear_color ⇒ Object
Returns the value of attribute auto_clear_color.
-
#auto_clear_depth ⇒ Object
Returns the value of attribute auto_clear_depth.
-
#auto_clear_stencil ⇒ Object
Returns the value of attribute auto_clear_stencil.
-
#gamma_factor ⇒ Object
Returns the value of attribute gamma_factor.
-
#gamma_input ⇒ Object
Returns the value of attribute gamma_input.
-
#gamma_output ⇒ Object
Returns the value of attribute gamma_output.
-
#height ⇒ Object
Returns the value of attribute height.
-
#info ⇒ Object
Returns the value of attribute info.
-
#light_renderer ⇒ Object
readonly
Returns the value of attribute light_renderer.
-
#logarithmic_depth_buffer ⇒ Object
readonly
Returns the value of attribute logarithmic_depth_buffer.
-
#max_morph_normals ⇒ Object
Returns the value of attribute max_morph_normals.
-
#max_morph_targets ⇒ Object
Returns the value of attribute max_morph_targets.
-
#pixel_ratio ⇒ Object
Returns the value of attribute pixel_ratio.
-
#programs ⇒ Object
readonly
Returns the value of attribute programs.
-
#proj_screen_matrix ⇒ Object
readonly
Returns the value of attribute proj_screen_matrix.
-
#shadow_map_cascade ⇒ Object
Returns the value of attribute shadow_map_cascade.
-
#shadow_map_cull_face ⇒ Object
Returns the value of attribute shadow_map_cull_face.
-
#shadow_map_debug ⇒ Object
Returns the value of attribute shadow_map_debug.
-
#shadow_map_enabled ⇒ Object
Returns the value of attribute shadow_map_enabled.
-
#shadow_map_type ⇒ Object
Returns the value of attribute shadow_map_type.
-
#sort_objects ⇒ Object
Returns the value of attribute sort_objects.
-
#state ⇒ Object
Returns the value of attribute state.
-
#width ⇒ Object
Returns the value of attribute width.
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
- #add_opengl_object(buffer, object) ⇒ Object
- #clamp_to_max_size(image, max_size = @_max_texture_size) ⇒ Object
- #clear(color = true, depth = true, stencil = true) ⇒ Object
- #clear_depth ⇒ Object
- #clear_stencil ⇒ Object
- #clear_target(render_target, color, depth, stencil) ⇒ Object
- #compressed_texture_formats ⇒ Object
- #enable_scissor_test(enable) ⇒ Object
- #get_clear_alpha ⇒ Object
-
#get_clear_color ⇒ Object
clearing.
-
#initialize(parameters = {}) ⇒ OpenGLRenderer
constructor
A new instance of OpenGLRenderer.
-
#max_anisotropy ⇒ Object
TODO: get_context ??? TODO: force_context_loss ??? TODO: supports_float_textures? ??? TODO: supports[half|standard|compressed|blend min max] …
- #object_in_frustum?(object) ⇒ Boolean
- #on_geometry_dispose(event) ⇒ Object
- #on_material_dispose(event) ⇒ Object
-
#on_object_removed(event) ⇒ Object
Events.
- #on_render_target_dispose(event) ⇒ Object
- #on_texture_dispose(event) ⇒ Object
- #remove_opengl_object(object) ⇒ Object
- #render(scene, camera, render_target = default_target, force_clear = false) ⇒ Object
- #render_buffer(camera, lights, fog, material, geometry_group, object) ⇒ Object
- #reset_gl_state ⇒ Object
- #set_clear_alpha(alpha) ⇒ Object
- #set_clear_color(color, alpha = 1.0) ⇒ Object
- #set_material_faces(material) ⇒ Object
- #set_render_target(render_target = default_target) ⇒ Object
- #set_scissor(x, y, width, height) ⇒ Object
- #set_size(width, height) ⇒ Object
- #set_viewport(x, y, width, height) ⇒ Object
- #shadow_map_enabled? ⇒ Boolean
- #sort_objects? ⇒ Boolean
- #supports_bone_textures? ⇒ Boolean
- #supports_vertex_textures? ⇒ Boolean
Constructor Details
#initialize(parameters = {}) ⇒ OpenGLRenderer
Returns a new instance of OpenGLRenderer.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 37 def initialize(parameters = {}) puts "Mittsu OpenGL Renderer #{VERSION}" fetch_parameters(parameters) @pixel_ratio = 1.0 @sort_objects = true init_collections init_clearing init_gamma init_shadow_properties init_morphs init_info init_state_cache init_camera_matrix_cache @light_renderer = OpenGLLightRenderer.new(self) create_window @state = OpenGLState.new # TODO: load extensions?? reset_gl_state set_default_gl_state get_gpu_capabilities init_plugins end |
Instance Attribute Details
#auto_clear ⇒ Object
Returns the value of attribute auto_clear.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def auto_clear @auto_clear end |
#auto_clear_color ⇒ Object
Returns the value of attribute auto_clear_color.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def auto_clear_color @auto_clear_color end |
#auto_clear_depth ⇒ Object
Returns the value of attribute auto_clear_depth.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def auto_clear_depth @auto_clear_depth end |
#auto_clear_stencil ⇒ Object
Returns the value of attribute auto_clear_stencil.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def auto_clear_stencil @auto_clear_stencil end |
#gamma_factor ⇒ Object
Returns the value of attribute gamma_factor.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def gamma_factor @gamma_factor end |
#gamma_input ⇒ Object
Returns the value of attribute gamma_input.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def gamma_input @gamma_input end |
#gamma_output ⇒ Object
Returns the value of attribute gamma_output.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def gamma_output @gamma_output end |
#height ⇒ Object
Returns the value of attribute height.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def height @height end |
#info ⇒ Object
Returns the value of attribute info.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def info @info end |
#light_renderer ⇒ Object (readonly)
Returns the value of attribute light_renderer.
35 36 37 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 35 def light_renderer @light_renderer end |
#logarithmic_depth_buffer ⇒ Object (readonly)
Returns the value of attribute logarithmic_depth_buffer.
35 36 37 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 35 def logarithmic_depth_buffer @logarithmic_depth_buffer end |
#max_morph_normals ⇒ Object
Returns the value of attribute max_morph_normals.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def max_morph_normals @max_morph_normals end |
#max_morph_targets ⇒ Object
Returns the value of attribute max_morph_targets.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def max_morph_targets @max_morph_targets end |
#pixel_ratio ⇒ Object
Returns the value of attribute pixel_ratio.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def pixel_ratio @pixel_ratio end |
#programs ⇒ Object (readonly)
Returns the value of attribute programs.
35 36 37 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 35 def programs @programs end |
#proj_screen_matrix ⇒ Object (readonly)
Returns the value of attribute proj_screen_matrix.
35 36 37 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 35 def proj_screen_matrix @proj_screen_matrix end |
#shadow_map_cascade ⇒ Object
Returns the value of attribute shadow_map_cascade.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def shadow_map_cascade @shadow_map_cascade end |
#shadow_map_cull_face ⇒ Object
Returns the value of attribute shadow_map_cull_face.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def shadow_map_cull_face @shadow_map_cull_face end |
#shadow_map_debug ⇒ Object
Returns the value of attribute shadow_map_debug.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def shadow_map_debug @shadow_map_debug end |
#shadow_map_enabled ⇒ Object
Returns the value of attribute shadow_map_enabled.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def shadow_map_enabled @shadow_map_enabled end |
#shadow_map_type ⇒ Object
Returns the value of attribute shadow_map_type.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def shadow_map_type @shadow_map_type end |
#sort_objects ⇒ Object
Returns the value of attribute sort_objects.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def sort_objects @sort_objects end |
#state ⇒ Object
Returns the value of attribute state.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def state @state end |
#width ⇒ Object
Returns the value of attribute width.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def width @width end |
#window ⇒ Object
Returns the value of attribute window.
31 32 33 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 31 def window @window end |
Instance Method Details
#add_opengl_object(buffer, object) ⇒ Object
313 314 315 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 313 def add_opengl_object(buffer, object) add_buffer(@_opengl_objects, buffer, object) end |
#clamp_to_max_size(image, max_size = @_max_texture_size) ⇒ Object
303 304 305 306 307 308 309 310 311 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 303 def clamp_to_max_size(image, max_size = @_max_texture_size) width, height = image.width, image.height if width > max_size || height > max_size # TODO: scale the image ... puts "WARNING: Mittsu::OpenGLRenderer: image is too big (#{width} x #{height}). Resized to #{@_max_texture_size} x #{@_max_texture_size}" end image end |
#clear(color = true, depth = true, stencil = true) ⇒ Object
148 149 150 151 152 153 154 155 156 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 148 def clear(color = true, depth = true, stencil = true) bits = 0 bits |= GL_COLOR_BUFFER_BIT if color bits |= GL_DEPTH_BUFFER_BIT if depth bits |= GL_STENCIL_BUFFER_BIT if stencil glClear(bits) end |
#clear_depth ⇒ Object
158 159 160 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 158 def clear_depth glClear(GL_DEPTH_BUFFER_BIT) end |
#clear_stencil ⇒ Object
162 163 164 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 162 def clear_stencil glClear(GL_STENCIL_BUFFER_BIT) end |
#clear_target(render_target, color, depth, stencil) ⇒ Object
166 167 168 169 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 166 def clear_target(render_target, color, depth, stencil) set_render_target(render_target) clear(color, depth, stencil) end |
#compressed_texture_formats ⇒ Object
261 262 263 264 265 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 261 def compressed_texture_formats # TODO: needs extensions.get ... @_compressed_texture_formats ||= [] end |
#enable_scissor_test(enable) ⇒ Object
115 116 117 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 115 def enable_scissor_test(enable) enable ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST) end |
#get_clear_alpha ⇒ Object
139 140 141 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 139 def get_clear_alpha @_clear_alpha end |
#get_clear_color ⇒ Object
clearing
129 130 131 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 129 def get_clear_color @_clear_color end |
#max_anisotropy ⇒ Object
TODO: get_context ??? TODO: force_context_loss ??? TODO: supports_float_textures? ??? TODO: supports[half|standard|compressed|blend min max] … ???
87 88 89 90 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 87 def max_anisotropy @_max_anisotropy ||= nil # TODO: get max anisotropy ???? end |
#object_in_frustum?(object) ⇒ Boolean
119 120 121 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 119 def object_in_frustum?(object) @_frustum.intersects_object?(object) end |
#on_geometry_dispose(event) ⇒ Object
277 278 279 280 281 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 277 def on_geometry_dispose(event) geometry = event.target geometry.remove_event_listener(:dispose, method(:on_geometry_dispose)) deallocate_geometry(geometry) end |
#on_material_dispose(event) ⇒ Object
297 298 299 300 301 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 297 def on_material_dispose(event) material = event.target material.remove_event_listener(:dispose, method(:on_material_dispose)) deallocate_material(material) end |
#on_object_removed(event) ⇒ Object
Events
269 270 271 272 273 274 275 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 269 def on_object_removed(event) object = event.target object.traverse do |child| child.remove_event_listener(:remove, method(:on_object_removed)) remove_child(child) end end |
#on_render_target_dispose(event) ⇒ Object
290 291 292 293 294 295 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 290 def on_render_target_dispose(event) render_target = event.target render_target.remove_event_listener(:dispose, method(:on_render_target_dispose)) deallocate_render_target(render_target) @info[:memory][:textures] -= 1 end |
#on_texture_dispose(event) ⇒ Object
283 284 285 286 287 288 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 283 def on_texture_dispose(event) texture = event.target texture.remove_event_listener(:dispose, method(:on_texture_dispose)) deallocate_texture(texture) @info[:memory][:textures] -= 1 end |
#remove_opengl_object(object) ⇒ Object
317 318 319 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 317 def remove_opengl_object(object) @_opengl_objects.delete(object.id) end |
#render(scene, camera, render_target = default_target, force_clear = false) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 196 def render(scene, camera, render_target = default_target, force_clear = false) raise "ERROR: Mittsu::OpenGLRenderer#render: camera is not an instance of Mittsu::Camera" unless camera.is_a?(Camera) reset_cache_for_this_frame scene.update_matrix_world if scene.auto_update camera.update_matrix_world if camera.parent.nil? update_skeleton_objects(scene) update_screen_projection(camera) scene.project(self) sort_objects_for_render if @sort_objects render_custom_plugins_pre_pass(scene, camera) set_matrices_for_immediate_objects(camera) set_render_target(render_target) perform_auto_clear if @auto_clear || force_clear render_main_pass(scene, camera) render_custom_plugins_post_pass(scene, camera) render_target.update_mipmap ensure_depth_buffer_writing end |
#render_buffer(camera, lights, fog, material, geometry_group, object) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 230 def render_buffer(camera, lights, fog, material, geometry_group, object) puts "--- RENDER #{object.name}" if DEBUG return unless material.visible geometry_group.renderer = self geometry_group.bind_vertex_array_object update_object(object) program = set_program(camera, lights, fog, material, object) attributes = program.attributes buffers_need_update = switch_geometry_program(program, material, geometry_group) @state.init_attributes if buffers_need_update if !material.morph_targets && attributes['position'] && attributes['position'] >= 0 geometry_group.update_vertex_buffer(attributes['position']) if buffers_need_update elsif object.morph_target_base # TODO: when morphing is implemented # setup_morph_targets(material, geometry_group, object) end if buffers_need_update geometry_group.update_other_buffers(object, material, attributes) end @state.disable_unused_attributes object.render_buffer(camera, lights, fog, material, geometry_group, buffers_need_update) end |
#reset_gl_state ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 171 def reset_gl_state @_current_program = nil @_current_camera = nil @_current_geometry_program = '' @_current_material_id = -1 @light_renderer.reset @state.reset end |
#set_clear_alpha(alpha) ⇒ Object
143 144 145 146 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 143 def set_clear_alpha(alpha) @_clear_alpha = alpha clear_color(@_clear_color.r, @_clear_color.g, @_clear_color.b, @_clear_alpha) end |
#set_clear_color(color, alpha = 1.0) ⇒ Object
133 134 135 136 137 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 133 def set_clear_color(color, alpha = 1.0) @_clear_color.set(color) @_clear_alpha = alpha clear_color(@_clear_color.r, @_clear_color.g, @_clear_color.b, @_clear_alpha) end |
#set_material_faces(material) ⇒ Object
225 226 227 228 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 225 def set_material_faces(material) @state.set_double_sided(material.side == DoubleSide) @state.set_flip_sided(material.side == BackSide) end |
#set_render_target(render_target = default_target) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 183 def set_render_target(render_target = default_target) # TODO: when OpenGLRenderTargetCube exists # is_cube = render_target.is_a? OpenGLRenderTargetCube # TODO framebuffer logic for render target cube render_target.setup_buffers if render_target != @_current_render_target render_target.use @_current_render_target = render_target end end |
#set_scissor(x, y, width, height) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 106 def set_scissor(x, y, width, height) glScissor( x * pixel_ratio, y * pixel_ratio, width * pixel_ratio, height * pixel_ratio ) end |
#set_size(width, height) ⇒ Object
92 93 94 95 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 92 def set_size(width, height) @width, @height = width, height self.(0, 0, width, height) end |
#set_viewport(x, y, width, height) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 97 def (x, y, width, height) default_target.( x * pixel_ratio, y * pixel_ratio, width * pixel_ratio, height * pixel_ratio ) end |
#shadow_map_enabled? ⇒ Boolean
78 79 80 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 78 def shadow_map_enabled? @shadow_map_enabled end |
#sort_objects? ⇒ Boolean
123 124 125 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 123 def sort_objects? @sort_objects end |
#supports_bone_textures? ⇒ Boolean
70 71 72 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 70 def supports_bone_textures? @_supports_bone_textures end |
#supports_vertex_textures? ⇒ Boolean
74 75 76 |
# File 'lib/mittsu/renderers/opengl_renderer.rb', line 74 def supports_vertex_textures? @_supports_vertex_textures end |