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 overrides

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

onBlobLoaded () void protected

Inherited Properties

From class PIXI.BlobResource

buffer ViewableBuffer inherited

The viewable buffer on the data

origin string inherited

The URL of the texture file

From class PIXI.Resource

destroyed boolean readonly inherited

If resource has been destroyed

Default Value:
  • false

height number readonly inherited

The height of the resource.

valid boolean readonly inherited

Has been validated

width number readonly inherited

The width of the resource.

_height number protected inherited

Internal height of the resource

_width number protected inherited

Internal width of the resource

internal boolean protected inherited

true if resource is created by BaseTexture useful for doing cleanup with BaseTexture destroy and not cleaning up resources that were created externally.

Inherited Methods

From class PIXI.BlobResource

load () Promise inherited

Loads the blob

Returns:
Type Description
Promise

From class PIXI.Resource

bind (baseTexture) void inherited

Bind to a parent BaseTexture

Name Type Description
baseTexture PIXI.BaseTexture

Parent texture

destroy () void inherited

Call when destroying resource, unbind any BaseTexture object before calling this method, as reference counts are maintained internally.

resize (width, height) void inherited

Trigger a resize event

Name Type Description
width number

X dimension

height number

Y dimension

style (renderer, baseTexture, glTexture) boolean inherited

Set the style, optional to override

Name Type Description
renderer PIXI.Renderer

yeah, renderer!

baseTexture PIXI.BaseTexture

the texture

glTexture PIXI.GLTexture

texture instance for this webgl context

Returns:
Type Description
boolean true is success

unbind (baseTexture) void inherited

Unbind to a parent BaseTexture

Name Type Description
baseTexture PIXI.BaseTexture

Parent texture

update () void inherited

Has been updated trigger event

dispose () void protected inherited

Clean up anything, this happens when destroying is ready.