commit ac3093136c339ecbad5982981f234aca19714031
parent 5e4efedc0a68600f7cdb2b3e4025ac933d853e27
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 4 Nov 2017 15:41:12 +0200
Use my BC5 decoder in the clipmap engine
Diffstat:
3 files changed, 56 insertions(+), 51 deletions(-)
diff --git a/clipmap.cc b/clipmap.cc
@@ -5,13 +5,12 @@
#include "shaders.h"
#include "immediate.h"
#include "text_renderer.h"
+#include "decompress_bc.h"
#include "gl.h"
#include "skybox.h"
#include "libs/lz4/lz4.h"
-#include "libs/squish/squish.h"
-
struct ClipmapTerrain
{
Mesh tile;
@@ -44,6 +43,7 @@ struct RGBA {
};
GAME_INIT( game_init ) {
+ // load quadtree
{
Heightmap * hm = alloc< Heightmap >( &mem->persistent_arena );
hm->width = hm->height = 4096;
@@ -56,61 +56,66 @@ GAME_INIT( game_init ) {
clipmap.quadtree.hm = hm;
clipmap.quadtree.nodes_memory = nodes.ptr();
clipmap.quadtree.nodes = nodes;
+ }
- {
- MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
+ // load heightmap
+ {
+ MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
- u8 * heightmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 );
- file_get_contents_and_decompress( "terrains/gta16.png.parts/heightmap.bc5.lz4", heightmap_data, 4096 * 4096 );
+ u8 * heightmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 );
+ file_get_contents_and_decompress( "terrains/gta16.png.parts/heightmap.bc5.lz4", heightmap_data, 4096 * 4096 );
- TextureConfig texture_config;
- texture_config.width = 4096;
- texture_config.height = 4096;
- texture_config.data = heightmap_data;
- texture_config.format = TEXFMT_BC5;
- texture_config.wrap = TEXWRAP_BORDER;
- texture_config.border_colour = v4( 0 );
- clipmap.heightmap = renderer_new_texture( texture_config );
+ TextureConfig texture_config;
+ texture_config.width = 4096;
+ texture_config.height = 4096;
+ texture_config.data = heightmap_data;
+ texture_config.format = TEXFMT_BC5;
+ texture_config.wrap = TEXWRAP_BORDER;
+ texture_config.border_colour = v4( 0 );
+ clipmap.heightmap = renderer_new_texture( texture_config );
- RGBA * rgba = memarena_push_many( &mem->persistent_arena, RGBA, 4096 * 4096 );
- squish::DecompressImage( ( u8 * ) rgba, 4096, 4096, heightmap_data, squish::kBc5 );
+ array2d< v2 > rg = alloc_array2d< v2 >( &mem->persistent_arena, 4096, 4096 );
+ decompress_bc5( rg, heightmap_data );
- for( size_t i = 0; i < 4096 * 4096; i++ ) {
- clipmap.quadtree.hm->pixels[ i ] = u16( rgba[ i ].r ) * u16( 255 ) + u16( rgba[ i ].g );
+ for( size_t y = 0; y < 4096; y++ ) {
+ for( size_t x = 0; x < 4096; x++ ) {
+ clipmap.quadtree.hm->pixels[ y * 4096 + x ] = u16( ( rg( x, y ).x * 256.0f + rg( x, y ).y ) * 255.0f );
}
}
+ }
- {
- MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
-
- u8 * normalmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 );
- file_get_contents_and_decompress( "terrains/gta16.png.parts/normalmap.bc5.lz4", normalmap_data, 4096 * 4096 );
-
- TextureConfig texture_config;
- texture_config.width = 4096;
- texture_config.height = 4096;
- texture_config.data = normalmap_data;
- texture_config.format = TEXFMT_BC5;
- texture_config.wrap = TEXWRAP_BORDER;
- texture_config.border_colour = v4( 0.5f );
- clipmap.normalmap = renderer_new_texture( texture_config );
- }
+ // load normalmap
+ {
+ MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
- {
- MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
-
- u8 * horizonmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 / 2 );
- file_get_contents_and_decompress( "terrains/gta16.png.parts/horizonmap.bc4.lz4", horizonmap_data, 4096 * 4096 / 2 );
-
- TextureConfig texture_config;
- texture_config.width = 4096;
- texture_config.height = 4096;
- texture_config.data = horizonmap_data;
- texture_config.format = TEXFMT_BC4;
- texture_config.wrap = TEXWRAP_BORDER;
- texture_config.border_colour = v4( 0 );
- clipmap.horizonmap = renderer_new_texture( texture_config );
- }
+ u8 * normalmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 );
+ file_get_contents_and_decompress( "terrains/gta16.png.parts/normalmap.bc5.lz4", normalmap_data, 4096 * 4096 );
+
+ TextureConfig texture_config;
+ texture_config.width = 4096;
+ texture_config.height = 4096;
+ texture_config.data = normalmap_data;
+ texture_config.format = TEXFMT_BC5;
+ texture_config.wrap = TEXWRAP_BORDER;
+ texture_config.border_colour = v4( 0.5f );
+ clipmap.normalmap = renderer_new_texture( texture_config );
+ }
+
+ // load horizonmap
+ {
+ MEMARENA_SCOPED_CHECKPOINT( &mem->persistent_arena );
+
+ u8 * horizonmap_data = memarena_push_size( &mem->persistent_arena, 4096 * 4096 / 2 );
+ file_get_contents_and_decompress( "terrains/gta16.png.parts/horizonmap.bc4.lz4", horizonmap_data, 4096 * 4096 / 2 );
+
+ TextureConfig texture_config;
+ texture_config.width = 4096;
+ texture_config.height = 4096;
+ texture_config.data = horizonmap_data;
+ texture_config.format = TEXFMT_BC4;
+ texture_config.wrap = TEXWRAP_BORDER;
+ texture_config.border_colour = v4( 0 );
+ clipmap.horizonmap = renderer_new_texture( texture_config );
}
// generate tile mesh
@@ -263,7 +268,7 @@ GAME_FRAME( game_frame ) {
v3 normal;
if( ray_vs_quadtree( &clipmap.quadtree, Ray3( game->pos + v3( 2048, 2048, 0 ), forward ), &t, &normal ) ) {
v3 impact = game->pos + forward * t;
- immediate_arrow( impact, v3( 0, 0, 1 ), 16, v4( 0, 1, 1, 1 ) );
+ immediate_arrow( impact, normal, 16, v4( 0, 1, 1, 1 ) );
}
RenderState impact_render_state;
diff --git a/main.cc b/main.cc
@@ -22,7 +22,7 @@ GameFrame game_frame;
int main( int argc, char ** argv ) {
install_debug_signal_handlers( true );
- size_t persistent_size = megabytes( 150 );
+ size_t persistent_size = megabytes( 256 );
u8 * persistent_memory = ( u8 * ) malloc( persistent_size );
if( persistent_memory == NULL ) {
FATAL( "couldn't allocate persistent memory" );
diff --git a/make.lua b/make.lua
@@ -51,7 +51,7 @@ bin( "bsp", { "main", "bsp", "bsp_renderer", game_objs }, { game_libs } )
-- TODO: fix btt build
-- bin( "btt", { "main", "mod_btt", "btt", "heightmap", "skybox", "lz4", game_objs }, { "stb_image", game_libs } )
bin( "sm", { "main", "shadow_map", game_objs }, { game_libs } )
-bin( "clipmap", { "main", "clipmap", "heightmap", "skybox", game_objs }, { "lz4", "squish", game_libs } )
+bin( "clipmap", { "main", "clipmap", "heightmap", "skybox", "decompress_bc", game_objs }, { "lz4", game_libs } )
msvc_bin_ldflags( "bsp", "opengl32.lib gdi32.lib" )
gcc_bin_ldflags( "bsp", game_ldflags )