API Reference · Model and texture loading

Ktx2Loader

Namespace: Ava3D

public static class Ktx2Loader

Reads a KTX2 file into a Texture.

Why KTX2 and not a format of our own. It is what glTF's own compressed-texture extension uses, it carries the format, the dimensions and the whole mip chain in a header nobody has to be told about, and there is a standard tool — toktx — that produces it from a PNG. A caller with a texture pipeline already has one of these; a caller without one can make one in a line.

What it reads. The parts a real asset uses: a two-dimensional, single-layer, single-face image with its mip levels, in one of the block formats TextureFormat names, uncompressed or zstd-free. Array textures, cube maps, 3D textures and supercompressed payloads are refused by name rather than misread — a loader that half-understands a container produces a picture that is wrong in a way nobody can trace back to the file.

Basis Universal is deliberately not here. A .ktx2 holding a supercompressed Basis payload needs a transcoder — a hundred kilobytes of library and a licence — and it decides its own target format at load time, which is a different design from "the caller ships what its device takes". If that is wanted it is its own piece of work, and this loader says so rather than failing obscurely.

Methods

MemberDescription
static Texture Load(byte[] bytes, string name = null)

Reads a KTX2 file.

bytes

The whole file.

name

Optional name, for diagnostics. Defaults to the format and size.

See also