medfall

A super great game engine
Log | Files | Refs

commit 300c7178130dc40619f7cc88cebbb31d421b3e4d
parent b70789f9347aed21957201534aee03bbe9bbd18d
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu Aug 31 22:44:14 +0300

Instanced draw calls

Diffstat:
renderer.cc | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/renderer.cc b/renderer.cc @@ -28,6 +28,8 @@ static const u32 UNIFORM_BUFFER_SIZE = kilobytes( 16 ); struct DrawCall { RenderState render_state; Mesh mesh; + u32 num_instances; + VB instance_data; }; enum DeleteCommandType { @@ -128,6 +130,7 @@ void renderer_begin_frame() { } static void renderer_draw_mesh_( const Mesh & mesh, const RenderState & state ); +static void renderer_draw_instances_( const Mesh & mesh, const RenderState & state, u32 num_instances, VB instance_data ); void renderer_end_frame() { ASSERT( !in_pass ); @@ -148,7 +151,12 @@ void renderer_end_frame() { // TODO: sort draw calls for( const DrawCall & dc : draw_calls.slice( pass.begin, pass.one_past_end ) ) { - renderer_draw_mesh_( dc.mesh, dc.render_state ); + if( dc.num_instances == 0 ) { + renderer_draw_mesh_( dc.mesh, dc.render_state ); + } + else { + renderer_draw_instances_( dc.mesh, dc.render_state, dc.num_instances, dc.instance_data ); + } } } @@ -954,6 +962,21 @@ void renderer_draw_mesh( const Mesh & mesh, const RenderState & render_state ) { DrawCall dc; dc.mesh = mesh; dc.render_state = render_state; + dc.num_instances = 0; + dc.instance_data = 0; + draw_calls.append( dc ); +} + +void renderer_draw_instances( const Mesh & mesh, const RenderState & render_state, u32 num_instances, VB instance_data ) { + if( num_instances == 0 ) { + return; + } + + DrawCall dc; + dc.mesh = mesh; + dc.render_state = render_state; + dc.num_instances = num_instances; + dc.instance_data = instance_data; draw_calls.append( dc ); } @@ -971,7 +994,7 @@ static void renderer_draw_mesh_( const Mesh & mesh, const RenderState & state ) glBindVertexArray( 0 ); } -void renderer_draw_instances( const Mesh & mesh, const RenderState & state, u32 num_instances, VB instance_data ) { +static void renderer_draw_instances_( const Mesh & mesh, const RenderState & state, u32 num_instances, VB instance_data ) { set_render_state( state ); glBindVertexArray( mesh.vao );