Skip to main content

Images package · texture APIs

@loaders.gl/images/texture

Ship one texture asset and choose the GPU format at runtime. Handle containers, mip chains, arrays, cube maps, and Basis Universal transcoding on the client.

Portable texture delivery

Package once. Choose the GPU target at runtime.

Containers preserve dimensions and mip levels; portable payloads delay the final format choice until the application knows what the current device supports.

Runtime choice

mipsdevicetranscode

metadata · levels · capabilities

Renderer receives

BC / S3TCdesktop GPU target
ETC2 / ASTCmobile GPU target
Fallback pixelswhen compression is unavailable

The application keeps one asset pipeline while the renderer receives the representation its WebGL or WebGPU device can use efficiently.

Container, payload, device

Keep texture delivery separate from texture use.

A source file can carry mip levels and a portable compressed payload. The application can inspect that metadata, select a target, and hand the resulting levels to its rendering layer.

Containers

KTX, KTX2, DDS, PVR, Basis, and Crunch

Layouts

Mips, arrays, cube maps, and 3D texture images

Transcode

Basis payloads to device-compatible compressed formats

Return

TextureLevel data or normalized texture objects

From-v3.0

The @loaders.gl/images 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.

See Texture Loaders for the shared category conventions.

Detailed guide

Images · Texture details

The sections below cover formats, loaders, writers, normalized return shapes, and runtime selection.

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/core @loaders.gl/images

Imports and parser access​

Import metadata loaders such as BasisLoader, CompressedTextureLoader, and TextureLoader from @loaders.gl/images. Async core APIs preload their parsers. For direct parsing, import BasisLoaderWithParser from @loaders.gl/images/basis or CompressedTextureLoaderWithParser from @loaders.gl/images/texture.

Writers use direct subpaths: KTX2BasisWriter comes from @loaders.gl/images/basis, and CompressedTextureWriter comes from @loaders.gl/images/texture. Manifest validators use @loaders.gl/images/texture; the exported JSON Schema is @loaders.gl/images/texture-manifest.schema.json.

Texture worker bundles and Basis/Crunch libraries now ship in the images package. Default loading uses the new package identity. Custom worker/library URLs must use @loaders.gl/images instead of the removed textures package. Compressed texture parsing/transcoding does not require Sharp; only Node image decoding/encoding does.

Formats​

The @loaders.gl/images 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

API​

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

Return Types​

The compressed texture loaders in this module return TextureLevel objects from @loaders.gl/core/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.
formatnumberWebGL internal format enum for the decoded level.
textureFormatTextureFormatWebGPU / luma.gl style format string for the data.
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.

CrunchLoader 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. 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). That utility is not a dependency of @loaders.gl/images; applications that use the writer must install it separately.

Sources and credits​

See the package source and license inventory and the project-wide Attributions and Credits.