Introduction
KTX is a container for textures, made by the Khronos Group, the body behind OpenGL and Vulkan. A texture is stored in the form the graphics card uses, often already block-compressed, so it can be loaded without decoding. One file can hold all the mipmap levels, the six faces of a cube map and arrays of layers.
There are two versions. KTX 1 (.ktx) describes the data with OpenGL
constants. KTX 2 (.ktx2) uses Vulkan formats, a data format descriptor
and optional supercompression with Basis Universal or Zstandard. KTX 2 with Basis
Universal is the texture format of the glTF extension
KHR_texture_basisu.
Structure
Both versions start with a 12-byte identifier. KTX 1 uses
AB 4B 54 58 20 31 31 BB 0D 0A 1A 0A («KTX 11»), and KTX 2 uses
AB 4B 54 58 20 32 30 BB 0D 0A 1A 0A («KTX 20»).
In KTX 1 the identifier is followed by an endianness word and twelve more 32-bit fields: the OpenGL type and formats, the width, height and depth, the number of array elements, faces and mipmap levels, and the length of the key and value data. The key and value pairs come next, then each mipmap level with its size in front.
In KTX 2 the identifier is followed by the Vulkan format, the size of the data type, the width, height and depth, the layer, face and level counts and the supercompression scheme. An index gives the offset and length of the data format descriptor, the key and value data and any supercompression data, and then one entry per mipmap level. Levels are stored from the smallest to the largest.
0Identifier «KTX 20»12 bytes12Header format, size, counts, supercompression scheme36 bytes48Index offsets and lengths of the descriptor, key and value data, supercompression data32 bytes80Level index offset and lengths for each mipmap level24 bytes each…Descriptor, key and value data, supercompression datavaries…Mipmap levels smallest firstvaries
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)
- Basis Universal – encoder and transcoder for supercompressed KTX 2 (C++)
Reference
- KTX – the Khronos page with both specifications