commit 6feb235352d6de11616956cbae265f34d578a899 parent 110d11645dae96e1e6a6c1c310d906d69c090dc7 Author: Michael Savage <mikejsavage@gmail.com> Date: Tue Dec 27 01:00:28 +0200 Add default constructors for Mesh/Texture/ShaderConfig Diffstat:
bsp.cc | | | 6 | +++--- |
bsp_renderer.cc | | | 2 | +- |
gpubtt.cc | | | 6 | +++--- |
hm.cc | | | 2 | +- |
immediate.cc | | | 2 | +- |
mod_btt.cc | | | 2 | +- |
renderer.cc | | | 2 | +- |
renderer.h | | | 36 | ++++++++++++++++++++++-------------- |
skybox.cc | | | 2 | +- |
terrain_manager.cc | | | 2 | +- |
text_renderer.cc | | | 4 | ++-- |
diff --git a/bsp.cc b/bsp.cc @@ -319,7 +319,7 @@ extern "C" GAME_INIT( game_init ) { game->test_shader = renderer_new_shader( vert_src, frag_src ); { - ShaderConfig config = { }; + ShaderConfig config; config.vertex_src = textured_vert_src; config.fragment_src = textured_frag_src; config.texture_uniform_names[ 0 ] = "tex"; @@ -400,7 +400,7 @@ extern "C" GAME_FRAME( game_frame ) { v4( 1, 1, 1, 0.5 ), v4( 0, 0, 0, 0.5 ), }; - TextureConfig texture_config = { }; + TextureConfig texture_config; texture_config.width = 2; texture_config.height = 2; texture_config.data = checkerboard; @@ -435,7 +435,7 @@ extern "C" GAME_FRAME( game_frame ) { v2( num_checks, num_checks / aspect ), }; - MeshConfig mesh_config = { }; + MeshConfig mesh_config; mesh_config.positions = renderer_new_vb( positions, sizeof( positions ) ); mesh_config.colours = renderer_new_vb( colours, sizeof( colours ) ); mesh_config.tex_coords0 = renderer_new_vb( texcoords, sizeof( texcoords ) ); diff --git a/bsp_renderer.cc b/bsp_renderer.cc @@ -96,7 +96,7 @@ void bspr_init( BSPRenderer * bspr, MemoryArena * arena, const BSP * bsp ) { } } - MeshConfig config = { }; + MeshConfig config; config.positions = renderer_new_vb( positions.ptr(), num_positions * sizeof( v3 ) ); config.colours = renderer_new_vb( colours.ptr(), num_colours * sizeof( v3 ) ); config.indices = renderer_new_ib( indices.ptr(), num_indices * sizeof( u32 ) ); diff --git a/gpubtt.cc b/gpubtt.cc @@ -64,21 +64,21 @@ void gpubtt_init( VB positions = renderer_new_vb( verts, num_vertices * sizeof( v3 ) ); - TextureConfig normals_config = { }; + TextureConfig normals_config; normals_config.width = ohm->hm.width; normals_config.height = ohm->hm.height; normals_config.format = TEXFMT_RGB_FLOAT; normals_config.data = normals; gpubtt->normal_map = renderer_new_texture( normals_config ); - TextureConfig horizons_config = { }; + TextureConfig horizons_config; horizons_config.width = ohm->hm.width; horizons_config.height = ohm->hm.height; horizons_config.format = TEXFMT_R_FLOAT; horizons_config.data = horizons; gpubtt->horizon_map = renderer_new_texture( horizons_config ); - MeshConfig mesh_config = { }; + MeshConfig mesh_config; mesh_config.positions = positions; mesh_config.num_vertices = num_vertices; gpubtt->mesh = renderer_new_mesh( mesh_config ); diff --git a/hm.cc b/hm.cc @@ -279,7 +279,7 @@ extern "C" GAME_FRAME( game_frame ) { } } - RenderState explosion_render_state = { }; + RenderState explosion_render_state; explosion_render_state.shader = game->test_outline_shader; explosion_render_state.ubs[ UB_VS_HOT ] = ub_sphere; immediate_render( &imm, explosion_render_state ); diff --git a/immediate.cc b/immediate.cc @@ -226,7 +226,7 @@ void immediate_render( const ImmediateContext * ctx, Shader shader, Texture text void immediate_render( const ImmediateContext * ctx, const RenderState & render_state ) { VB vb = renderer_new_vb( ctx->triangles, ctx->num_triangles * sizeof( ImmediateTriangle ), BUFFERUSAGE_STREAM ); - MeshConfig mesh_config = { }; + MeshConfig mesh_config; mesh_config.unified_buffer = vb; mesh_config.stride = sizeof( ImmediateVertex ); mesh_config.positions_offset = checked_cast< u32 >( offsetof( ImmediateVertex, pos ) ); diff --git a/mod_btt.cc b/mod_btt.cc @@ -155,7 +155,7 @@ extern "C" GAME_INIT( game_init ) { game->test_sun = 0.3f; - ShaderConfig terrain_config = { }; + ShaderConfig terrain_config; terrain_config.vertex_src = vert_src; terrain_config.fragment_src = frag_src; terrain_config.texture_uniform_names[ 0 ] = "normals"; diff --git a/renderer.cc b/renderer.cc @@ -251,7 +251,7 @@ Shader renderer_new_shader( ShaderConfig config ) { } Shader renderer_new_shader( const char * vertex_src, const char * fragment_src ) { - ShaderConfig config = { }; + ShaderConfig config; config.vertex_src = vertex_src; config.fragment_src = fragment_src; return renderer_new_shader( config ); diff --git a/renderer.h b/renderer.h @@ -92,8 +92,16 @@ struct Mesh { }; struct MeshConfig { - VB unified_buffer; - u32 stride; + MeshConfig() { + positions = 0; + normals = 0; + tex_coords0 = 0; + tex_coords1 = 0; + colours = 0; + } + + VB unified_buffer = 0; + u32 stride = 0; union { struct { VB positions; @@ -110,17 +118,17 @@ struct MeshConfig { u32 colours_offset; }; }; - IB indices; - u32 num_vertices; - PrimitiveType primitive_type; + IB indices = 0; + u32 num_vertices = 0; + PrimitiveType primitive_type = PRIMITIVETYPE_TRIANGLES; }; struct ShaderConfig { - const char * vertex_src; - const char * fragment_src; - const char * geometry_src; - const char * texture_uniform_names[ RENDERER_MAX_TEXTURES ]; - const char * texture_buffer_uniform_names[ RENDERER_MAX_TEXTURE_BUFFERS ]; + const char * vertex_src = NULL; + const char * fragment_src = NULL; + const char * geometry_src = NULL; + const char * texture_uniform_names[ RENDERER_MAX_TEXTURES ] = { }; + const char * texture_buffer_uniform_names[ RENDERER_MAX_TEXTURE_BUFFERS ] = { }; }; enum TextureFormat { @@ -131,10 +139,10 @@ enum TextureFormat { }; struct TextureConfig { - u32 width, height; - TextureFormat format; - // TODO: internal format? - const void * data; + u32 width = 0; + u32 height = 0; + TextureFormat format = TEXFMT_RGBA_FLOAT; + const void * data = NULL; size_t data_size; // TODO: min/mag filters, wrap modes, border }; diff --git a/skybox.cc b/skybox.cc @@ -59,7 +59,7 @@ void skybox_init( Skybox * skybox ) { VB vb = renderer_new_vb( cube_verts, sizeof( cube_verts ) ); IB ib = renderer_new_ib( cube_indices, sizeof( cube_indices ) ); - MeshConfig mesh_config = { }; + MeshConfig mesh_config; mesh_config.positions = vb; mesh_config.indices = ib; mesh_config.num_vertices = ARRAY_COUNT( cube_indices ); diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -280,7 +280,7 @@ void terrain_init( } { - ShaderConfig config = { }; + ShaderConfig config; config.vertex_src = vert_src; config.fragment_src = frag_src; config.texture_uniform_names[ 0 ] = "normals"; diff --git a/text_renderer.cc b/text_renderer.cc @@ -76,7 +76,7 @@ void text_renderer_init() { float scale = stbtt_ScaleForPixelHeight( &font_info, pixel_size ); - TextureConfig texture_config = { }; + TextureConfig texture_config; texture_config.width = width; texture_config.height = height; texture_config.format = TEXFMT_R_U8; @@ -88,7 +88,7 @@ void text_renderer_init() { sizes[ i ].atlas = renderer_new_texture( texture_config ); } - ShaderConfig shader_config = { }; + ShaderConfig shader_config; shader_config.vertex_src = vert_src; shader_config.fragment_src = frag_src; shader_config.texture_uniform_names[ 0 ] = "atlas";