Introduction
KTX 1 is the first version of the Khronos Group’s texture container, made for OpenGL and OpenGL ES. It stores a texture in exactly the form that is passed to OpenGL’s texture upload calls, so a loader can read the header, then hand each mipmap level straight to the driver. One file can hold a 1D, 2D or 3D texture, a cube map or an array, with all its mipmap levels.
Each texture is described with OpenGL’s own numbers: the type, format and internal
format constants such as GL_UNSIGNED_BYTE, GL_RGBA or a
compressed format such as ETC2. KTX 2 replaced it for Vulkan, but KTX 1 files are still
common in OpenGL ES and Android projects.
Structure
A 12-byte identifier is followed by an endianness word and twelve 32-bit fields. Then come the key and value pairs, and then each mipmap level, largest first, each preceded by its size. The file layout page has every field.
0Identifier «KTX 11»12 bytes12Endianness0x04030201as written4 bytes16Header OpenGL type and formats, size, counts48 bytes64Key and value data pairs, each padded to 4 bytesvaries…Mipmap levels each with a 4-byte size first, largest firstvaries
In the viewer
Drop a .ktx file on the page and the viewer shows every byte of it in the
tree: the header field by field, the key and value pairs (the known keys with their
meaning), and each mip level with its size, each of its images (every array element and
cube face) and the padding. A file made on a big-endian machine is read too: every 32-bit
field is swapped, and so is each value of the pixel data.
Every image of every level can be opened as a picture. Uncompressed textures of
any glFormat and glType that name components (red, red and green, RGB,
RGBA, BGR, BGRA, luminance, luminance and alpha, alpha, in bytes, shorts, ints, floats and half
floats, normalised or integer), the packed types 5-6-5, 4-4-4-4, 5-5-5-1, 2-10-10-10,
10F-11F-11F and 5-9-9-9, and the compressed formats BC1 to BC7 (S3TC, RGTC, BPTC), ETC1, ETC2, EAC and
ASTC in the 2D block sizes are decoded, with the same decoders as
KTX 2. The pictures equal those of the KTX 2 files that Khronos’ ktx convert makes from the same
files.
Not described
KTX 1 is documented by Khronos. These pages follow the 1.0 specification; the parts below are not covered yet.
Known, not yet covered
- Reference: the full OpenGL enumerations for
glInternalFormat,glFormatandglType; the file layout page lists only the common values, and the rest belong to the OpenGL registry. The viewer names about a hundred and thirty of them. - Viewer: pictures of PVRTC, ATC, ASTC in three dimensions, and of
the depth and stencil pixel types (
GL_UNSIGNED_INT_24_8andGL_FLOAT_32_UNSIGNED_INT_24_8_REV) are not made: the layout is shown, with the bytes. AGL_COMPRESSED_RGBA_ASTCformat is read as low dynamic range (the same constant is used for the high dynamic range variant, which a file does not say), so an HDR block shows as magenta.
Variants
- Khronos Texture 1 – OpenGL textures described by OpenGL constants, in either byte order
- Khronos Texture 2 – Vulkan textures with a data format descriptor and optional supercompression
Links
Software
- KTX-Software tools – Khronos command-line tools that create, check and convert KTX files (Windows, macOS, Linux)
- PVRTexTool – Imagination Technologies’ texture compression and viewing tool (Windows, macOS, Linux)
- Compressonator – AMD’s texture compression tool (Windows, Linux)
Developers
- libktx – Khronos library that reads and writes KTX 1 and KTX 2 (C)
Reference
- KTX File Format Specification – the Khronos specification of KTX 1