medfall

A super great game engine
Log | Files | Refs

commit db8e4b6f4ceed06212ab285bb64cc3e13d23fc6c
parent 024bb02ea89e26dfd8b78e1f537e03357d5bceab
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat May 20 14:52:11 +0300

Move glViewport calls into the renderer

Diffstat:
renderer.cc | 24+++++++++++++++++++++---
renderer.h | 2+-
shadow_map.cc | 7-------
3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/renderer.cc b/renderer.cc @@ -1,6 +1,7 @@ #include "glad.h" #include "intrinsics.h" +#include "game.h" #include "renderer.h" #include "log.h" #include "linear_algebra.h" @@ -214,10 +215,8 @@ static GLenum framebufferattachment_to_glenum( FramebufferAttachment attachment FB renderer_new_fb( TextureConfig texture_config, FramebufferAttachment attachment ) { ASSERT( !is_compressed( texture_config.format ) ); - return renderer_new_fb( renderer_new_texture( texture_config ), attachment ); -} -FB renderer_new_fb( Texture texture, FramebufferAttachment attachment ) { + Texture texture = renderer_new_texture( texture_config ); GLuint fbo; glGenFramebuffers( 1, &fbo ); @@ -236,6 +235,8 @@ FB renderer_new_fb( Texture texture, FramebufferAttachment attachment ) { fb.fbo = fbo; fb.attachment = attachment; fb.texture = texture; + fb.width = texture_config.width; + fb.height = texture_config.height; return fb; } @@ -596,6 +597,7 @@ static GLenum primitivetype_to_glenum( PrimitiveType primitive_type ) { } static RenderState previous_render_state; +static u32 previous_viewport_width, previous_viewport_height; void renderer_clear_fb( FB fb ) { if( fb.fbo != previous_render_state.fb.fbo ) { @@ -638,6 +640,22 @@ 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 ); + + u32 new_viewport_width, new_viewport_height; + if( state.fb.fbo == 0 ) { + new_viewport_width = WIDTH; + new_viewport_height = HEIGHT; + } + else { + new_viewport_width = state.fb.width; + new_viewport_height = state.fb.height; + } + + if( new_viewport_width != previous_viewport_width || new_viewport_height != previous_viewport_height ) { + previous_viewport_width = new_viewport_width; + previous_viewport_height = new_viewport_height; + glViewport( 0, 0, new_viewport_width, new_viewport_height ); + } } // depth writing diff --git a/renderer.h b/renderer.h @@ -90,6 +90,7 @@ struct FB { FramebufferObject fbo; FramebufferAttachment attachment; Texture texture; + u32 width, height; }; struct RenderState { @@ -193,7 +194,6 @@ void renderer_tb_data( TB tb, const void * data, u32 len, BufferUsage usage = BU 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 ); diff --git a/shadow_map.cc b/shadow_map.cc @@ -1,5 +1,3 @@ -#include "glad.h" - #include "game.h" #include "intrinsics.h" #include "linear_algebra.h" @@ -154,12 +152,7 @@ extern "C" GAME_FRAME( game_frame ) { render_state.ubs[ UB_LIGHT_VIEW ] = ub_light_view; render_state.fb = shadow_fb; - glViewport( 0, 0, SHADOW_SIZE, SHADOW_SIZE ); - - // renderer_clear( CLEARCOLOUR_DONT ); draw_scene( render_state ); - - glViewport( 0, 0, WIDTH, HEIGHT ); } // render shadow map