LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_astc_loader.c File Reference

Functions

void * lg_load_astc (const char *path, lg_tc_format *tc_format, size_t *size, int *w, int *h, int *n_mipmaps)
 
void * lg_load_etc1 (const char *path, lg_tc_format *tc_format, size_t *size, int *w, int *h, int *n_mipmaps)
 

Detailed Description

 === Loading of ASTC and ETC1 compressed textures on Android ===

Function Documentation

◆ lg_load_astc()

void* lg_load_astc ( const char *  path,
lg_tc_format *  tc_format,
size_t *  size,
int *  w,
int *  h,
int *  n_mipmaps 
)

Load an ASTC compressed texture

Returned data must be freed afterwards

 Android: ASTC      ->      GL_KHR_texture_compression_astc_ldr/hdr
                    GL_EXT_texture_compression_astc_decode_mode
    16 bytes per compressed block
    Not available on all devices

 (https://github.com/ARM-software/astc-encoder/blob/main/Docs/FileFormat.md)

 === ASTC layout ===

    struct  ASTC_Header
    void    *data

 sizeof(ASTC_Header) = 16 bytes

 See: lg_astc_loader.h

 Using ASTC encoder from https://launchpad.net/~roehling/+archive/ubuntu/open3d?field.series_filter=focal
    - Enable PPA
    - Install astenc

    astcenc -cl wallpaper2_1024x512.png wallpaper2_1024x512.astc 4x4 -thorough

 Doc: astcenc -help |less

 If no ASTC support, fallback to ETC1 (available on most devices)
Parameters
path
tc_formatPointer to lg_tc_format which will store compressed texture format
sizePointer to size_t which will store compressed texture size (cumulative size, ie of all levels, but excluding magic and header)
wPointer to int which will store width (of level 0)
hPointer to int which will store height (of level 0)
n_mipmapsPointer to int which will store number of generated mipmaps
Returns
Pointer to compressed texture data if OK, NULL on error

◆ lg_load_etc1()

void* lg_load_etc1 ( const char *  path,
lg_tc_format *  tc_format,
size_t *  size,
int *  w,
int *  h,
int *  n_mipmaps 
)

Load an ETC1 compressed texture

Fallback if no ASTC support

Returned data must be freed afterwards

 Android: ETC1      ->      GL_OES_compressed_ETC1_RGB8_texture
    6:1 compression ratio
    4x4 pixels block -> 64 bits = 8 bytes
    Container: PKM file, header size = 16
    Available on most devices

 === PKM/ETC1 layout ===

    struct  PKM_Header
    void    *data

 sizeof(PKM_Header) = 16 bytes

 See: lg_astc_loader.h

 To create PKM/ETC1 files:
    etc1tool (in Android SDK)
Parameters
path
tc_formatPointer to lg_tc_format which will store compressed texture format
sizePointer to size_t which will store compressed texture size (cumulative size, ie of all levels, but excluding magic and header)
wPointer to int which will store width (of level 0)
hPointer to int which will store height (of level 0)
n_mipmapsPointer to int which will store number of generated mipmaps
Returns
Pointer to compressed texture data if OK, NULL on error