Format:KTX and KTX2 (Khronos texture)
| Magic | AB 4B 54 58 20 31 31 BB 0D 0A 1A 0A (KTX 1); AB 4B 54 58 20 32 30 BB 0D 0A 1A 0A (KTX 2) |
|---|---|
| Extensions | .ktx, .ktx2 |
| On this wiki | Facts · Code · Notes · Topics |
Khronos texture containers for GPU-ready textures: KTX 1 (.ktx, 64-byte header, identifier AB 4B 54 58 20 31 31 BB 0D 0A 1A 0A, OpenGL formats) and KTX 2 (.ktx2, 80-byte header, identifier AB 4B 54 58 20 32 30 BB 0D 0A 1A 0A, Vulkan vkFormat, optional supercompression and a level index).
Identification
Both versions start with a 12-byte identifier that embeds the version, a CR LF / SUB / LF tail to catch text-mode corruption, and 0xAB as a non-ASCII first byte:
- KTX 1:
AB 4B 54 58 20 31 31 BB 0D 0A 1A 0A("KTX 11" in guillemets), followed by a 32-bitendiannessfield that is 0x04030201 when the file matches the reader (0x01020304 is the reversed value, a byte-swapped file). - KTX 2:
AB 4B 54 58 20 32 30 BB 0D 0A 1A 0A("KTX 20" in guillemets). Unverified: KTX 2 is always little-endian (it has no endianness field).
KTX 1 header (64 bytes)
identifier[12], endianness, glType, glTypeSize, glFormat, glInternalformat, glBaseInternalformat, pixelWidth, pixelHeight, pixelDepth, numberOfArrayElements, numberOfFaces, numberOfMipLevels, bytesOfKeyValueData. Unverified: block-compressed files have glType and glFormat 0 and a compressed OpenGL enum in glInternalformat.
KTX 2 header (80 bytes) and level index
identifier[12], vkFormat, typeSize, pixelWidth, pixelHeight, pixelDepth, layerCount, faceCount, levelCount, supercompressionScheme, then three index entries: dataFormatDescriptor (u32 offset, u32 length), keyValueData (u32, u32) and supercompressionGlobalData (u64 offset, u64 length). KTX-Software declares a level index entry as three uint64: byteOffset, byteLength, uncompressedByteLength. Unverified: the level index starts right after the 80-byte header.
Supercompression scheme values: 0 none, 1 BasisLZ, 2 Zstandard, 3 ZLIB, 4 UASTC HDR 6x6 Intermediate; 0x10000-0x1ffff is the vendor range and 0x20000 and up is reserved. KTX-Software's loader requires, for the KHR_texture_basisu case, a data format descriptor model of ETC1S or UASTC, allows UASTC only with scheme none or Zstandard, and requires the ETC1S model for BasisLZ.
Key/value metadata uses keys such as KTXorientation, KTXswizzle, KTXwriter and KTXwriterScParams.
Related
Format:Basis Universal (.basis) data is carried inside KTX 2 files (BasisLZ/ETC1S or UASTC). Block layouts: Technique:Block-compressed texture formats.
Code & repositories
- https://github.com/KhronosGroup/KTX-Software @
2f7a0b07024dd4b35f2bc2f4c3a25fe159a91c28· license: Apache-2.0 (read from LICENSE.md; GitHub's detector did not classify it)
Reference libktx and tools for KTX 1 and KTX 2 (Apache-2.0 for its own files)
Tested on: source read, not run: source read, no build · checked 2026-10-19; last activity 2026-10-19; Note: the latest release ships binaries; the wiki links only the source, never the binaries