Class: CompressedTextureResource

PIXI.CompressedTextureResource

Resource for compressed texture formats, as follows: S3TC/DXTn (& their sRGB formats), ATC, ASTC, ETC 1/2, PVRTC.

Compressed textures improve performance when rendering is texture-bound. The texture data stays compressed in graphics memory, increasing memory locality and speeding up texture fetches. These formats can also be used to store more detail in the same amount of memory.

For most developers, container file formats are a better abstraction instead of directly handling raw texture data. PixiJS provides native support for the following texture file formats (via PIXI.Loader):

  • .dds - the DirectDraw Surface file format stores DXTn (DXT-1,3,5) data. See PIXI.DDSLoader
  • .ktx - the Khronos Texture Container file format supports storing all the supported WebGL compression formats. See PIXI.KTXLoader.
  • .basis - the BASIS supercompressed file format stores texture data in an internal format that is transcoded to the compression format supported on the device at runtime. It also supports transcoding into a uncompressed format as a fallback; you must install the @pixi/basis-loader, @pixi/basis-transcoder packages separately to use these files. See PIXI.BasisLoader.

The loaders for the aforementioned formats use CompressedTextureResource internally. It is strongly suggested that they be used instead.

Working directly with CompressedTextureResource

Since CompressedTextureResource inherits BlobResource, you can provide it a URL pointing to a file containing the raw texture data (with no file headers!):

// The resource backing the texture data for your textures.
// NOTE: You can also provide a ArrayBufferView instead of a URL. This is used when loading data from a container file
//   format such as KTX, DDS, or BASIS.
const compressedResource = new PIXI.CompressedTextureResource("bunny.dxt5", {
  format: PIXI.INTERNAL_FORMATS.COMPRESSED_RGBA_S3TC_DXT5_EXT,
  width: 256,
  height: 256
});

// You can create a base-texture to the cache, so that future `Texture`s can be created using the `Texture.from` API.
const baseTexture = new PIXI.BaseTexture(compressedResource, { pmaMode: PIXI.ALPHA_MODES.NPM });

// Create a Texture to add to the TextureCache
const texture = new PIXI.Texture(baseTexture);

// Add baseTexture & texture to the global texture cache
PIXI.BaseTexture.addToCache(baseTexture, "bunny.dxt5");
PIXI.Texture.addToCache(texture, "bunny.dxt5");

new PIXI.CompressedTextureResource (source, options) overrides

Name Type Attributes Default Description
source string | Uint8Array | Uint32Array

the buffer/URL holding the compressed texture data

options ICompressedTextureResourceOptions
options.format PIXI.INTERNAL_FORMATS

the compression format

options.width number

the image width in pixels.

options.height number

the image height in pixels.

options.level number <optional>
1

the mipmap levels stored in the compressed texture, including level 0.

options.levelBuffers number <optional>

the buffers for each mipmap level. CompressedTextureResource can allows you to pass null for source, for cases where each level is stored in non-contiguous memory.

Extends

Members

format

The compression format

levels

The number of mipmap levels stored in the resource buffer.

Default Value:
  • 1

Methods

upload (renderer, _texture, _glTexture) boolean

Name Type Description
renderer PIXI.Renderer
_texture PIXI.BaseTexture
_glTexture PIXI.GLTexture
Returns:
Type Description
boolean

onBlobLoaded () void protected

Inherited Properties

From class PIXI.resources.BlobResource

buffer ViewableBuffer inherited

The viewable buffer on the data

origin string inherited

The URL of the texture file

Inherited Methods

From class PIXI.resources.BlobResource

load () Promise inherited

Loads the blob

Returns:
Type Description
Promise