Skip to main content

Compressed texture writer

Keep the compression step at the build or Node.js boundary.

CompressedTextureWriter is an experimental Node.js-only bridge to an externally installed native compressor. It is useful when an application needs to produce a GPU texture container, but it is not a browser-side encoder.

The compression boundary

Prepare image input. Invoke the local toolchain. Write a GPU container.

The writer delegates actual compression to `texture-compressor`. Keep that dependency explicit and run this path in build tooling or a controlled Node.js process.

Input

Encoded image URL or compatible image input

Toolchain

Application-installed texture-compressor package

Encode

Native compressor produces GPU blocks

Output

Compressed texture container at the destination URL

From-v3.0Node.js-only

The experimental CompressedTextureWriter class can encode a binary encoded image into a compressed texture.

Detailed guide

Writer prerequisites and limitations

The reference below covers installation, Node.js constraints, output assumptions, native tool invocation, and current experimental limitations.

caution

This writer works by loading the texture-compressor package, which runs its bundled native compressor. That package is not installed by @loaders.gl/images. Applications that use this writer must install it themselves:

npm install --save-dev texture-compressor

The package is resolved as an optional peer dependency and called directly. The writer does not invoke npx or access the npm registry. If the package cannot be resolved locally, encodeURLtoURL() rejects.

CompressedTextureWriter
File Extension
File TypeBinary
Data FormatEncoded image URL
File FormatS3TC / DXT1 in a KTX container
Encoder TypeAsynchronous
Worker Thread❌ No; Node.js-only native tool invocation
Streaming❌ No

Usage​

import '@loaders.gl/core/polyfills'; // only if using under Node
import {encodeURLtoURL} from '@loaders.gl/core';
import {CompressedTextureWriter} from '@loaders.gl/images/texture';

export const IMAGE_URL = 'image.png';

const outputFilename = await encodeURLtoURL(IMAGE_URL, '/tmp/test.ktx', CompressedTextureWriter);

// app can now read the file from outputFilename

Data Format​

The experimental encoder accepts an input image URL and invokes the optional texture-compressor package to produce an S3TC/DXT1 texture. The current command-line tool writes a KTX container even though the public writer metadata uses the dds identifier. The output URL must therefore end in .ktx.

This path is intentionally URL-based and does not expose a browser-side encode() method. For a portable browser workflow, use KTX2BasisWriter or prepare compressed textures during an asset build.

Options​

OptionTypeDefaultDescription
texture.formatstring'auto'Format hint retained for the writer options contract; the current encoder emits S3TC/DXT1.
texture.compressionstring'auto'Compression hint retained for compatibility; the current encoder uses DXT1.
texture.qualitystring'auto'Quality hint retained for compatibility; the current encoder uses normal quality.
texture.mipmapbooleanfalseMipmap preference retained for compatibility with the external toolchain.
texture.flipYbooleanfalseVertical orientation preference retained for compatibility with the external toolchain.
texture.toolFlagsstring''Additional tool flags reserved for the external compressor.

Remarks​

  • Requires the texture-compressor package to be installed by the application, see the note above.
  • Output is currently hardcoded to the S3TC/DXT1 compression format, and the CLI only writes .ktx containers, so outputUrl must end in .ktx despite the writer being registered under the dds id.
  • For more information, see texture-compressor.