medfall

A super great game engine
Log | Files | Refs

commit c44b3af3425d6f8db8737a037e7cf6933213a954
parent 9372d70ac10f2b4a0b42993bb5d4050140b9aae4
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue, 21 Nov 2017 00:38:35 +0200

Draw the centre cross filler mesh

Diffstat:
clipmap.cc | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+), 0 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -26,6 +26,7 @@ struct ClipmapTerrain { Mesh horizontal_filler; Mesh vertical_filler; Mesh trim; + Mesh cross; Mesh seam; Mesh skirt; Texture heightmap; @@ -367,6 +368,74 @@ GAME_INIT( game_init ) { clipmap.gpu.trim = renderer_new_mesh( mesh_config ); } + // generate cross mesh + { + MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena ); + + array< v3 > vertices = alloc_array< v3 >( &mem->persistent_arena, PATCH_RESOLUTION * 8 + 4 ); + size_t n = 0; + + // horizontal vertices + for( u32 i = 0; i < PATCH_RESOLUTION * 2 + 1; i++ ) { + vertices[ n++ ] = v3( i - float( PATCH_RESOLUTION ), 0, 0 ); + vertices[ n++ ] = v3( i - float( PATCH_RESOLUTION ), 1, 0 ); + } + + size_t start_of_vertical = n; + + // vertical vertices + for( u32 i = 0; i < PATCH_RESOLUTION * 2 + 1; i++ ) { + vertices[ n++ ] = v3( 0, i - float( PATCH_RESOLUTION ), 0 ); + vertices[ n++ ] = v3( 1, i - float( PATCH_RESOLUTION ), 0 ); + } + + ASSERT( n == vertices.n ); + + array< u32 > indices = alloc_array< u32 >( &mem->persistent_arena, PATCH_RESOLUTION * 24 - 6 ); + n = 0; + + // horizontal indices + for( u32 i = 0; i < PATCH_RESOLUTION * 2; i++ ) { + u32 bl = i * 2 + 0; + u32 br = i * 2 + 1; + u32 tl = i * 2 + 2; + u32 tr = i * 2 + 3; + + indices[ n++ ] = br; + indices[ n++ ] = bl; + indices[ n++ ] = tr; + indices[ n++ ] = bl; + indices[ n++ ] = tl; + indices[ n++ ] = tr; + } + + // vertical indices + for( u32 i = 0; i < PATCH_RESOLUTION * 2; i++ ) { + if( i == PATCH_RESOLUTION ) + continue; + + u32 bl = i * 2 + 0; + u32 br = i * 2 + 1; + u32 tl = i * 2 + 2; + u32 tr = i * 2 + 3; + + indices[ n++ ] = start_of_vertical + br; + indices[ n++ ] = start_of_vertical + tr; + indices[ n++ ] = start_of_vertical + bl; + indices[ n++ ] = start_of_vertical + bl; + indices[ n++ ] = start_of_vertical + tr; + indices[ n++ ] = start_of_vertical + tl; + } + + ASSERT( n == indices.n ); + + MeshConfig mesh_config; + mesh_config.positions = renderer_new_vb( vertices ); + mesh_config.indices = renderer_new_ib( indices ); + mesh_config.num_vertices = indices.n; + clipmap.gpu.cross = renderer_new_mesh( mesh_config ); + } + // generate skirt mesh { float scale = checked_cast< float >( u32( 1 ) << ( NUM_LODS - 1 ) ); @@ -653,6 +722,14 @@ GAME_FRAME( game_frame ) { render_state.textures[ 3 ] = renderer_blue_noise(); render_state.wireframe = game->draw_wireframe; + // draw cross + { + v2 snapped_pos = floorf( game->pos.xy() ); + render_state.uniforms[ UNIFORMS_MODEL ] = rotation_uniforms[ 0 ]; + render_state.uniforms[ UNIFORMS_CLIPMAP ] = renderer_uniforms( snapped_pos, 1.0f ); + renderer_draw_mesh( clipmap.gpu.cross, render_state ); + } + for( u32 l = 0; l < NUM_LODS; l++ ) { float scale = checked_cast< float >( u32( 1 ) << l ); v2 tile_size = v2( checked_cast< float >( PATCH_RESOLUTION << l ) );