Skip to main content

Overview

From-v3.0

The @loaders.gl/textures module contains loaders for compressed textures. More specifically it contains loaders and writers for compressed texture container formats, including KTX, DDS and PVR. It also supports supercompressed Basis textures and decoded Radiance HDR images.

Note that a texture is more complex than an image. A texture typically has many subimages. A texture can represent a single logical image but can also be a texture cube, a texture array etc representing many logical images. In addition, each "image" typically has many mipmap levels.

In addition, in compressed textures each mipmap image is compressed opaquely into a format that can only be understood by certain GPUs.

Basis encoded textures are super compressed. A more recent addition, they can be efficiently transcoded on the client into actual compressed texture formats appropriate for each device and are therefore quite convenient to use.

Installation

npm install @loaders.gl/textures
npm install @loaders.gl/core

Formats

The @loaders.gl/textures module handles the following formats:

FormatDescription
Compressed TexturesOverview of GPU texture container and compression formats
KTX / KTX2Khronos texture container formats for mipmapped textures
DDSMicrosoft DirectDraw Surface texture container
PVRPowerVR texture container format
Basis UniversalSupercompressed texture format for runtime transcoding
CrunchLossy compressed texture distribution format for GPU textures
Radiance HDRHigh-dynamic-range RGBE textures stored in .hdr files From-v4.4

API

LoaderDescription
BasisLoaderBasis Universal textures as TextureLevel[][]
CompressedTextureLoaderKTX, DDS and PVR mip chains as TextureLevel[]
RadianceHDRLoaderRadiance .hdr textures as Texture From-v4.4
CrunchWorkerLoaderCrunch mip chains as TextureLevel[]
TextureLoaderManifest-driven single image or mip chain From-v4.4
TextureArrayLoaderManifest-driven texture arrays From-v4.4
TextureCubeLoaderManifest-driven cubemaps From-v4.4
TextureCubeArrayLoaderManifest-driven cube arrays From-v4.4

Return Types

The compressed texture loaders in this module return TextureLevel objects from @loaders.gl/schema.

Texture Category

A TextureLevel describes one mip level of one texture image.

FieldTypeDescription
compressedbooleanWhether the mip level data is GPU-compressed.
shape'texture-level'Shape tag for normalized texture-level payloads. From-v4.4
formatnumberWebGL internal format enum for the decoded level. From-v4.4
textureFormatTextureFormatWebGPU / luma.gl style format string for the data. From-v4.4
dataTypedArrayThe payload for this mip level. Compressed texture loaders return Uint8Array; RadianceHDRLoader returns Float32Array.
widthnumberWidth of this mip level.
heightnumberHeight of this mip level.
levelSizenumberSize in bytes for this mip level, when available.
hasAlphabooleanWhether the transcoded texture contains alpha.

BasisLoader returns TextureLevel[][], preserving all images in a .basis or .ktx2 asset.

CompressedTextureLoader returns TextureLevel[].

RadianceHDRLoader returns a Texture with shape: 'texture', type: '2d', one decoded rgba32float level in data, and optional application-facing metadata.

CrunchWorkerLoader returns TextureLevel[].

See BasisLoader and CompressedTextureLoader for loader-specific options and return shapes.

Composite Image Loaders

The textures module also includes manifest-driven loaders for composite image textures:

These loaders resolve relative member URLs against the manifest URL, or against options.core.baseUrl when parsing an in-memory manifest. Member assets are parsed with ImageLoader by default, and additional loaders passed to top-level load() are also available for manifest members. They return schema Texture objects rather than raw image trees.

Attributions

  • The CompressedTextureLoader was forked from PicoGL, Copyright (c) 2017 Tarek Sherif, The MIT License (MIT)
  • The CompressedTextureWriter is a wrapper around @TimvanScherpenzeel's texture-compressor utility (MIT licensed).