Vixen
02b45cc4
csharp
public static class Ktx2

Reads and writes the KTX2 container.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

KTX2 is what a Vixen build ships textures in, and the runtime reads it with this rather than with an image codec: the bytes in the file are the bytes the GPU wants, so loading a texture is a header parse and an upload. That is also why Vixen.Core.Imaging has no PNG decoder — decoding a PNG is import-time work, and ADR-015 keeps ImageSharp out of every runtime assembly for licence reasons as well.

Level data is stored smallest first. The level index is ordered largest first, but the bytes it points at run the other way, so a streaming loader can read the small mips off the front of the file and show something before the rest has arrived. It is the one part of the format that reads like a mistake and is not, so it is the part most worth a test.

What is implemented: the identifier, the header, the level index, the data format descriptor, key/value data, and level data for uncompressed and block-compressed formats. What is not: supercompression — neither Basis Universal nor Zstd — and therefore supercompression global data, which is written as absent and refused on read. A build that wants smaller bundles compresses the chunk the texture lives in, which [08](../../../docs/plan/08-asset-pipeline-and-addressables.md) already does per bundle.

What has not been done: validated against an independent KTX2 implementation. The layout here is written from the specification and checked byte-for-byte against a hand-computed file in the tests, which catches a misread of the spec but not a misunderstanding of it. Running the Khronos ktx validate tool over what this writes is an owed step, and until it has been run, "valid KTX2" is a claim about intent.

Fields and properties (3)

  • public static ReadOnlySpan<byte> Identifier

    The twelve bytes every KTX2 file starts with.

  • public const int HeaderLength

    How long the header is, up to and including the supercompression global data pointers.

  • public const int LevelIndexEntryLength

    How long one level index entry is.

Methods (2)

  • public static byte[] Write(TextureData texture)

    Writes a texture.

  • public static TextureData Read(ReadOnlySpan<byte> file)

    Reads a texture.

Used by (9)

  • AssetTextureSourceVixen.Engine.Renderer
  • AssetTextureSourceTestsVixen.Engine.Renderer.Tests
  • BlockCompressorTestsVixen.Core.Imaging.Tests
  • Ktx2TestsVixen.Core.Imaging.Tests
  • WorldRendererTestsVixen.Engine.Renderer.Tests
  • CubeLutImporterVixen.Editor.Assets
  • Ktx2DecoderVixen.Editor.Assets
  • TextureImporterVixen.Editor.Assets
  • TextureImporterTestsVixen.Editor.Assets.Tests