medfall

A super great game engine
Log | Files | Refs

commit caf496ee77d09b2eecb802124746c52146789650
parent c1f0195e1343e75b249e890cacbd1f7e95a027c3
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat May 20 00:18:17 +0300

Add renderer_clear_fb

Diffstat:
renderer.cc | 11++++++++++-
renderer.h | 2++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/renderer.cc b/renderer.cc @@ -234,6 +234,7 @@ FB renderer_new_fb( Texture texture, FramebufferAttachment attachment ) { FB fb; fb.fbo = fbo; + fb.attachment = attachment; fb.texture = texture; return fb; } @@ -596,6 +597,15 @@ static GLenum primitivetype_to_glenum( PrimitiveType primitive_type ) { static RenderState previous_render_state; +void renderer_clear_fb( FB fb ) { + if( fb.fbo != previous_render_state.fb.fbo ) { + glBindFramebuffer( GL_DRAW_FRAMEBUFFER, fb.fbo ); + previous_render_state.fb = fb; + } + + glClear( fb.attachment == FB_COLOUR ? GL_COLOR_BUFFER_BIT : GL_DEPTH_BUFFER_BIT ); +} + void renderer_draw_mesh( const Mesh & mesh, const RenderState & state ) { if( state.shader != previous_render_state.shader ) { glUseProgram( state.shader ); @@ -628,7 +638,6 @@ void renderer_draw_mesh( const Mesh & mesh, const RenderState & state ) { // framebuffer if( state.fb.fbo != previous_render_state.fb.fbo ) { glBindFramebuffer( GL_DRAW_FRAMEBUFFER, state.fb.fbo ); - glClear( GL_DEPTH_BUFFER_BIT ); // TODO TODO TODO } // depth writing diff --git a/renderer.h b/renderer.h @@ -90,6 +90,7 @@ struct TB { struct FB { FramebufferObject fbo; + FramebufferAttachment attachment; Texture texture; }; @@ -195,6 +196,7 @@ void renderer_delete_tb( TB ub ); FB renderer_new_fb( TextureConfig texture_format, FramebufferAttachment attachment ); FB renderer_new_fb( Texture texture, FramebufferAttachment attachment ); +void renderer_clear_fb( FB fb ); void renderer_delete_fb( FB fb ); Shader renderer_new_shader( ShaderConfig config );