Skip to content

Instantly share code, notes, and snippets.

@Griefchief
Last active September 17, 2022 15:34
Show Gist options
  • Save Griefchief/500910e8c9dce659353d605315bd9b7d to your computer and use it in GitHub Desktop.
Save Griefchief/500910e8c9dce659353d605315bd9b7d to your computer and use it in GitHub Desktop.
Godot Streamable Texture Format 2 Documentation

Full DataFormat

: is zero byte separator. every other char is 1 byte

FILESTART is -		GST2:VERS:WDTH:HGHT:DTFM:MMLM:RSVD:RSVD:RSVD
IMAGE_FORMAT is -	FRMT:WI:HG:MIPA:FRM2
IMAGE_PAYLOAD is -  SIZE:IMAGEPAYLOAD
					SIZE:IMAGEPAYLOAD
					SIZE:IMAGEPAYLOAD
					SIZE:IMAGEPAYLOAD
					SIZE:IMAGEPAYLOAD

FILESTART in detail

FILESTART is		GST2:VERS:WDTH:HGHT:DTFM:MMRS:MRSV:RSVD:RSVD:RSVD

Legend:
GST2  - 4 byte ASCII, has to be 'GST2'
VERS - uint32 (4 bytes) file version, has to be 1 in code or CompressedTexture2D::load_image quits
WDTH - uint32 width
HGHT - uint32 height
DTFM - uint32 DataFormat of the file as 1 bit flags: see enum FormatBits
MMLM - MipMap limit

IMAGE_FORMAT in detail: Data based on DRFM format, godot simply loads it as "load image"

IMAGE_PAYLOAD is -	FRMT:WI:HG:MIPA:FRM2

FRMT - uint32 - image format enum Texture::DataFormat: "image", "png", "webp", "basis_universal"
WI - uint16 - width
HG - uint16 - height
MIPA - uint32 - literally number of mipmaps as a uint, they are loaded in a for controlled 	by MIPM
FRM2 - uint32 - format of the image based on enum Image::Format, see bellow

IMAGE_PAYLOAD om detail: Contains two things, a 4 byte uint indicating size and the actual PNG, WebP, basis_universal or (raw) Image.

flag FORMAT_BIT_STREAM DRFM if not set, will read the whole file, if set, will read based on max size given when loading only then will PAYLOAD be rocessed to be read as an image by CompressedTexture2D.

/scene/resources/texture.h // enum FormatBits { FORMAT_BIT_STREAM = 1 << 22, FORMAT_BIT_HAS_MIPMAPS = 1 << 23, FORMAT_BIT_DETECT_3D = 1 << 24, //FORMAT_BIT_DETECT_SRGB = 1 << 25, FORMAT_BIT_DETECT_NORMAL = 1 << 26, FORMAT_BIT_DETECT_ROUGNESS = 1 << 27, };

/scene/resources/image.h // enum DataFormat { DATA_FORMAT_IMAGE, DATA_FORMAT_PNG, DATA_FORMAT_WEBP, DATA_FORMAT_BASIS_UNIVERSAL, };

========================================================

IMHEX pattern for editor:

image

/*enum FormatBitsForReference : u32 {
FORMAT_BIT_STREAM = 1 << 22,
FORMAT_BIT_HAS_MIPMAPS = 1 << 23,
FORMAT_BIT_DETECT_3D = 1 << 24,
//FORMAT_BIT_DETECT_SRGB = 1 << 25,
FORMAT_BIT_DETECT_NORMAL = 1 << 26,
FORMAT_BIT_DETECT_ROUGNESS = 1 << 27,
};*/
bitfield FormatBitsBitfield {
FORMAT_BIT_STREAM:1;
FORMAT_BIT_HAS_MIPMAPS:1;
FORMAT_BIT_DETECT_3D: 1;
padding:1;
//FORMAT_BIT_DETECT_SRGB = 1 << 25,
FORMAT_BIT_DETECT_NORMAL :1;
FORMAT_BIT_DETECT_ROUGNESS :1;
padding: 21; // no idea why bitfields are reversed but they are
};
enum DataFormat: u32 {
DATA_FORMAT_IMAGE,
DATA_FORMAT_PNG,
DATA_FORMAT_WEBP,
DATA_FORMAT_BASIS_UNIVERSAL,
};
enum ImageFormat : u32 {
FORMAT_L8, //luminance
FORMAT_LA8, //luminance-alpha
FORMAT_R8,
FORMAT_RG8,
FORMAT_RGB8,
FORMAT_RGBA8,
FORMAT_RGBA4444,
FORMAT_RGB565,
FORMAT_RF, //float
FORMAT_RGF,
FORMAT_RGBF,
FORMAT_RGBAF,
FORMAT_RH, //half float
FORMAT_RGH,
FORMAT_RGBH,
FORMAT_RGBAH,
FORMAT_RGBE9995,
FORMAT_DXT1, //s3tc bc1
FORMAT_DXT3, //bc2
FORMAT_DXT5, //bc3
FORMAT_RGTC_R,
FORMAT_RGTC_RG,
FORMAT_BPTC_RGBA, //btpc bc7
FORMAT_BPTC_RGBF, //float bc6h
FORMAT_BPTC_RGBFU, //unsigned float bc6hu
FORMAT_ETC, //etc1
FORMAT_ETC2_R11, //etc2
FORMAT_ETC2_R11S, //signed, NOT srgb.
FORMAT_ETC2_RG11,
FORMAT_ETC2_RG11S,
FORMAT_ETC2_RGB8,
FORMAT_ETC2_RGBA8,
FORMAT_ETC2_RGB8A1,
FORMAT_ETC2_RA_AS_RG, //used to make basis universal happy
FORMAT_DXT5_RA_AS_RG, //used to make basis universal happy
FORMAT_MAX,
};
char GST2_Format_Name[4] @ 0x0;
u32 Version @ 0x4;
u32 Width @ 0x8;
u32 Height @ 0xC;
FormatBitsBitfield Data_Format @ 0x10;
u32 Mipmaps_Amount_Unused @ 0x14;
u32 Mipmaps_Limit_Unused @ 0x18;
u32 Reserved_1 @ 0x18;
u32 Reserved_2 @ 0x1C;
u32 Reserved_3 @ 0x20;
DataFormat Image_Format @ 0x24;
u16 Width2 @ 0x28;
u16 Height2 @ 0x2A;
u32 Mipmap_Amount @ 0x2C;
ImageFormat Image_Format2 @ 0x30;
if( Image_Format != DataFormat::DATA_FORMAT_IMAGE){
u32 Size;
char ImagePayload_PNG_WEBP_BASIS_UNIVERSAL[Size];
}else{
//DataFormat::DATA_FORMAT_IMAGE
char ImagePayload[1000];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment