Class KTX2TextureLoader

A texture loader for KTX2 format files that handles transcoding of compressed texture data.

KTX2 is a container format for GPU textures that supports various compression formats including Basis Universal (ETC1S and UASTC). This loader can transcode KTX2 textures to device-specific formats based on available GPU extensions.

The loader supports:

  • ETC1S and UASTC4x4 compressed formats
  • Multiple target formats (ASTC, BC, ETC, PVRTC, etc.)
  • ZSTD supercompression
  • Mipmap generation
  • Both WebGL and WebGPU rendering contexts
const loader = KTX2TextureLoader.getInstance();
const textureData = await loader.transcode(ktx2ArrayBuffer);

Constructors

Methods

Constructors

Methods

  • Transcodes a KTX2 texture from the provided byte array.

    This method parses the KTX2 container, validates its format constraints, and transcodes the texture data to a format suitable for the current GPU.

    Parameters

    • uint8Array: Uint8Array

      The KTX2 texture data as a Uint8Array

    Returns Promise<{
        compressionTextureType: CompressionTextureTypeEnum;
        height: number;
        mipmapData: TextureData[];
        needGammaCorrection: boolean;
        width: number;
    }>

    A promise that resolves to the transcoded texture data

    Error if the texture format is not supported (3D textures, array textures, or cube textures)

    const ktx2Data = new Uint8Array(buffer);
    const textureData = await loader.transcode(ktx2Data);