X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=render.h;h=209bed692d5bc5777fbb3db122b4410ab2a96b56;hb=47941822dae18a018c985847b052e70214a3ccc6;hp=a00c209d2697476f2eb922ae2662ee07dcaf50c5;hpb=d00b1df8f80e4714dc2f9aa2189d242bb4d09a2f;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/render.h b/render.h index a00c209..209bed6 100644 --- a/render.h +++ b/render.h @@ -8,13 +8,12 @@ #include "shaders/blit.h" #include "shaders/standard.h" #include "shaders/vblend.h" -#include "shaders/unlit.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 @@ -28,7 +27,7 @@ struct framebuffer int allocated; }; -static struct pipeline +VG_STATIC struct pipeline { float fov; glmesh fsquad; @@ -104,7 +103,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 = { @@ -122,18 +121,18 @@ 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, - (float)vg_window_x / (float)vg_window_y, + (float)vg.window_x / (float)vg.window_y, nearz, 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 ); @@ -143,7 +142,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; @@ -179,24 +178,24 @@ 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 ) { glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - glViewport( 0, 0, vg_window_x, vg_window_y ); + glViewport( 0, 0, vg.window_x, vg.window_y ); } else { glBindFramebuffer( GL_FRAMEBUFFER, fb->fb ); - glViewport( 0, 0, vg_window_x / fb->div, vg_window_y / fb->div ); + glViewport( 0, 0, vg.window_x / fb->div, vg.window_y / fb->div ); } } -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; + i32 ix = vg.window_x / fb->div, + iy = vg.window_y / fb->div; glGenFramebuffers( 1, &fb->fb ); glBindFramebuffer( GL_FRAMEBUFFER, fb->fb ); @@ -223,25 +222,25 @@ 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; - i32 ix = vg_window_x / fb->div, - iy = vg_window_y / fb->div; + i32 ix = vg.window_x / fb->div, + iy = vg.window_y / fb->div; glBindTexture( GL_TEXTURE_2D, fb->colour ); glTexImage2D( GL_TEXTURE_2D, 0, fb->format, ix, iy, 0, @@ -251,18 +250,18 @@ 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 ) { glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, 0, + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg.window_x, vg.window_y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL ); } } /* 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" ); @@ -271,7 +270,7 @@ static void render_init_temp_buffer(void) glGenTextures( 1, &gpipeline.rgb_background ); glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background ); - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y, + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg.window_x, vg.window_y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); @@ -285,7 +284,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" ); @@ -307,7 +306,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" ); @@ -327,7 +326,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" ); @@ -342,12 +341,11 @@ 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(); shader_vblend_register(); - shader_unlit_register(); vg_acquire_thread_sync(); { @@ -363,24 +361,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 );