Options
All
  • Public
  • Public/Protected
  • All
Menu

Class 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 {@link 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");
memberof

PIXI

Hierarchy

Index

Constructors

constructor

  • new CompressedTextureResource(source: string | Uint32Array | Uint8Array, options: ICompressedTextureResourceOptions): CompressedTextureResource
  • Parameters

    • source: string | Uint32Array | Uint8Array

      the buffer/URL holding the compressed texture data

    • options: ICompressedTextureResourceOptions

    Returns CompressedTextureResource

Properties

Private _extension

_extension: any

Protected _height

_height: number

Private _levelBuffers

_levelBuffers: any

Protected _width

_width: number

Protected buffer

data

data: Uint16Array | Uint32Array | Float32Array | Uint8Array

destroyed

destroyed: boolean

format

internal

internal: boolean

levels

levels: number

Protected loaded

loaded: boolean

Protected onError

onError: Runner

Protected onResize

onResize: Runner

Protected onUpdate

onUpdate: Runner

Protected origin

origin: string

Static Private _createLevelBuffers

_createLevelBuffers: any

Pre-creates buffer views for each mipmap level

param
param
param
param
param
param
param

Static Private _formatToExtension

_formatToExtension: any

Returns the key (to ContextSystem#extensions) for the WebGL extension supporting the compression format

param
returns

Accessors

height

  • get height(): number
  • The height of the resource.

    member

    {number}

    readonly

    Returns number

valid

  • get valid(): boolean
  • Has been validated

    readonly
    member

    {boolean}

    Returns boolean

width

  • get width(): number
  • The width of the resource.

    member

    {number}

    readonly

    Returns number

Methods

bind

destroy

  • destroy(): void
  • Call when destroying resource, unbind any BaseTexture object before calling this method, as reference counts are maintained internally.

    Returns void

dispose

  • dispose(): void
  • Destroy and don't use after this

    override

    Returns void

load

  • Loads the blob

    Returns Promise<Resource>

Protected onBlobLoaded

  • onBlobLoaded(): void
  • Returns void

resize

  • resize(width: number, height: number): void
  • Trigger a resize event

    Parameters

    • width: number

      X dimension

    • height: number

      Y dimension

    Returns void

style

unbind

update

  • update(): void
  • Has been updated trigger event

    Returns void

upload

Static test

  • test(source: unknown): source is Uint32Array | Float32Array | Uint8Array
  • Used to auto-detect the type of resource.

    static

    Parameters

    • source: unknown

      The source object

    Returns source is Uint32Array | Float32Array | Uint8Array

    true if

Generated using TypeDoc