medfall

A super great game engine
Log | Files | Refs

commit 0fb79e51b6353a2c61d31553fcb1363888188a3b
parent 3b804ad7683ba9afae3c98b1904a5af8cad311a9
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Thu,  9 Nov 2017 20:39:58 +0200

Don't use lodepng in terrain_manager/obj

Diffstat:
make.lua | 2+-
obj.cc | 39++++++++++++++-------------------------
pp2.cc | 6+++---
terrain_manager.cc | 15+++++----------
4 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/make.lua b/make.lua @@ -2,7 +2,7 @@ require( "scripts.gen_makefile" ) local common_objs = { "memory_arena", "log", "ggformat", "patterns", "strlcpy", "strlcat", "strtonum", "profiler", "stats", "rng/well512", "breakbools" } local game_objs = { "work_queue", "renderer", "shaders", "gl", "glad", "immediate", "text_renderer", "liberation", "obj", "blue_noise", common_objs } -local game_libs = { "glfw", "lodepng", "stb_truetype", "tinyobjloader" } +local game_libs = { "glfw", "stb_image", "stb_truetype", "tinyobjloader" } if OS ~= "windows" then bin( "srv", { "server/main", "platform_network", common_objs } ) diff --git a/obj.cc b/obj.cc @@ -2,7 +2,8 @@ #include "memory_arena.h" #include "renderer.h" -#include "libs/lodepng/lodepng.h" +#include "libs/stb/stb_image.h" + #include "libs/tinyobjloader/tinyobjloader.h" Mesh load_obj( const char * path, MemoryArena * arena ) { @@ -49,47 +50,35 @@ Mesh load_obj( const char * path, MemoryArena * arena ) { } Texture load_png( const char * path, TextureFormat format, int channels ) { - LodePNGColorType color = LCT_RGBA; - if( channels == 1 ) color = LCT_GREY; - if( channels == 2 ) color = LCT_GREY_ALPHA; - if( channels == 3 ) color = LCT_RGB; - - u32 w, h; - u8 * data; - u32 ok = lodepng_decode_file( &data, &w, &h, path, color, 8 ); - ASSERT( ok == 0 ); + int w, h; + u8 * img = stbi_load( path, &w, &h, NULL, channels ); + ASSERT( img != NULL ); TextureConfig texture_config; - texture_config.width = w; - texture_config.height = h; - texture_config.data = data; + texture_config.width = checked_cast< u32 >( w ); + texture_config.height = checked_cast< u32 >( h ); + texture_config.data = img; texture_config.format = format; Texture texture = renderer_new_texture( texture_config ); - free( data ); + stbi_image_free( img ); return texture; } Texture load_png_memory( const u8 * data, size_t len, TextureFormat format, int channels ) { - LodePNGColorType color = LCT_RGBA; - if( channels == 1 ) color = LCT_GREY; - if( channels == 2 ) color = LCT_GREY_ALPHA; - if( channels == 3 ) color = LCT_RGB; - - u32 w, h; - u8 * decoded; - u32 ok = lodepng_decode_memory( &decoded, &w, &h, data, len, color, 8 ); - ASSERT( ok == 0 ); + int w, h; + u8 * img = stbi_load_from_memory( data, checked_cast< int >( len ), &w, &h, NULL, channels ); + ASSERT( img != NULL ); TextureConfig texture_config; texture_config.width = w; texture_config.height = h; - texture_config.data = decoded; + texture_config.data = img; texture_config.format = format; Texture texture = renderer_new_texture( texture_config ); - free( decoded ); + stbi_image_free( img ); return texture; } diff --git a/pp2.cc b/pp2.cc @@ -7,14 +7,14 @@ #include "heightmap.h" #include "autogdb.h" +#include "libs/lz4/lz4.h" +#include "libs/lz4/lz4hc.h" + #include "libs/squish/squish.h" #include "libs/stb/stb_image.h" #include "libs/stb/stb_image_write.h" -#include "libs/lz4/lz4.h" -#include "libs/lz4/lz4hc.h" - static float tan_theta( v2 a, v2 b ) { v2 d = a - b; return -d.y / d.x; diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -18,10 +18,10 @@ #include "shaders.h" #include "obj.h" -#include "libs/lodepng/lodepng.h" - #include "libs/lz4/lz4.h" +#include "libs/stb/stb_image.h" + struct AsyncLoadTile { TerrainManager * tm; s32 tx, ty; @@ -101,15 +101,10 @@ static WORK_QUEUE_CALLBACK( async_load_tile ) { dt.normalmap = decompressed_normalmap; // horizonmap - u8 * decompressed_horizonmap; + int w, h; + u8 * decompressed_horizonmap = stbi_load_from_memory( ct.horizonmap.ptr(), checked_cast< int >( ct.horizonmap.n ), &w, &h, NULL, 1 ); size_t decompressed_horizonmap_size = align4( TILE_SIZE + 1 ) * ( TILE_SIZE + 1 ) * sizeof( u8 ); - { - u32 w, h; - unsigned ok_horizonmap = lodepng_decode_memory( &decompressed_horizonmap, &w, &h, - ct.horizonmap.ptr(), ct.horizonmap.n, LCT_GREY, 8 ); - ASSERT( ok_horizonmap == 0 ); - ASSERT( decompressed_horizonmap != NULL ); - } + ASSERT( decompressed_horizonmap != NULL ); // quadtree size_t max_decompressed_quadtree_size = heightmap_quadtree_max_nodes( &dt.heightmap ) * sizeof( HeightmapQuadTreeNode );