commit 76c141fce8cd5ece190011a9187954ef01f69043 parent dfd00acb455b37a760f0b551a42f5ffb03e11219 Author: Michael Savage <mikejsavage@gmail.com> Date: Thu Aug 31 00:17:06 +0300 Just orphan instead of double/triple buffering Diffstat:
renderer.cc | | | 21 | ++++++++------------- |
diff --git a/renderer.cc b/renderer.cc @@ -65,9 +65,7 @@ static RenderPass current_render_pass; static bool in_frame; static bool in_pass; -// double buffered UBO. TODO: maybe just orphan -static StaticArray< UB, 2 > uniforms; -static u32 uniforms_idx; +static UB uniforms; static u32 ubo_offset_alignment; static u8 * uniforms_buffer; static u32 uniforms_offset; @@ -100,13 +98,10 @@ static void bind_fb( FB fb ) { } void renderer_init() { - glGenBuffers( uniforms.size(), uniforms.ptr() ); - for( UB ub : uniforms ) { - glBindBuffer( GL_UNIFORM_BUFFER, ub ); - glBufferData( GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW ); - } + glGenBuffers( 1, &uniforms ); + glBindBuffer( GL_UNIFORM_BUFFER, uniforms ); + glBufferData( GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW ); - uniforms_idx = 0; in_frame = false; in_pass = false; @@ -116,7 +111,7 @@ void renderer_init() { } void renderer_term() { - glDeleteBuffers( uniforms.size(), uniforms.ptr() ); + glDeleteBuffers( 1, &uniforms ); } void renderer_begin_frame() { @@ -127,7 +122,8 @@ void renderer_begin_frame() { deletes.clear(); render_passes.clear(); - glBindBuffer( GL_UNIFORM_BUFFER, uniforms[ uniforms_idx ] ); + glBindBuffer( GL_UNIFORM_BUFFER, uniforms ); + glBufferData( GL_UNIFORM_BUFFER, UNIFORM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW ); uniforms_buffer = ( u8 * ) glMapBuffer( GL_UNIFORM_BUFFER, GL_WRITE_ONLY ); ASSERT( uniforms_buffer != NULL ); uniforms_offset = 0; @@ -140,10 +136,9 @@ void renderer_end_frame() { ASSERT( in_frame ); in_frame = false; - glBindBuffer( GL_UNIFORM_BUFFER, uniforms[ uniforms_idx ] ); // TODO: not necessary + glBindBuffer( GL_UNIFORM_BUFFER, uniforms ); // TODO: not necessary glUnmapBuffer( GL_UNIFORM_BUFFER ); uniforms_buffer = NULL; - uniforms_idx = ( uniforms_idx + 1 ) % uniforms.size(); for( const RenderPass & pass : render_passes ) { bind_fb( pass.render_target );