medfall

A super great game engine
Log | Files | Refs

commit a90e3cb42e4b60af9fdcc7d440b67ab0ef19b579
parent 8c6a0f731825ac9d324a782cb41a69a24eccb65f
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue, 14 Nov 2017 23:50:56 +0200

Use fans for empty tile meshes because it will make seams easier

Diffstat:
clipmap.cc | 28++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -223,18 +223,30 @@ GAME_INIT( game_init ) { // generate empty tile mesh { - StaticArray< v3, 4 > vertices; - vertices[ 0 ] = v3( 0, 0, 0 ); - vertices[ 1 ] = v3( PATCH_RESOLUTION, 0, 0 ); - vertices[ 2 ] = v3( 0, PATCH_RESOLUTION, 0 ); - vertices[ 3 ] = v3( PATCH_RESOLUTION, PATCH_RESOLUTION, 0 ); + StaticArray< v3, PATCH_RESOLUTION * 4 + 1 > vertices; + vertices[ 0 ] = v3( PATCH_RESOLUTION / 2.0f, PATCH_RESOLUTION / 2.0f, 0 ); + + for( u32 i = 0; i < PATCH_RESOLUTION; i++ ) { + vertices[ i + 1 + 0 * PATCH_RESOLUTION ] = v3( i, 0, 0 ); + vertices[ i + 1 + 1 * PATCH_RESOLUTION ] = v3( PATCH_RESOLUTION, i, 0 ); + vertices[ i + 1 + 2 * PATCH_RESOLUTION ] = v3( PATCH_RESOLUTION - i, PATCH_RESOLUTION, 0 ); + vertices[ i + 1 + 3 * PATCH_RESOLUTION ] = v3( 0, PATCH_RESOLUTION - i, 0 ); + } + + StaticArray< u32, PATCH_RESOLUTION * 12 > indices; + + for( u32 i = 0; i < PATCH_RESOLUTION * 4; i++ ) { + indices[ i * 3 + 0 ] = 0; + indices[ i * 3 + 1 ] = i + 1; + indices[ i * 3 + 2 ] = i + 2; + } - u32 indices[] = { 0, 1, 2, 2, 1, 3 }; + indices[ indices.size() - 1 ] = 1; MeshConfig mesh_config; mesh_config.positions = renderer_new_vb( vertices.ptr(), vertices.num_bytes() ); - mesh_config.indices = renderer_new_ib( indices, sizeof( indices ) ); - mesh_config.num_vertices = ARRAY_COUNT( indices ); + mesh_config.indices = renderer_new_ib( indices.ptr(), indices.num_bytes() ); + mesh_config.num_vertices = indices.size(); clipmap.gpu.empty_tile = renderer_new_mesh( mesh_config ); }