Class: Rendering::InstanceRenderer
- Inherits:
-
Object
- Object
- Rendering::InstanceRenderer
- Defined in:
- lib/engine/rendering/instance_renderer.rb
Instance Attribute Summary collapse
-
#material ⇒ Object
readonly
Returns the value of attribute material.
-
#mesh ⇒ Object
readonly
Returns the value of attribute mesh.
Instance Method Summary collapse
- #add_instance(mesh_renderer) ⇒ Object
- #draw_all ⇒ Object
-
#initialize(mesh, material) ⇒ InstanceRenderer
constructor
A new instance of InstanceRenderer.
- #remove_instance(mesh_renderer) ⇒ Object
- #update_instance(mesh_renderer) ⇒ Object
Constructor Details
#initialize(mesh, material) ⇒ InstanceRenderer
Returns a new instance of InstanceRenderer.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/engine/rendering/instance_renderer.rb', line 7 def initialize(mesh, material) @mesh = mesh @material = material @mesh_renderers = [] @mesh_matrix_data = [] setup_vertex_attribute_buffer setup_vertex_buffer setup_index_buffer generate_instance_vbo_buf end |
Instance Attribute Details
#material ⇒ Object (readonly)
Returns the value of attribute material.
5 6 7 |
# File 'lib/engine/rendering/instance_renderer.rb', line 5 def material @material end |
#mesh ⇒ Object (readonly)
Returns the value of attribute mesh.
5 6 7 |
# File 'lib/engine/rendering/instance_renderer.rb', line 5 def mesh @mesh end |
Instance Method Details
#add_instance(mesh_renderer) ⇒ Object
19 20 21 22 |
# File 'lib/engine/rendering/instance_renderer.rb', line 19 def add_instance(mesh_renderer) @mesh_renderers << mesh_renderer @mesh_matrix_data += mesh_renderer.game_object.model_matrix.to_a.flatten end |
#draw_all ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/engine/rendering/instance_renderer.rb', line 35 def draw_all set_material_per_frame_data GL.BindVertexArray(@vao) update_vbo_buf GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, @ebo) GL.BindBuffer(GL::ARRAY_BUFFER, @instance_vbo) GL.DrawElementsInstanced(GL::TRIANGLES, mesh.index_data.length, GL::UNSIGNED_INT, 0, @mesh_renderers.count) GL.BindVertexArray(0) GL.BindBuffer(GL::ELEMENT_ARRAY_BUFFER, 0) end |
#remove_instance(mesh_renderer) ⇒ Object
24 25 26 27 28 |
# File 'lib/engine/rendering/instance_renderer.rb', line 24 def remove_instance(mesh_renderer) index = @mesh_renderers.index(mesh_renderer) @mesh_renderers.delete_at(index) @mesh_matrix_data[index * 16, 16] = [] end |
#update_instance(mesh_renderer) ⇒ Object
30 31 32 33 |
# File 'lib/engine/rendering/instance_renderer.rb', line 30 def update_instance(mesh_renderer) index = @mesh_renderers.index(mesh_renderer) @mesh_matrix_data[index * 16, 16] = mesh_renderer.game_object.model_matrix.to_a.flatten end |