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) → {}
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. |
Summary
Properties from CompressedTextureResource
PIXI.INTERNAL_FORMATS |
The compression format |
number |
|
Methods from CompressedTextureResource
boolean |
|
void |
|
Properties inherited from Resource
boolean |
|
number |
|
boolean |
|
string |
The url of the resource |
boolean |
|
number |
|
number |
Internal height of the resource. |
number |
Internal width of the resource. |
Methods inherited from BlobResource
Promise<PIXI.Resource> |
Loads the blob |
Methods inherited from Resource
void |
|
void |
|
void |
Clean up anything, this happens when destroying is ready. |
void |
|
boolean |
|
void |
|
void |
Has been updated trigger event. |
Public Properties
levels: number = 1
The number of mipmap levels stored in the resource buffer.
Public Methods
upload(renderer: PIXI.Renderer, _texture: PIXI.BaseTexture, _glTexture: PIXI.GLTexture) → {boolean}
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 |
Type | Description |
---|---|
boolean |
Protected Methods
protected onBlobLoaded() → {void}
Type | Description |
---|---|
void |