medfall

A super great game engine
Log | Files | Refs

commit 37dc01a237b743f0cb004c03ea2923f57d4e7df9
parent d81c830a3b8f2e08d0667368786ec8c863d4a5bc
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun, 29 Oct 2017 19:08:28 +0200

Remove ImmediateContext and make the immediate renderer use a DynamicArray

Diffstat:
bsp.cc | 18+++++++-----------
game.h | 3---
hm.cc | 96+++++++++++++++++++++++++++++++++++--------------------------------------------
immediate.cc | 124++++++++++++++++++++++++++++++++++++-------------------------------------------
immediate.h | 27+++++++--------------------
shadow_map.cc | 27+++++++++++----------------
text_renderer.cc | 11+++--------
7 files changed, 126 insertions(+), 180 deletions(-)

diff --git a/bsp.cc b/bsp.cc @@ -11,9 +11,6 @@ #include "bsp_renderer.h" #include "text_renderer.h" -static ImmediateTriangle triangles[ 512000 ]; -static ImmediateContext imm; - static bool fix = false; static v3 fix_start; static v3 fix_end; @@ -118,16 +115,16 @@ bool BSP::trace_seg_brush( const BSP_Brush & brush, v3 start, v3 dir, float tmin hit = true; colour = v4( 0, 0, 0, 1 ); } - immediate_sphere( &imm, start + t * dir, 8, colour, 8 ); + immediate_sphere( start + t * dir, 8, colour, 8 ); } else - immediate_sphere( &imm, start + t * dir, 8, v4( 0.5, 0.5, 0.5, 1 ), 8 ); + immediate_sphere( start + t * dir, 8, v4( 0.5, 0.5, 0.5, 1 ), 8 ); } v4 colour = v4( 1, 0, 1, 1 ); if( tnear >= tfar ) colour = v4( 1, 1, 0, 1 ); - if( hit ) immediate_sphere( &imm, start + tfar * dir, 16, colour ); + if( hit ) immediate_sphere( start + tfar * dir, 16, colour ); if( hit ) { if( !starts_inside ) { if( tfar <= tnear ) { @@ -201,7 +198,7 @@ void BSP::trace_seg_tree( s32 node_idx, v3 start, v3 dir, float tmin, float tmax // otherwise we straddle the plane check_both_sides = true; t = unchecked_t; - immediate_sphere( &imm, start + t * dir, 8, v4( 0, 1, 0, 1 ), 8 ); + immediate_sphere( start + t * dir, 8, v4( 0, 1, 0, 1 ), 8 ); } } } @@ -298,8 +295,7 @@ GAME_FRAME( game_frame ) { bspr_render( &game->bspr, game->pos, render_state ); } - immediate_init( &imm, triangles, ARRAY_COUNT( triangles ) ); - immediate_sphere( &imm, v3( 0, 0, 0 ), 128, v4( 1, 1, 0, 1 ) ); + immediate_sphere( v3( 0, 0, 0 ), 128, v4( 1, 1, 0, 1 ) ); if( input->keys[ KEY_T ] ) { fix = true; @@ -312,14 +308,14 @@ GAME_FRAME( game_frame ) { bool hit = game->bspr.bsp->trace_seg( fix_start, fix_end, is ); if( hit ) { - immediate_sphere( &imm, is.pos, 16, v4( 1, 0, 0, 1 ) ); + immediate_sphere( is.pos, 16, v4( 1, 0, 0, 1 ) ); } } RenderState immediate_render_state; immediate_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); immediate_render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms; - immediate_render( &imm, immediate_render_state ); + immediate_render( immediate_render_state ); char buf[ 256 ]; snprintf( buf, sizeof( buf ), "pos: (%.2f %.2f %.2f) pitch: %.2f yaw: %.2f forward: (%.2f %.2f %.2f) right: (%.2f %.2f %.2f) up: (%.2f %.2f %.2f)", game->pos.x, game->pos.y, game->pos.z, game->pitch, game->yaw, diff --git a/game.h b/game.h @@ -10,7 +10,6 @@ #include "bsp.h" #include "bsp_renderer.h" #include "skybox.h" -#include "immediate.h" #include "work_queue.h" #include "memory_arena.h" #include "keys.h" @@ -43,8 +42,6 @@ struct GameState { BTTs btt; GPUBTT gpubtt; Heightmap hm; - - ImmediateContext test_immediate; }; struct GameMemory { diff --git a/hm.cc b/hm.cc @@ -10,6 +10,7 @@ #include "gl.h" #include "renderer.h" #include "shaders.h" +#include "immediate.h" #include "text_renderer.h" #include "pool.h" #include "hashtable.h" @@ -74,40 +75,6 @@ GAME_INIT( game_init ) { game->sun_angle = 0.3f; - const size_t triangles = 65536; - ImmediateTriangle * immediate_memory = memarena_push_many( &mem->persistent_arena, ImmediateTriangle, triangles ); - immediate_init( &game->test_immediate, immediate_memory, triangles ); - - const float aspect = get_aspect_ratio(); - const float crosshair_thickness = 0.0025f; - const float crosshair_length = 0.01f; - - const v4 red( 1, 0, 0, 1 ); - immediate_triangle( &game->test_immediate, - v3( -crosshair_length, -crosshair_thickness, 0 ), - v3( -crosshair_length, crosshair_thickness, 0 ), - v3( crosshair_length, crosshair_thickness, 0 ), - red - ); - immediate_triangle( &game->test_immediate, - v3( crosshair_length, crosshair_thickness, 0 ), - v3( crosshair_length, -crosshair_thickness, 0 ), - v3( -crosshair_length, -crosshair_thickness, 0 ), - red - ); - immediate_triangle( &game->test_immediate, - v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), - v3( crosshair_thickness / aspect, crosshair_length * aspect, 0 ), - v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), - red - ); - immediate_triangle( &game->test_immediate, - v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), - v3( -crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), - v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), - red - ); - skybox_init( &game->skybox ); load_trees( &mem->persistent_arena ); @@ -352,10 +319,41 @@ GAME_FRAME( game_frame ) { renderer_draw_instances( tree_mesh, render_state, num_trees, instance_data ); } - RenderState immediate_render_state; - immediate_render_state.shader = get_shader( SHADER_UI ); - immediate_render_state.depth_func = DEPTHFUNC_DISABLED; - immediate_render( &game->test_immediate, immediate_render_state ); + { + const float aspect = get_aspect_ratio(); + const float crosshair_thickness = 0.0025f; + const float crosshair_length = 0.01f; + + const v4 red( 1, 0, 0, 1 ); + immediate_triangle( + v3( -crosshair_length, -crosshair_thickness, 0 ), + v3( -crosshair_length, crosshair_thickness, 0 ), + v3( crosshair_length, crosshair_thickness, 0 ), + red + ); + immediate_triangle( + v3( crosshair_length, crosshair_thickness, 0 ), + v3( crosshair_length, -crosshair_thickness, 0 ), + v3( -crosshair_length, -crosshair_thickness, 0 ), + red + ); + immediate_triangle( + v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + v3( crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + red + ); + immediate_triangle( + v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + v3( -crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + red + ); + RenderState render_state; + render_state.shader = get_shader( SHADER_UI ); + render_state.depth_func = DEPTHFUNC_DISABLED; + immediate_render( render_state ); + } if( input->keys[ KEY_F ] ) { Fireball * fireball = fireballs.acquire(); @@ -364,10 +362,6 @@ GAME_FRAME( game_frame ) { } { - ImmediateContext imm; - static ImmediateTriangle asdf[ megabytes( 1 ) ]; - immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); - { PROFILE_BLOCK( "Update fireballs" ); for( size_t i = 0; i < fireballs.elems.n; i++ ) { @@ -387,7 +381,7 @@ GAME_FRAME( game_frame ) { const float gravity = 9.81f; fireball->pos = new_pos; fireball->velocity.z -= dt * gravity; - immediate_sphere( &imm, fireball->pos, 4, v4( 1, 0, 0, 1 ), 4 ); + immediate_sphere( fireball->pos, 4, v4( 1, 0, 0, 1 ), 4 ); } } } @@ -395,15 +389,13 @@ GAME_FRAME( game_frame ) { RenderState fireball_render_state; fireball_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); fireball_render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms; - immediate_render( &imm, fireball_render_state ); - - immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); + immediate_render( fireball_render_state ); for( size_t i = 0; i < explosions.elems.n; i++ ) { Explosion * explosion = &explosions.elems[ i ]; float t = float( current_time - explosion->created_at ); if( t < 0.5f ) { - immediate_sphere( &imm, explosion->pos, t * 32.0f, v4( 1, 0.5, 0, 1 ), 4 ); + immediate_sphere( explosion->pos, t * 32.0f, v4( 1, 0.5, 0, 1 ), 4 ); } else { explosions.release( explosion ); @@ -414,7 +406,7 @@ GAME_FRAME( game_frame ) { RenderState explosion_render_state; explosion_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); explosion_render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms; - immediate_render( &imm, explosion_render_state ); + immediate_render( explosion_render_state ); } { @@ -504,22 +496,18 @@ GAME_FRAME( game_frame ) { last_connection_attempt = current_time; } - ImmediateContext imm; - ImmediateTriangle boxes[ 4096 ]; - immediate_init( &imm, boxes, ARRAY_COUNT( boxes ) ); - for( const Player & player : players.elems ) { if( player.sid != sid ) { v3 mins = player.pos - v3( 0.4f, 0.4f, 0.0f ); v3 maxs = player.pos + v3( 0.4f, 0.4f, EYE_HEIGHT + 0.1f ); - immediate_aabb( &imm, mins, maxs, v4( 1, 1, 0, 1 ) ); + immediate_aabb( mins, maxs, v4( 1, 1, 0, 1 ) ); } } RenderState impact_render_state; impact_render_state.shader = get_shader( SHADER_FLAT_VERTEX_COLOURS ); impact_render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms; - immediate_render( &imm, impact_render_state ); + immediate_render( impact_render_state ); } { diff --git a/immediate.cc b/immediate.cc @@ -2,45 +2,39 @@ #include <math.h> #include "intrinsics.h" +#include "array.h" #include "linear_algebra.h" #include "immediate.h" #include "renderer.h" -void immediate_init( ImmediateContext * ctx, ImmediateTriangle * memory, u32 max_triangles ) { - ctx->triangles = memory; - ctx->num_triangles = 0; - ctx->max_triangles = max_triangles; -} +struct ImmediateTriangle { + ImmediateVertex vertices[ 3 ]; +}; -void immediate_triangle( ImmediateContext * ctx, v3 p1, v3 p2, v3 p3, v4 colour ) { - ASSERT( ctx->num_triangles < ctx->max_triangles - 1 ); +static DynamicArray< ImmediateTriangle > triangles; +void immediate_triangle( v3 p1, v3 p2, v3 p3, v4 colour ) { v3 normal = normalize( cross( p2 - p1, p3 - p1 ) ); v2 uv( 0, 0 ); - ImmediateTriangle triangle = { { - { p1, normal, colour, uv }, - { p2, normal, colour, uv }, - { p3, normal, colour, uv }, - } }; - ctx->triangles[ ctx->num_triangles++ ] = triangle; -} + ImmediateTriangle triangle; + triangle.vertices[ 0 ] = { p1, normal, colour, uv }; + triangle.vertices[ 1 ] = { p2, normal, colour, uv }; + triangle.vertices[ 2 ] = { p3, normal, colour, uv }; -void immediate_triangle( - ImmediateContext * ctx, - ImmediateVertex v1, ImmediateVertex v2, ImmediateVertex v3 -) { - ASSERT( ctx->num_triangles < ctx->max_triangles - 1 ); + triangles.append( triangle ); +} - ImmediateTriangle triangle = { { v1, v2, v3 } }; +void immediate_triangle( ImmediateVertex v1, ImmediateVertex v2, ImmediateVertex v3 ) { + ImmediateTriangle triangle; + triangle.vertices[ 0 ] = v1; + triangle.vertices[ 1 ] = v2; + triangle.vertices[ 2 ] = v3; - ctx->triangles[ ctx->num_triangles++ ] = triangle; + triangles.append( triangle ); } -void immediate_sphere( - ImmediateContext * ctx, v3 centre, float radius, - v4 colour, u32 subdivisions -) { +void immediate_sphere( v3 centre, float radius, v4 colour, u32 subdivisions ) { const float azimuth_max = TAU; const float pitch_max = PI; @@ -68,8 +62,8 @@ void immediate_sphere( ImmediateVertex bottom_right = VERT( v3( ca1 * sp1, sa1 * sp1, cp1 ) ); #undef VERT - immediate_triangle( ctx, top_right, top_left, bottom_left ); - immediate_triangle( ctx, bottom_left, bottom_right, top_right ); + immediate_triangle( top_right, top_left, bottom_left ); + immediate_triangle( bottom_left, bottom_right, top_right ); sp0 = sp1; cp0 = cp1; @@ -84,7 +78,7 @@ void immediate_sphere( } } -void immediate_aabb( ImmediateContext * ctx, v3 mins, v3 maxs, v4 colour ) { +void immediate_aabb( v3 mins, v3 maxs, v4 colour ) { const v3 p0( mins.x, mins.y, mins.z ); const v3 p1( maxs.x, mins.y, mins.z ); const v3 p2( mins.x, maxs.y, mins.z ); @@ -94,18 +88,18 @@ void immediate_aabb( ImmediateContext * ctx, v3 mins, v3 maxs, v4 colour ) { const v3 p6( mins.x, maxs.y, maxs.z ); const v3 p7( maxs.x, maxs.y, maxs.z ); - immediate_triangle( ctx, p0, p2, p1, colour ); // bottom - immediate_triangle( ctx, p1, p2, p3, colour ); - immediate_triangle( ctx, p4, p5, p6, colour ); // top - immediate_triangle( ctx, p6, p5, p7, colour ); - immediate_triangle( ctx, p2, p0, p6, colour ); // left - immediate_triangle( ctx, p6, p0, p4, colour ); - immediate_triangle( ctx, p1, p3, p5, colour ); // right - immediate_triangle( ctx, p5, p3, p7, colour ); - immediate_triangle( ctx, p0, p1, p4, colour ); // front - immediate_triangle( ctx, p4, p1, p5, colour ); - immediate_triangle( ctx, p3, p2, p7, colour ); // back - immediate_triangle( ctx, p7, p2, p6, colour ); + immediate_triangle( p0, p2, p1, colour ); // bottom + immediate_triangle( p1, p2, p3, colour ); + immediate_triangle( p4, p5, p6, colour ); // top + immediate_triangle( p6, p5, p7, colour ); + immediate_triangle( p2, p0, p6, colour ); // left + immediate_triangle( p6, p0, p4, colour ); + immediate_triangle( p1, p3, p5, colour ); // right + immediate_triangle( p5, p3, p7, colour ); + immediate_triangle( p0, p1, p4, colour ); // front + immediate_triangle( p4, p1, p5, colour ); + immediate_triangle( p3, p2, p7, colour ); // back + immediate_triangle( p7, p2, p6, colour ); } static m3 about_with_sin_cos( v3 axis, float s, float c ) { @@ -134,10 +128,7 @@ static m3 rotation_between( v3 from, v3 to ) { return about_with_sin_cos( axis, sin_theta, cos_theta ); } -void immediate_arrow( - ImmediateContext * ctx, - v3 origin, v3 direction, float length, v4 colour -) { +void immediate_arrow( v3 origin, v3 direction, float length, v4 colour ) { v3 v[] = { // base of stick v3( -0.05f, -0.05f, 0.0f ), @@ -177,42 +168,41 @@ void immediate_arrow( cone[ i ] = ( rot * cone[ i ] ) * length + origin; } - immediate_triangle( ctx, v[ 0 ], v[ 2 ], v[ 1 ], colour ); // bottom - immediate_triangle( ctx, v[ 1 ], v[ 2 ], v[ 3 ], colour ); - immediate_triangle( ctx, v[ 4 ], v[ 5 ], v[ 6 ], colour ); // top - immediate_triangle( ctx, v[ 6 ], v[ 5 ], v[ 7 ], colour ); - immediate_triangle( ctx, v[ 2 ], v[ 0 ], v[ 6 ], colour ); // left - immediate_triangle( ctx, v[ 6 ], v[ 0 ], v[ 4 ], colour ); - immediate_triangle( ctx, v[ 1 ], v[ 3 ], v[ 5 ], colour ); // right - immediate_triangle( ctx, v[ 5 ], v[ 3 ], v[ 7 ], colour ); - immediate_triangle( ctx, v[ 0 ], v[ 1 ], v[ 4 ], colour ); // front - immediate_triangle( ctx, v[ 4 ], v[ 1 ], v[ 5 ], colour ); - immediate_triangle( ctx, v[ 3 ], v[ 2 ], v[ 7 ], colour ); // back - immediate_triangle( ctx, v[ 7 ], v[ 2 ], v[ 6 ], colour ); + immediate_triangle( v[ 0 ], v[ 2 ], v[ 1 ], colour ); // bottom + immediate_triangle( v[ 1 ], v[ 2 ], v[ 3 ], colour ); + immediate_triangle( v[ 4 ], v[ 5 ], v[ 6 ], colour ); // top + immediate_triangle( v[ 6 ], v[ 5 ], v[ 7 ], colour ); + immediate_triangle( v[ 2 ], v[ 0 ], v[ 6 ], colour ); // left + immediate_triangle( v[ 6 ], v[ 0 ], v[ 4 ], colour ); + immediate_triangle( v[ 1 ], v[ 3 ], v[ 5 ], colour ); // right + immediate_triangle( v[ 5 ], v[ 3 ], v[ 7 ], colour ); + immediate_triangle( v[ 0 ], v[ 1 ], v[ 4 ], colour ); // front + immediate_triangle( v[ 4 ], v[ 1 ], v[ 5 ], colour ); + immediate_triangle( v[ 3 ], v[ 2 ], v[ 7 ], colour ); // back + immediate_triangle( v[ 7 ], v[ 2 ], v[ 6 ], colour ); for( size_t i = 0; i < ARRAY_COUNT( cone ); i++ ) { - immediate_triangle( ctx, v[ 8 ], cone[ ( i + 1 ) % ARRAY_COUNT( cone ) ], cone[ i ], colour ); + immediate_triangle( v[ 8 ], cone[ ( i + 1 ) % ARRAY_COUNT( cone ) ], cone[ i ], colour ); } for( size_t i = 0; i < ARRAY_COUNT( cone ); i++ ) { - immediate_triangle( ctx, v[ 9 ], cone[ i ], cone[ ( i + 1 ) % ARRAY_COUNT( cone ) ], colour ); + immediate_triangle( v[ 9 ], cone[ i ], cone[ ( i + 1 ) % ARRAY_COUNT( cone ) ], colour ); } } -void immediate_render( const ImmediateContext * ctx, Shader shader, Texture texture ) { +void immediate_render( Shader shader, Texture texture ) { RenderState render_state; render_state.shader = shader; render_state.textures[ 0 ] = texture; - - immediate_render( ctx, render_state ); + immediate_render( render_state ); } -void immediate_render( const ImmediateContext * ctx, const RenderState & render_state ) { - if( ctx->num_triangles == 0 ) { +void immediate_render( const RenderState & render_state ) { + if( triangles.size() == 0 ) { return; } - VB vb = renderer_new_vb( ctx->triangles, ctx->num_triangles * sizeof( ImmediateTriangle ), BUFFERUSAGE_STREAM ); + VB vb = renderer_new_vb( triangles.ptr(), triangles.num_bytes(), BUFFERUSAGE_STREAM ); MeshConfig mesh_config; mesh_config.unified_buffer = vb; @@ -220,7 +210,7 @@ void immediate_render( const ImmediateContext * ctx, const RenderState & render_ mesh_config.positions_offset = checked_cast< u32 >( offsetof( ImmediateVertex, pos ) ); mesh_config.normals_offset = checked_cast< u32 >( offsetof( ImmediateVertex, normal ) ); mesh_config.colours_offset = checked_cast< u32 >( offsetof( ImmediateVertex, colour ) ); - mesh_config.num_vertices = ctx->num_triangles * 3; + mesh_config.num_vertices = triangles.size() * 3; if( render_state.textures[ 0 ] != 0 ) { mesh_config.tex_coords0_offset = checked_cast< u32 >( offsetof( ImmediateVertex, uv ) ); } @@ -228,8 +218,6 @@ void immediate_render( const ImmediateContext * ctx, const RenderState & render_ Mesh mesh = renderer_new_mesh( mesh_config ); renderer_draw_mesh( mesh, render_state ); renderer_delete_mesh( mesh ); -} -void immediate_clear( ImmediateContext * ctx ) { - ctx->num_triangles = 0; + triangles.clear(); } diff --git a/immediate.h b/immediate.h @@ -10,25 +10,12 @@ struct ImmediateVertex { v2 uv; }; -struct ImmediateTriangle { - ImmediateVertex vertices[ 3 ]; -}; - -struct ImmediateContext { - ImmediateTriangle * triangles; - u32 num_triangles; - u32 max_triangles; -}; - -void immediate_init( ImmediateContext * ctx, ImmediateTriangle * memory, u32 max_triangles ); - -void immediate_triangle( ImmediateContext * ctx, v3 p1, v3 p2, v3 p3, v4 colour ); -void immediate_triangle( ImmediateContext * ctx, ImmediateVertex v1, ImmediateVertex v2, ImmediateVertex v3 ); -void immediate_sphere( ImmediateContext * ctx, v3 centre, float radius, v4 colour, u32 subdivisions = 16 ); -void immediate_aabb( ImmediateContext * ctx, v3 mins, v3 maxs, v4 colour ); -void immediate_arrow( ImmediateContext * ctx, v3 origin, v3 direction, float length, v4 colour ); +void immediate_triangle( v3 p1, v3 p2, v3 p3, v4 colour ); +void immediate_triangle( ImmediateVertex v1, ImmediateVertex v2, ImmediateVertex v3 ); -void immediate_render( const ImmediateContext * ctx, Shader shader, Texture texture = 0 ); -void immediate_render( const ImmediateContext * ctx, const RenderState & render_state ); +void immediate_sphere( v3 centre, float radius, v4 colour, u32 subdivisions = 16 ); +void immediate_aabb( v3 mins, v3 maxs, v4 colour ); +void immediate_arrow( v3 origin, v3 direction, float length, v4 colour ); -void immediate_clear( ImmediateContext * ctx ); +void immediate_render( Shader shader, Texture texture = 0 ); +void immediate_render( const RenderState & render_state ); diff --git a/shadow_map.cc b/shadow_map.cc @@ -9,9 +9,6 @@ #include "log.h" #include "obj.h" -static ImmediateTriangle triangles[ 512000 ]; -static ImmediateContext imm; - static Mesh square; static FB shadow_fb; static Mesh tree_mesh; @@ -22,32 +19,30 @@ static v3 light_pos( -0, -10, 15 ); static v3 light_dir = v3_forward( -60, 90 ); 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[ UNIFORMS_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 ) ); + immediate_sphere( v3( 0, 0, 2 ), 2, v4( 1, 0, 0, 1 ) ); + immediate_sphere( v3( -3, 7, 2 ), 2, v4( 0, 1, 0, 1 ) ); - immediate_aabb( &imm, v3( 3, 3, 0 ), v3( 5, 5, 2 ), v4( 0, 0, 1, 1 ) ); - immediate_aabb( &imm, v3( 3, 0, 0 ), v3( 5, 2, 2 ), v4( 0, 0, 1, 1 ) ); - immediate_aabb( &imm, v3( 3, -3, 0 ), v3( 5, -1, 2 ), v4( 0, 0, 1, 1 ) ); - immediate_aabb( &imm, v3( 3, -6, 0 ), v3( 5, -4, 2 ), v4( 0, 0, 1, 1 ) ); + immediate_aabb( v3( 3, 3, 0 ), v3( 5, 5, 2 ), v4( 0, 0, 1, 1 ) ); + immediate_aabb( v3( 3, 0, 0 ), v3( 5, 2, 2 ), v4( 0, 0, 1, 1 ) ); + immediate_aabb( v3( 3, -3, 0 ), v3( 5, -1, 2 ), v4( 0, 0, 1, 1 ) ); + immediate_aabb( v3( 3, -6, 0 ), v3( 5, -4, 2 ), v4( 0, 0, 1, 1 ) ); if( draw_light ) { - immediate_sphere( &imm, light_pos, 0.1f, v4( 1, 1, 1, 1 ) ); - immediate_arrow( &imm, light_pos, light_dir, 0.5f, v4( 1, 1, 1, 1 ) ); + immediate_sphere( light_pos, 0.1f, v4( 1, 1, 1, 1 ) ); + immediate_arrow( light_pos, light_dir, 0.5f, v4( 1, 1, 1, 1 ) ); } v3 tl( -50, 50, 0 ); v3 tr( 50, 50, 0 ); v3 bl( -50, -50, 0 ); v3 br( 50, -50, 0 ); - immediate_triangle( &imm, tr, tl, bl, v4( 0.5, 0.5, 0.5, 1.0 ) ); - immediate_triangle( &imm, bl, br, tr, v4( 0.5, 0.5, 0.5, 1.0 ) ); + immediate_triangle( tr, tl, bl, v4( 0.5, 0.5, 0.5, 1.0 ) ); + immediate_triangle( bl, br, tr, v4( 0.5, 0.5, 0.5, 1.0 ) ); - immediate_render( &imm, render_state ); + immediate_render( render_state ); m4 M = m4_translation( v3( -7, -2, 0 ) ) * m4_rotx( deg_to_rad( 90 ) ); render_state.uniforms[ UNIFORMS_MODEL ] = renderer_uniforms( M ); diff --git a/text_renderer.cc b/text_renderer.cc @@ -20,8 +20,6 @@ static stbtt_fontinfo font_info; static const float pixel_sizes[] = { 16.0f, 32.0f, 48.0f }; static FontSize sizes[ ARRAY_COUNT( pixel_sizes ) ]; -static ImmediateTriangle triangles[ 4096 ]; - void text_renderer_init() { ttf = file_get_contents( "LiberationSans-Regular.ttf" ); @@ -61,9 +59,6 @@ void text_renderer_init() { void draw_text( const char * str, int x, int y, float pixel_size ) { const v4 white( 1, 1, 1, 1 ); - ImmediateContext imm; - immediate_init( &imm, triangles, ARRAY_COUNT( triangles ) ); - size_t size_idx = 0; for( size_t i = 0; i < ARRAY_COUNT( sizes ); i++ ) { size_idx = i; @@ -109,8 +104,8 @@ void draw_text( const char * str, int x, int y, float pixel_size ) { v2( q.s1, q.t1 ), }; - immediate_triangle( &imm, tr, tl, bl ); - immediate_triangle( &imm, bl, br, tr ); + immediate_triangle( tr, tl, bl ); + immediate_triangle( bl, br, tr ); str++; } @@ -123,7 +118,7 @@ void draw_text( const char * str, int x, int y, float pixel_size ) { render_state.enable_alpha_blending = true; // render_state.disable_depth_writes = true; - immediate_render( &imm, render_state ); + immediate_render( render_state ); } void text_renderer_term() {