-VG_STATIC GLuint vg_tex2d_new(void)
-{
- GLuint texture_name;
- glGenTextures( 1, &texture_name );
- glBindTexture( GL_TEXTURE_2D, texture_name );
-
- return texture_name;
-}
-
-VG_STATIC void vg_tex2d_set_error(void)
-{
- u32 tex_err[4] =
- {
- 0xffff00ff,
- 0xff000000,
- 0xff000000,
- 0xffff00ff
- };
-
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 2, 2,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_err );
-}
-
-VG_STATIC void vg_tex2d_qoi( void *mem, u32 size, const char *name )
-{
- qoi_desc info;
- u8 *tex_buffer = qoi_decode( mem, size, &info, 4 );
-
- if( tex_buffer )
- {
- vg_info( "Texture decoded: [%u %u] %s\n",
- info.width, info.height, name );
-
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, info.width, info.height,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_buffer );
-
- QOI_FREE(tex_buffer);
- }
- else
- {
- vg_error( "File size: %u\n", size );
- vg_tex2d_set_error();
- }
-}
-
-VG_STATIC GLuint vg_tex2d_rgba( const char *path )
-{
- GLuint texture_name = vg_tex2d_new();
-
- vg_linear_clear( vg_mem.scratch );
- u32 size;
- void *file = vg_file_read( vg_mem.scratch, path, &size );
-
- if( file )
- {
- vg_tex2d_qoi( file, size, path );
- }
- else
- {
- vg_error( "Loading texture failed (%s)\n", path );
- vg_tex2d_set_error();
- }
-
- return texture_name;
-}
-
-VG_STATIC void vg_tex2d_init( vg_tex2d *textures[], int num )
-{
- for( int i=0; i<num; i ++ )
- {
- vg_tex2d *tex = textures[i];
- tex->name = vg_tex2d_rgba( tex->path );
- if( !(tex->flags & VG_TEXTURE_NO_MIP) )
- vg_tex2d_mipmap();
-
- if( tex->flags & VG_TEXTURE_NEAREST )
- {
- if( tex->flags & VG_TEXTURE_NO_MIP )
- vg_error( "Invalid texture settings\n" );
- else
- vg_tex2d_nearest();
- }
- else
- {
- if( tex->flags & VG_TEXTURE_NO_MIP )
- vg_tex2d_linear();
- else
- vg_tex2d_linear_mipmap();
- }
-
- if( tex->flags & VG_TEXTURE_CLAMP )
- vg_tex2d_clamp();
- else
- vg_tex2d_repeat();
-
- tex->flags |= VG_TEXTURE_ALLOCATED_INTERNAL;
- }
-}
-
-VG_STATIC void vg_tex2d_free( vg_tex2d *textures[], int num )
-{
- for( int i = 0; i < num; i ++ )
- {
- glDeleteTextures( 1, &textures[i]->name );
- }
-}