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.
Distributed asset
Runtime choice
metadata · levels · capabilities
Renderer receives
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
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:
| Format | Description |
|---|---|
Compressed Textures | Overview of GPU texture container and compression formats |
KTX / KTX2 | Khronos texture container formats for mipmapped textures |
DDS | Microsoft DirectDraw Surface texture container |
PVR | PowerVR texture container format |
Basis Universal | Supercompressed texture format for runtime transcoding |
Crunch | Lossy compressed texture distribution format for GPU textures |
Radiance HDR | High-dynamic-range RGBE textures stored in .hdr files |
API
| Loader | Description |
|---|---|
BasisLoader | Basis Universal textures as TextureLevel[][] |
CompressedTextureLoader | KTX, DDS and PVR mip chains as TextureLevel[] |
RadianceHDRLoader | Radiance .hdr textures as Texture |
CrunchLoader | Crunch mip chains as TextureLevel[] |
TextureLoader | Manifest-driven single image or mip chain |
TextureArrayLoader | Manifest-driven texture arrays |
TextureCubeLoader | Manifest-driven cubemaps |
TextureCubeArrayLoader | Manifest-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.
| Field | Type | Description |
|---|---|---|
compressed | boolean | Whether the mip level data is GPU-compressed. |
shape | 'texture-level' | Shape tag for normalized texture-level payloads. |
format | number | WebGL internal format enum for the decoded level. |
textureFormat | TextureFormat | WebGPU / luma.gl style format string for the data. |
data | TypedArray | The payload for this mip level. Compressed texture loaders return Uint8Array; RadianceHDRLoader returns Float32Array. |
width | number | Width of this mip level. |
height | number | Height of this mip level. |
levelSize | number | Size in bytes for this mip level, when available. |
hasAlpha | boolean | Whether 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:
TextureLoaderfor a single image or mip chainTextureArrayLoaderfor texture arrays, including mipmapped layersTextureCubeLoaderfor cubemaps, including mipmapped facesTextureCubeArrayLoaderfor cube arrays
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
CompressedTextureLoaderwas forked from PicoGL, Copyright (c) 2017 Tarek Sherif, The MIT License (MIT) - The
CompressedTextureWriteris a wrapper around @TimvanScherpenzeel'stexture-compressorutility (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.