Skip to main content

CompressedTextureLoader

From-v3.0

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

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

Usage​

import {CompressedTextureLoader} from '@loaders.gl/textures';
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 encoder runtime through options.modules.

  • modules.basisEncoder: supply a preloaded Basis encoder module that resolves to {BasisFile, KTX2File, BasisEncoder}.
  • 'basis_encoder.js': override the URL used for the Basis encoder JavaScript wrapper.
  • 'basis_encoder.wasm': override the URL used for the Basis encoder WebAssembly binary.