Ktx2Decoder

interface Ktx2Decoder

Pluggable codec for KTX2 / Basis-Universal texture compression (KHR_texture_basisu glTF extension).

The engine has no built-in KTX2 decoder — Basis Universal's transcoder is ~30K LOC of C++ (ETC1S / UASTC block decoding + endpoint dequantisation + selector palettes) and a real decoder ships as a native library per platform. Apps that need to render KTX2-compressed 3D Tiles (Google Photorealistic 3D Tiles, many Cesium Ion photogrammetry assets) wire in a platform-specific implementation by setting earth.worldwind.layer.ogc3d.GltfDecoderRegistry.ktx2Decoder once at startup.

Implementations are expected to be:

  • Thread-safe: GltfReader.parse is called from background coroutines, potentially in parallel for different tiles.

  • Stateless between calls: each decode runs against fresh input and produces fresh output.

  • Fast: decode runs on every textured tile fetch; native implementations should reuse internal scratch buffers.

Typical app-side wiring:

GltfDecoderRegistry.ktx2Decoder = MyJvmKtx2Decoder()  // JNI-backed

When no decoder is registered, GltfReader logs once + emits no image bytes for the affected texture; the layer renders the primitive untextured (vertex colour or material base-colour factor only).

Functions

Link copied to clipboard
abstract fun decode(ktx2Bytes: ByteArray): Ktx2Image

Decode a single KTX2 / Basis-Universal compressed texture into an RGBA8888 pixel buffer plus its dimensions.