Skip to main content

Module texture

Module texture 

Source
Expand description

Texture payload format helpers shared between the runtime and the build crate. The file -> pixels decoders (PNG / JPEG / DDS / TGA / KTX2 / glb-embedded images) live in concinnity_cook::compile::texture; this module keeps only what a running engine needs with no image-decode dependencies: turning a compiled payload back into a TextureImage (deserialise) and the box-filter downscale_rgba the build pipeline uses to cap oversized source maps.

One tagged format serves every 2D texture (little-endian): u32 magic = b“TEX2“ u32 format_id (0 RGBA8, 1 BC1, 2 BC3, 3 BC5, 4 BC7) u32 mip_count (>= 1) per mip, level 0 first (largest): u32 width u32 height u32 byte_len byte_len bytes of level data

RGBA8 sources (PNG / JPEG / procedural generators) carry a single mip; the backend upload generates the minification chain (crate::render::mipmap). Block-compressed sources (KTX2 / DDS) carry the container’s full mip chain and upload it verbatim, since no runtime BCn encoder exists.

Structs§

TextureImage
A decoded 2D texture: its GPU format plus one or more mip levels, level 0 first. The backend uploads mips directly for compressed formats and generates the minification chain from mips[0] for RGBA8.
TextureMip
One mip level: dimensions plus its tightly packed level bytes (RGBA8 pixels or block-compressed data, per the owning image’s format).

Enums§

TextureFormat
GPU pixel format of a compiled texture payload. RGBA8 is the uncompressed path (runtime mip generation); the rest are block-compressed formats uploaded with their container mip chains.

Constants§

MAX_MIP_LEVELS
A u32 dimension bottoms out at 1x1 after at most this many halvings, so a file or payload declaring more levels than this is malformed rather than large. Decoders bound a declared mip count against it before reserving.

Functions§

deserialise
Deserialise a tagged payload back into a TextureImage.
downscale_rgba
Box-filter an RGBA image down so its longest edge is at most max_size. A max_size of 0 (or an image already within budget) returns the input unchanged. Used to keep oversized source maps (4K+ DDS) from exploding the compiled blob, which stores raw RGBA8.
serialise
Serialise a TextureImage into the tagged payload the runtime reads. The build crate writes payloads through this so the reader and writer share one format definition.