Skip to main content

Texture container loader

Preserve the mip chain and the GPU format.

CompressedTextureLoader reads KTX, KTX2, DDS, and PVR containers without reducing them to ordinary pixels. The result keeps each level's dimensions, compression state, and runtime format metadata.

Container in, levels out

Keep the data in the form a renderer expects.

The loader returns normalized levels rather than a browser image object. That makes container metadata available to WebGL, WebGPU, and application-specific texture upload code.

Reads

KTX, KTX2, DDS, and PVR containers

Preserves

Dimensions, mip levels, compression, and format tags

Returns

TextureLevel[] with typed payloads

Pairs with

BasisLoader for KTX2 Basis transcoding

From-v3.0

Loader for compressed texture containers in the KTX, DDS and PVR formats.

Detailed guide

Compressed texture details

The sections below cover container support, usage, normalized texture levels, and format-specific metadata.

CompressedTextureLoader
File FormatPVR, DDS, KTX
File Extension.dds, .pvr, .ktx, .ktx2
File TypeBinary
Data FormatTextureLevel[]
Supported APIsload, parse

Usage​

import {CompressedTextureLoader} from '@loaders.gl/images/texture';
import {load} from '@loaders.gl/core';

const mipLevels = await load(url, CompressedTextureLoader);
for (const level of mipLevels) {
console.log(level.shape, level.format, level.textureFormat);
}

Data Format​

Returns TextureLevel[], one entry per mip level.

Each level includes:

  • shape: 'texture-level' From-v4.4
  • compressed
  • format From-v4.4
  • textureFormat From-v4.4
  • width
  • height
  • data
  • levelSize when available

Options​

OptionTypeDefaultDescription
compressed-texture.useBasisBooleanfalseUse BasisLoader to decode KTX2 texture

Basis loader​

Use BasisLoader for KTX2 assets that need Basis transcoding.

Module Overrides​

When compressed-texture.useBasis is true, CompressedTextureLoader uses the Basis transcoder runtime through options.modules.

  • modules.basis: supply a preloaded transcoder module containing KTX2File.
  • 'basis_transcoder.js': override the transcoder JavaScript wrapper URL.
  • 'basis_transcoder.wasm': override the transcoder WebAssembly URL.