X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=src%2Fvg%2Fvg_tex.h;h=6c7c40335a6d0e7c28ea2c57f558d89822ef9990;hb=5df88af6730a8b9c4ef698070bb729866ed2e597;hp=e92e5f152582258af9b0c73d59713a68f1be8764;hpb=a83978cdbdf393dc37362bff71d828b9b00c6879;p=vg.git diff --git a/src/vg/vg_tex.h b/src/vg/vg_tex.h index e92e5f1..6c7c403 100644 --- a/src/vg/vg_tex.h +++ b/src/vg/vg_tex.h @@ -11,9 +11,9 @@ #define VG_TEXTURE_NEAREST 0x8 #define VG_TEXTURE_ALLOCATED_INTERNAL 0x10 +/* TODO: Update this implementation */ #define QOI_IMPLEMENTATION -#define QOI_MALLOC vg_alloc -#define QOI_FREE vg_free +#define QOI_NO_STDIO #include "phoboslab/qoi.h" @@ -29,7 +29,7 @@ struct vg_sprite v4f uv_xywh; }; -static void vg_tex2d_bind( vg_tex2d *tex, u32 id ) +VG_STATIC void vg_tex2d_bind( vg_tex2d *tex, u32 id ) { if( !(tex->flags & VG_TEXTURE_ALLOCATED_INTERNAL) ) { @@ -77,28 +77,44 @@ static inline void vg_tex2d_clamp(void) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); } -static GLuint vg_tex2d_rgba( const char *path ) +VG_STATIC GLuint vg_tex2d_rgba( const char *path ) { - i64 length; - u8 *src_data = vg_asset_read_s( path, &length ); - GLuint texture_name; glGenTextures( 1, &texture_name ); glBindTexture( GL_TEXTURE_2D, texture_name ); - - if( src_data ) - { + + vg_linear_clear( vg_mem.scratch ); + void *file = vg_file_read( vg_mem.scratch, path ); + + if( file ) + { qoi_desc info; - u8 *tex_buffer = qoi_decode( src_data, length, &info, 4 ); - - glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_buffer ); - - vg_free( tex_buffer ); - vg_free( src_data ); - } - else - { + + u32 size = vg_file_size( vg_mem.scratch ); + u8 *tex_buffer = qoi_decode( file, size, &info, 4 ); + + if( tex_buffer ) + { + vg_info( "Texture decoded: [%u %u] %s\n", + info.width, info.height, path ); + + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_buffer ); + + /* TODO: pass through linear_alloc function */ + QOI_FREE(tex_buffer); + } + else + { + vg_error( "File size: %u\n", size ); + goto temp_error; + } + } + else + { +temp_error: + vg_error( "Loading texture failed (%s)\n", path ); + u32 tex_err[4] = { 0xffff00ff, @@ -107,15 +123,14 @@ static GLuint vg_tex2d_rgba( const char *path ) 0xffff00ff }; - vg_error( "Loading texture failed (%s)\n", path ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, - 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_err ); - } - + 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_err ); + } + return texture_name; } -static void vg_tex2d_init( vg_tex2d *textures[], int num ) +VG_STATIC void vg_tex2d_init( vg_tex2d *textures[], int num ) { for( int i=0; i