medfall

A super great game engine
Log | Files | Refs

commit b97a41cd27e31c9c7cac8452301c6ab0e5e3b13f
parent f9b1d0d4a1452004f9fca8e41619c504526d3aff
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Sep  3 12:20:08 +0300

More renderer API cleanup

Diffstat:
bsp.cc | 4++--
hm.cc | 10+++++-----
renderer.cc | 5++---
renderer.h | 31+++++++++++++++----------------
shadow_map.cc | 12++++++------
skybox.cc | 4++--
terrain_manager.cc | 4++--
text_renderer.cc | 2+-
8 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/bsp.cc b/bsp.cc @@ -293,7 +293,7 @@ GAME_FRAME( game_frame ) { { RenderState render_state; render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - render_state.uniforms[ UB_VIEW ] = view_uniforms; + render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; bspr_render( &game->bspr, game->pos, render_state ); } @@ -317,7 +317,7 @@ GAME_FRAME( game_frame ) { RenderState immediate_render_state; immediate_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - immediate_render_state.uniforms[ UB_VIEW ] = view_uniforms; + immediate_render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; immediate_render( &imm, immediate_render_state ); char buf[ 256 ]; diff --git a/hm.cc b/hm.cc @@ -345,8 +345,8 @@ GAME_FRAME( game_frame ) { { RenderState render_state; render_state.shader = get_shader( SHADER_TREE ); - render_state.uniforms[ UB_VIEW ] = view_uniforms; - render_state.uniforms[ UB_SUN ] = renderer_uniforms( sun_dir ); + render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; + render_state.uniforms[ UNIFORM_SUN ] = renderer_uniforms( sun_dir ); render_state.cull_face = CULLFACE_FRONT; renderer_draw_instances( tree_mesh, render_state, num_trees, instance_data ); @@ -394,7 +394,7 @@ GAME_FRAME( game_frame ) { RenderState fireball_render_state; fireball_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - fireball_render_state.uniforms[ UB_VIEW ] = view_uniforms; + fireball_render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; immediate_render( &imm, fireball_render_state ); immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); @@ -413,7 +413,7 @@ GAME_FRAME( game_frame ) { RenderState explosion_render_state; explosion_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - explosion_render_state.uniforms[ UB_VIEW ] = view_uniforms; + explosion_render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; immediate_render( &imm, explosion_render_state ); } @@ -518,7 +518,7 @@ GAME_FRAME( game_frame ) { RenderState impact_render_state; impact_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); - impact_render_state.uniforms[ UB_VIEW ] = view_uniforms; + impact_render_state.uniforms[ UNIFORM_VIEW ] = view_uniforms; immediate_render( &imm, impact_render_state ); } diff --git a/renderer.cc b/renderer.cc @@ -11,7 +11,6 @@ STATIC_ASSERT( SAME_TYPE( VB, GLuint ) ); STATIC_ASSERT( SAME_TYPE( IB, GLuint ) ); -STATIC_ASSERT( SAME_TYPE( UB, GLuint ) ); STATIC_ASSERT( SAME_TYPE( Shader, GLuint ) ); STATIC_ASSERT( SAME_TYPE( Texture, GLuint ) ); STATIC_ASSERT( SAME_TYPE( TextureBufferObject, GLuint ) ); @@ -69,7 +68,7 @@ static RenderPass current_render_pass; static bool in_frame; static bool in_pass; -static UB uniforms; +static GLuint uniforms; static size_t ubo_offset_alignment; static u8 * uniforms_buffer; static size_t uniforms_offset; @@ -205,7 +204,7 @@ void renderer_end_frame() { } } -UniformBinding renderer_ub_data( const void * data, size_t size, size_t alignment ) { +UniformBinding renderer_upload_uniforms( const void * data, size_t size, size_t alignment ) { alignment = max( alignment, ubo_offset_alignment ); UniformBinding binding; diff --git a/renderer.h b/renderer.h @@ -10,19 +10,18 @@ typedef u32 VB; typedef u32 IB; -typedef u32 UB; typedef u32 Shader; typedef u32 Texture; typedef u32 TextureBufferObject; typedef u32 FramebufferObject; -const u32 UB_VS_COLD = 0; -const u32 UB_VIEW = 1; -const u32 UB_MODEL = 2; -const u32 UB_LIGHT_VIEW = 3; -const u32 UB_WINDOW = 4; -const u32 UB_SUN = 5; -const u32 UB_SKY = 6; +const u32 UNIFORM_VS_COLD = 0; +const u32 UNIFORM_VIEW = 1; +const u32 UNIFORM_MODEL = 2; +const u32 UNIFORM_LIGHT_VIEW = 3; +const u32 UNIFORM_WINDOW = 4; +const u32 UNIFORM_SUN = 5; +const u32 UNIFORM_SKY = 6; #define RENDERER_MAX_TEXTURES 4 #define RENDERER_MAX_TEXTURE_BUFFERS 4 @@ -201,7 +200,7 @@ void renderer_end_frame(); Texture renderer_blue_noise(); -UniformBinding renderer_ub_data( const void * data, size_t size, size_t alignment ); +UniformBinding renderer_upload_uniforms( const void * data, size_t size, size_t alignment ); // void renderer_begin_frame( ClearColourBool clear_colour = RENDERER_CLEAR_COLOUR_DO, ClearDepthBool clear_depth = RENDERER_CLEAR_DEPTH_DO ); // TODO: define render passes that have clear/undefined input framebuffers @@ -215,7 +214,7 @@ void renderer_delete_ib( IB ib ); TB renderer_new_tb( TextureFormat format, const void * data = NULL, u32 len = 0, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); void renderer_tb_data( TB tb, const void * data, u32 len, BufferUsage usage = BUFFERUSAGE_DYNAMIC ); -void renderer_delete_tb( TB ub ); +void renderer_delete_tb( TB tb ); FB renderer_new_fb( TextureConfig texture_format, FramebufferAttachment attachment ); void renderer_clear_fb( FB fb ); @@ -248,7 +247,7 @@ VB renderer_new_ib( const array< T > data, BufferUsage usage = BUFFERUSAGE_STATI } /* - * cheesy renderer_ub_data helper + * renderer_uniform helper */ template< typename T > @@ -281,13 +280,13 @@ constexpr size_t renderer_uniforms_size( size_t size ) { return renderer_uniforms_size< T, Rest... >( sizeof( S ) + align_power_of_2( size, renderer_ubo_alignment< S >() ) ); } -inline void renderer_uniforms_copy( char * buf, size_t len ) { } +inline void renderer_serialise_uniforms( char * buf, size_t len ) { } template< typename T, typename... Rest > -inline void renderer_uniforms_copy( char * buf, size_t len, const T & first, Rest... rest ) { +inline void renderer_serialise_uniforms( char * buf, size_t len, const T & first, Rest... rest ) { len = align_power_of_2( len, renderer_ubo_alignment< T >() ); memcpy( buf + len, &first, sizeof( first ) ); - renderer_uniforms_copy( buf, len + sizeof( first ), rest... ); + renderer_serialise_uniforms( buf, len + sizeof( first ), rest... ); } template< typename... Rest > @@ -296,6 +295,6 @@ inline UniformBinding renderer_uniforms( Rest... rest ) { constexpr size_t alignment = renderer_ub_alignment< Rest... >(); char buf[ buf_size ]; memset( buf, 0, sizeof( buf ) ); - renderer_uniforms_copy( buf, 0, rest... ); - return renderer_ub_data( buf, sizeof( buf ), alignment ); + renderer_serialise_uniforms( buf, 0, rest... ); + return renderer_upload_uniforms( buf, sizeof( buf ), alignment ); } diff --git a/shadow_map.cc b/shadow_map.cc @@ -25,7 +25,7 @@ static void draw_scene( RenderState render_state, bool draw_light = false ) { immediate_init( &imm, triangles, ARRAY_COUNT( triangles ) ); m4 I = m4_identity(); - render_state.uniforms[ UB_MODEL ] = renderer_uniforms( I ); + render_state.uniforms[ UNIFORM_MODEL ] = renderer_uniforms( I ); immediate_sphere( &imm, v3( 0, 0, 2 ), 2, v4( 1, 0, 0, 1 ) ); immediate_sphere( &imm, v3( -3, 7, 2 ), 2, v4( 0, 1, 0, 1 ) ); @@ -50,7 +50,7 @@ static void draw_scene( RenderState render_state, bool draw_light = false ) { immediate_render( &imm, render_state ); m4 M = m4_translation( v3( -7, -2, 0 ) ) * m4_rotx( deg_to_rad( 90 ) ); - render_state.uniforms[ UB_MODEL ] = renderer_uniforms( M ); + render_state.uniforms[ UNIFORM_MODEL ] = renderer_uniforms( M ); render_state.cull_face = CULLFACE_FRONT; renderer_draw_mesh( tree_mesh, render_state ); } @@ -138,7 +138,7 @@ GAME_FRAME( game_frame ) { RenderState render_state; render_state.shader = get_shader( SHADER_WRITE_SHADOW_MAP ); - render_state.uniforms[ UB_LIGHT_VIEW ] = light_view_uniforms; + render_state.uniforms[ UNIFORM_LIGHT_VIEW ] = light_view_uniforms; render_state.fb = shadow_fb; draw_scene( render_state ); @@ -160,9 +160,9 @@ GAME_FRAME( game_frame ) { { RenderState render_state; render_state.shader = get_shader( SHADER_SHADOWED_VERTEX_COLOURS ); - render_state.uniforms[ UB_VS_COLD ] = renderer_uniforms( light_pos ); - render_state.uniforms[ UB_VIEW ] = renderer_uniforms( V, P, game->pos ); - render_state.uniforms[ UB_LIGHT_VIEW ] = light_view_uniforms; + render_state.uniforms[ UNIFORM_VS_COLD ] = renderer_uniforms( light_pos ); + render_state.uniforms[ UNIFORM_VIEW ] = renderer_uniforms( V, P, game->pos ); + render_state.uniforms[ UNIFORM_LIGHT_VIEW ] = light_view_uniforms; render_state.textures[ 0 ] = shadow_fb.texture; render_state.textures[ 1 ] = renderer_blue_noise(); diff --git a/skybox.cc b/skybox.cc @@ -136,8 +136,8 @@ void skybox_render( const Skybox * skybox, const m4 & Vsky, const m4 & P, float render_state.shader = get_shader( SHADER_SKYBOX ); render_state.cull_face = CULLFACE_FRONT; render_state.disable_depth_writes = true; - render_state.uniforms[ UB_VIEW ] = renderer_uniforms( Vsky, P ); - render_state.uniforms[ UB_SKY ] = renderer_uniforms( hosek.A, hosek.B, hosek.C, hosek.D, hosek.E, hosek.F, hosek.G, hosek.H, hosek.I, hosek.Z, sun_dir ); + render_state.uniforms[ UNIFORM_VIEW ] = renderer_uniforms( Vsky, P ); + render_state.uniforms[ UNIFORM_SKY ] = renderer_uniforms( hosek.A, hosek.B, hosek.C, hosek.D, hosek.E, hosek.F, hosek.G, hosek.H, hosek.I, hosek.Z, sun_dir ); render_state.textures[ 0 ] = renderer_blue_noise(); renderer_draw_mesh( skybox->mesh, render_state ); diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -352,8 +352,8 @@ 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.textures[ 2 ] = renderer_blue_noise(); - render_state.uniforms[ UB_VIEW ] = renderer_uniforms( V, P ); - render_state.uniforms[ UB_SUN ] = renderer_uniforms( sun_dir, sun_angle ); + render_state.uniforms[ UNIFORM_VIEW ] = renderer_uniforms( V, P ); + render_state.uniforms[ UNIFORM_SUN ] = renderer_uniforms( sun_dir, sun_angle ); render_state.tbs[ 0 ] = tm->point_light_origins; render_state.tbs[ 1 ] = tm->point_light_colours; diff --git a/text_renderer.cc b/text_renderer.cc @@ -118,7 +118,7 @@ void draw_text( const char * str, int x, int y, float pixel_size ) { RenderState render_state; render_state.shader = get_shader( SHADER_TEXT ); render_state.textures[ 0 ] = sizes[ size_idx ].atlas; - render_state.uniforms[ UB_WINDOW ] = renderer_uniforms( get_window_size() ); + render_state.uniforms[ UNIFORM_WINDOW ] = renderer_uniforms( get_window_size() ); render_state.depth_func = DEPTHFUNC_DISABLED; render_state.enable_alpha_blending = true; // render_state.disable_depth_writes = true;