commit 8a7f4635db536200c4533812dd4dcb1ec945805b parent 88e1e405497759c247212c083eb00948e7d0eb2d Author: Michael Savage <mikejsavage@gmail.com> Date: Sat May 20 14:40:21 +0300 Remove UB_VS_HOT Diffstat:
bsp.cc | | | 17 | +++++------------ |
hm.cc | | | 12 | ++++++------ |
renderer.cc | | | 2 | +- |
renderer.h | | | 13 | ++++++------- |
shaders/flat_vertex_colours.glsl | | | 2 | +- |
shaders/skybox.glsl | | | 2 | +- |
shaders/terrain.glsl | | | 2 | +- |
shaders/tree.glsl | | | 2 | +- |
skybox.cc | | | 23 | ++++++++--------------- |
skybox.h | | | 4 | ++-- |
terrain_manager.cc | | | 13 | +++---------- |
terrain_manager.h | | | 2 | +- |
diff --git a/bsp.cc b/bsp.cc @@ -246,7 +246,7 @@ BSP_Leaf & BSP::position_to_leaf( v3 pos ) const { return leaves[ -( node_idx + 1 ) ]; } -static UB test_ub; +static UB ub_view; extern "C" GAME_INIT( game_init ) { bsp_init( &game->bsp, "acidwdm2.bsp" ); @@ -259,14 +259,9 @@ extern "C" GAME_INIT( game_init ) { bspr_init( &game->bspr, &arena, &game->bsp ); - test_ub = renderer_new_ub(); + ub_view = renderer_new_ub(); } -struct FSData { - m4 V; - m4 P; -}; - extern "C" GAME_FRAME( game_frame ) { const int fb = input->keys[ KEY_W ] - input->keys[ KEY_S ]; const int lr = input->keys[ KEY_D ] - input->keys[ KEY_A ]; @@ -290,14 +285,12 @@ extern "C" GAME_FRAME( game_frame ) { m4 P = m4_perspective( VERTICAL_FOV, ( float ) WIDTH / ( float ) HEIGHT, NEAR_PLANE_DEPTH, FAR_PLANE_DEPTH ); m4 V = m4_view( forward, right, up, game->pos ); - FSData fsdata = { V, P }; - renderer_begin_frame(); - renderer_ub_data( test_ub, &fsdata, sizeof( fsdata ) ); + renderer_ub_easy( ub_view, V, P ); RenderState render_state; render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - render_state.ubs[ UB_VS_HOT ] = test_ub; + render_state.ubs[ UB_VIEW ] = ub_view; bspr_render( &game->bspr, game->pos, render_state ); immediate_init( &imm, triangles, ARRAY_COUNT( triangles ) ); @@ -320,7 +313,7 @@ extern "C" GAME_FRAME( game_frame ) { RenderState immediate_render_state; render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - immediate_render_state.ubs[ UB_VS_HOT ] = test_ub; + immediate_render_state.ubs[ UB_VIEW ] = ub_view; immediate_render( &imm, immediate_render_state ); char buf[ 256 ]; diff --git a/hm.cc b/hm.cc @@ -24,7 +24,7 @@ static u64 sid; static double last_connection_attempt = -5.0; // TODO static bool connected = false; static struct sockaddr_in addr; -static UB tree_uniforms; +static UB ub_view; extern "C" GAME_INIT( game_init ) { net_init(); @@ -38,7 +38,7 @@ extern "C" GAME_INIT( game_init ) { game->test_sun = 0.3f; - tree_uniforms = renderer_new_ub(); + ub_view = renderer_new_ub(); const size_t triangles = 65536; ImmediateTriangle * immediate_memory = memarena_push_many( &mem->persistent_arena, ImmediateTriangle, triangles ); @@ -166,7 +166,7 @@ extern "C" GAME_FRAME( game_frame ) { terrain_render( &game->tm, V, P, game->test_sun, current_time ); struct { m4 V; m4 P; } uniforms = { V, P }; - renderer_ub_data( tree_uniforms, &uniforms, sizeof( uniforms ) ); + renderer_ub_data( ub_view, &uniforms, sizeof( uniforms ) ); RenderState immediate_render_state; immediate_render_state.shader = get_shader( SHADER_SHIT ); @@ -227,7 +227,7 @@ extern "C" GAME_FRAME( game_frame ) { RenderState fireball_render_state; fireball_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - fireball_render_state.ubs[ UB_VS_HOT ] = tree_uniforms; + fireball_render_state.ubs[ UB_VIEW ] = ub_view; immediate_render( &imm, fireball_render_state ); immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); @@ -244,7 +244,7 @@ extern "C" GAME_FRAME( game_frame ) { RenderState explosion_render_state; explosion_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - explosion_render_state.ubs[ UB_VS_HOT ] = tree_uniforms; + explosion_render_state.ubs[ UB_VIEW ] = ub_view; immediate_render( &imm, explosion_render_state ); } @@ -347,7 +347,7 @@ extern "C" GAME_FRAME( game_frame ) { RenderState impact_render_state; impact_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - impact_render_state.ubs[ UB_VS_HOT ] = tree_uniforms; + impact_render_state.ubs[ UB_VIEW ] = ub_view; immediate_render( &imm, impact_render_state ); } diff --git a/renderer.cc b/renderer.cc @@ -306,7 +306,7 @@ Shader renderer_new_shader( ShaderConfig config ) { return INVALID_SHADER; } - const char * ubo_names[] = { "v_hot", "v_cold", "f_hot", "f_cold", "view", "model", "light_view" }; + const char * ubo_names[] = { "v_cold", "f_hot", "f_cold", "view", "model", "light_view" }; for( size_t i = 0; i < ARRAY_COUNT( ubo_names ); i++ ) { GLuint idx = glGetUniformBlockIndex( program, ubo_names[ i ] ); if( idx != GL_INVALID_INDEX ) { diff --git a/renderer.h b/renderer.h @@ -16,13 +16,12 @@ typedef u32 Texture; typedef u32 TextureBufferObject; typedef u32 FramebufferObject; -const u32 UB_VS_HOT = 0; -const u32 UB_VS_COLD = 1; -const u32 UB_FS_HOT = 2; -const u32 UB_FS_COLD = 3; -const u32 UB_VIEW = 4; -const u32 UB_MODEL = 5; -const u32 UB_LIGHT_VIEW = 6; +const u32 UB_VS_COLD = 0; +const u32 UB_FS_HOT = 1; +const u32 UB_FS_COLD = 2; +const u32 UB_VIEW = 3; +const u32 UB_MODEL = 4; +const u32 UB_LIGHT_VIEW = 5; #define RENDERER_MAX_TEXTURES 4 #define RENDERER_MAX_TEXTURE_BUFFERS 4 diff --git a/shaders/flat_vertex_colours.glsl b/shaders/flat_vertex_colours.glsl @@ -5,7 +5,7 @@ in vec3 colour; out vec3 frag_colour; -layout( std140 ) uniform v_hot { +layout( std140 ) uniform view { mat4 V; mat4 P; }; diff --git a/shaders/skybox.glsl b/shaders/skybox.glsl @@ -3,7 +3,7 @@ in vec3 position; out vec3 pos; -layout( std140 ) uniform v_hot { +layout( std140 ) uniform view { mat4 V; mat4 P; }; diff --git a/shaders/terrain.glsl b/shaders/terrain.glsl @@ -8,7 +8,7 @@ struct VSOut { in vec3 position; out VSOut v2f; -layout( std140 ) uniform v_hot { +layout( std140 ) uniform view { mat4 V; mat4 P; }; diff --git a/shaders/tree.glsl b/shaders/tree.glsl @@ -4,7 +4,7 @@ in vec3 position; out vec3 frag_colour; -layout( std140 ) uniform v_hot { +layout( std140 ) uniform view { mat4 V; mat4 P; }; diff --git a/skybox.cc b/skybox.cc @@ -29,15 +29,10 @@ void skybox_init( Skybox * skybox ) { mesh_config.primitive_type = PRIMITIVETYPE_TRIANGLE_STRIP; skybox->mesh = renderer_new_mesh( mesh_config ); - skybox->vertex_uniforms = renderer_new_ub(); - skybox->fragment_uniforms = renderer_new_ub(); + skybox->ub_view = renderer_new_ub(); + skybox->ub_sun = renderer_new_ub(); } -struct VSData { - m4 V; - m4 P; -}; - struct FSData { float sun; }; @@ -47,23 +42,21 @@ static m4 angles_to_view( v3 angles ) { } void skybox_render( const Skybox * skybox, const m4 & V, const m4 & P, float sun ) { - VSData vsdata = { V, P }; - FSData fsdata = { sun }; - renderer_ub_data( skybox->vertex_uniforms, &vsdata, sizeof( vsdata ) ); - renderer_ub_data( skybox->fragment_uniforms, &fsdata, sizeof( fsdata ) ); + renderer_ub_easy( skybox->ub_view, V, P ); + renderer_ub_easy( skybox->ub_sun, sun ); RenderState render_state; render_state.shader = get_shader( SHADER_SKYBOX ); render_state.cull_face = CULLFACE_FRONT; render_state.disable_depth_writes = true; - render_state.ubs[ UB_VS_HOT ] = skybox->vertex_uniforms; - render_state.ubs[ UB_FS_HOT ] = skybox->fragment_uniforms; + render_state.ubs[ UB_VIEW ] = skybox->ub_view; + render_state.ubs[ UB_FS_HOT ] = skybox->ub_sun; renderer_draw_mesh( skybox->mesh, render_state ); } void skybox_destroy( Skybox * skybox ) { renderer_delete_mesh( skybox->mesh ); - renderer_delete_ub( skybox->vertex_uniforms ); - renderer_delete_ub( skybox->fragment_uniforms ); + renderer_delete_ub( skybox->ub_view ); + renderer_delete_ub( skybox->ub_sun ); } diff --git a/skybox.h b/skybox.h @@ -5,8 +5,8 @@ struct Skybox { Mesh mesh; - UB vertex_uniforms; - UB fragment_uniforms; + UB ub_view; + UB ub_sun; }; void skybox_init( Skybox * skybox ); diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -176,7 +176,7 @@ void terrain_init( } } - tm->vertex_uniforms = renderer_new_ub(); + tm->ub_view = renderer_new_ub(); tm->fragment_uniforms = renderer_new_ub(); tm->point_light_origins = renderer_new_tb( TEXFMT_RGB_FLOAT ); tm->point_light_colours = renderer_new_tb( TEXFMT_RGB_FLOAT ); @@ -265,11 +265,6 @@ void terrain_update( TerrainManager * tm, v3 position ) { } } -struct VSData { - m4 V; - m4 P; -}; - struct FSData { v2 dimensions; float sun; @@ -300,10 +295,8 @@ void terrain_render( TerrainManager * tm, const m4 & V, const m4 & P, float sun, tm->tile_states[ tx ][ ty ] = TILE_LOADED; } - VSData vsdata = { V, P }; + renderer_ub_easy( tm->ub_view, V, P ); FSData fsdata = { v2( TILE_SIZE, TILE_SIZE ), sun }; - - renderer_ub_data( tm->vertex_uniforms, &vsdata, sizeof( vsdata ) ); renderer_ub_data( tm->fragment_uniforms, &fsdata, sizeof( fsdata ) ); /* start lighting */ @@ -328,7 +321,7 @@ void terrain_render( TerrainManager * tm, const m4 & V, const m4 & P, float sun, RenderState render_state; render_state.shader = get_shader( SHADER_TERRAIN ); - render_state.ubs[ UB_VS_HOT ] = tm->vertex_uniforms; + render_state.ubs[ UB_VIEW ] = tm->ub_view; render_state.ubs[ UB_FS_HOT ] = tm->fragment_uniforms; render_state.tbs[ 0 ] = tm->point_light_origins; render_state.tbs[ 1 ] = tm->point_light_colours; diff --git a/terrain_manager.h b/terrain_manager.h @@ -52,7 +52,7 @@ struct TerrainManager { u32 width, height; - UB vertex_uniforms; + UB ub_view; UB fragment_uniforms; TB point_light_origins; TB point_light_colours;