PIXI.CompressedTextureResource

class CompressedTextureResource extends PIXI.BlobResource

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");

Constructor


new PIXI.CompressedTextureResource(source: string | Uint8Array | Uint32Array, options: ICompressedTextureResourceOptions) → {}
Parameters:
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.

Summary


Properties from CompressedTextureResource

PIXI.INTERNAL_FORMATS
format

The compression format

number
levels = 1

Methods from CompressedTextureResource

Properties inherited from BlobResource

ViewableBuffer
buffer
string
origin

Properties inherited from Resource

boolean
destroyed = false
number
height
boolean
internal
string
src

The url of the resource

boolean
valid
number
width
number
protected _height

Internal height of the resource.

number
protected _width

Internal width of the resource.

Methods inherited from BlobResource

Promise<PIXI.Resource>
load()

Loads the blob

Methods inherited from Resource

void
bind(baseTexture: PIXI.BaseTexture)
void
destroy()
void
dispose()

Clean up anything, this happens when destroying is ready.

void
resize(width: number, height: number)
boolean
style(_renderer: PIXI.Renderer, _baseTexture: PIXI.BaseTexture, _glTexture: PIXI.GLTexture)
void
unbind(baseTexture: PIXI.BaseTexture)
void
update()

Has been updated trigger event.

Public Properties


format CompressedTextureResource.ts:80
format: PIXI.INTERNAL_FORMATS

The compression format

levels CompressedTextureResource.ts:82
levels: number = 1

The number of mipmap levels stored in the resource buffer.

Public Methods


upload CompressedTextureResource.ts:129
upload(renderer: PIXI.Renderer, _texture: PIXI.BaseTexture, _glTexture: PIXI.GLTexture) → {boolean}
Parameters:
Name Type Description
renderer PIXI.Renderer

A reference to the current renderer

_texture PIXI.BaseTexture

the texture

_glTexture PIXI.GLTexture

texture instance for this webgl context

Returns:
Type Description
boolean

Protected Methods


onBlobLoaded CompressedTextureResource.ts:160
protected onBlobLoaded() → {void}
Returns:
Type Description
void

Powered by webdoc!