X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=317b30110bc2d6df942816a258f60940871eec82;hb=a1741ec4aed057cbafff2d6bc9e5cf8a15ae322b;hp=8122b2ae8e41f18effe8dea39a9d5224ae8f2c93;hpb=15beb60ade240af4e00b0d204f7e89a4d35dca36;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index 8122b2a..317b301 100644 --- a/render.h +++ b/render.h @@ -9,11 +9,11 @@ #include "shaders/standard.h" #include "shaders/vblend.h" -static void render_water_texture( m4x3f camera ); -static void render_water_surface( m4x4f pv, m4x3f camera ); -static void render_world( m4x4f projection, m4x3f camera ); -static void shader_link_standard_ub( GLuint shader, int texture_id ); -static void render_world_depth( m4x4f projection, m4x3f camera ); +VG_STATIC void render_water_texture( m4x3f camera ); +VG_STATIC void render_water_surface( m4x4f pv, m4x3f camera ); +VG_STATIC void render_world( m4x4f projection, m4x3f camera ); +VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ); +VG_STATIC void render_world_depth( m4x4f projection, m4x3f camera ); #ifndef RENDER_H #define RENDER_H @@ -27,7 +27,7 @@ struct framebuffer int allocated; }; -static struct pipeline +VG_STATIC struct pipeline { float fov; glmesh fsquad; @@ -49,6 +49,7 @@ static struct pipeline float g_water_fog; int g_light_count; int g_light_preview; + int g_shadow_samples; } ub_world_lighting; @@ -103,7 +104,7 @@ gpipeline = /* * http://www.terathon.com/lengyel/Lengyel-Oblique.pdf */ -static void plane_clip_projection( m4x4f mat, v4f plane ) +VG_STATIC void plane_clip_projection( m4x4f mat, v4f plane ) { v4f c = { @@ -121,7 +122,7 @@ static void plane_clip_projection( m4x4f mat, v4f plane ) mat[3][2] = c[3]; } -static void pipeline_projection( m4x4f mat, float nearz, float farz ) +VG_STATIC void pipeline_projection( m4x4f mat, float nearz, float farz ) { m4x4_projection( mat, gpipeline.fov, @@ -132,7 +133,7 @@ static void pipeline_projection( m4x4f mat, float nearz, float farz ) /* * Shaders */ -static void shader_link_standard_ub( GLuint shader, int texture_id ) +VG_STATIC void shader_link_standard_ub( GLuint shader, int texture_id ) { GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" ); glUniformBlockBinding( shader, idx, 0 ); @@ -142,7 +143,7 @@ static void shader_link_standard_ub( GLuint shader, int texture_id ) glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id ); } -static void render_update_lighting_ub(void) +VG_STATIC void render_update_lighting_ub(void) { struct ub_world_lighting *winf = &gpipeline.ub_world_lighting; int c = 0; @@ -169,6 +170,11 @@ static void render_update_lighting_ub(void) winf->g_light_directions[0][3] = gpipeline.shadow_length; winf->g_light_colours[0][3] = gpipeline.shadow_spread; + if( vg.quality_profile == k_quality_profile_low ) + winf->g_shadow_samples = 0; + else + winf->g_shadow_samples = 8; + glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting), &gpipeline.ub_world_lighting ); @@ -178,7 +184,7 @@ static void render_update_lighting_ub(void) * Framebuffers */ -static void fb_use( struct framebuffer *fb ) +VG_STATIC void fb_use( struct framebuffer *fb ) { if( !fb ) { @@ -192,7 +198,7 @@ static void fb_use( struct framebuffer *fb ) } } -static void fb_init( struct framebuffer *fb ) +VG_STATIC void fb_init( struct framebuffer *fb ) { i32 ix = vg.window_x / fb->div, iy = vg.window_y / fb->div; @@ -222,19 +228,19 @@ static void fb_init( struct framebuffer *fb ) fb->allocated = 1; } -static void fb_free( struct framebuffer *fb ) +VG_STATIC void fb_free( struct framebuffer *fb ) { glDeleteTextures( 1, &fb->colour ); glDeleteFramebuffers( 1, &fb->fb ); } -static void fb_bindtex( struct framebuffer *fb, int texture ) +VG_STATIC void fb_bindtex( struct framebuffer *fb, int texture ) { glActiveTexture( GL_TEXTURE0 + texture ); glBindTexture( GL_TEXTURE_2D, fb->colour ); } -static void fb_resize( struct framebuffer *fb ) +VG_STATIC void fb_resize( struct framebuffer *fb ) { if( !fb->allocated ) return; @@ -250,7 +256,7 @@ static void fb_resize( struct framebuffer *fb ) glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, ix, iy ); } -static void render_fb_resize(void) +VG_STATIC void render_fb_resize(void) { if( gpipeline.ready ) { @@ -261,7 +267,7 @@ static void render_fb_resize(void) } /* used for drawing player onto */ -static void render_init_temp_buffer(void) +VG_STATIC void render_init_temp_buffer(void) { vg_info( "[render] Allocate temporary framebuffer\n" ); @@ -284,7 +290,7 @@ static void render_init_temp_buffer(void) /* used for drawing world depth from the top view, used in our water and * lighting calculations */ -static void render_init_depthmap_buffer(void) +VG_STATIC void render_init_depthmap_buffer(void) { vg_info( "[render] Allocate depth map buffer\n" ); @@ -306,7 +312,7 @@ static void render_init_depthmap_buffer(void) VG_CHECK_GL_ERR(); } -static void render_init_fs_quad(void) +VG_STATIC void render_init_fs_quad(void) { vg_info( "[render] Allocate quad\n" ); @@ -326,7 +332,7 @@ static void render_init_fs_quad(void) VG_CHECK_GL_ERR(); } -static void render_init_uniform_buffers(void) +VG_STATIC void render_init_uniform_buffers(void) { vg_info( "[render] Allocate uniform buffer\n" ); @@ -341,7 +347,7 @@ static void render_init_uniform_buffers(void) VG_CHECK_GL_ERR(); } -static void render_init(void) +VG_STATIC void render_init(void) { shader_blit_register(); shader_standard_register(); @@ -361,24 +367,10 @@ static void render_init(void) vg_release_thread_sync(); } -static void render_free(void *_) -{ - glDeleteBuffers( 1, &gpipeline.ubo_world_lighting ); - - glDeleteVertexArrays( 1, &gpipeline.fsquad.vao ); - glDeleteBuffers( 1, &gpipeline.fsquad.vbo ); - - glDeleteFramebuffers( 1, &gpipeline.fb_depthmap ); - glDeleteTextures( 1, &gpipeline.rgb_depthmap ); - - glDeleteFramebuffers( 1, &gpipeline.fb_background ); - glDeleteTextures( 1, &gpipeline.rgb_background ); -} - /* * Utility */ -static void render_fsquad(void) +VG_STATIC void render_fsquad(void) { glBindVertexArray( gpipeline.fsquad.vao ); glDrawArrays( GL_TRIANGLES, 0, 6 );