Skip to main content

Class: TextureManager

Creates, updates, and reads textures.

Constructors​

Constructor​

new TextureManager(): TextureManager;

Returns​

TextureManager

Methods​

Create2D()​

static Create2D(
width,
height,
format?,
linear?): Promise<number>;

Creates a 2D texture.

Parameters​

ParameterTypeDescription
widthnumberThe texture width, in pixels.
heightnumberThe texture height, in pixels.
format?TextureFormatThe texture format. Defaults to TextureFormat.RGBA32.
linear?booleanWhether the texture should use linear color format. Defaults to false (sRGB).

Returns​

Promise<number>

A promise that resolves to the created Texture.


CreateRenderTexture()​

static CreateRenderTexture(
width?,
height?,
depth?,
dimension?,
format?): Promise<number>;

Creates a render texture.

Parameters​

ParameterTypeDescription
width?numberThe texture width, in pixels. Defaults to 512.
height?numberThe texture height, in pixels. Defaults to 512.
depth?numberThe depth buffer size. Defaults to 16.
dimension?TextureDimensionThe texture dimension. Defaults to TextureDimension.Tex2D.
format?RenderTextureFormatThe texture format. Defaults to RenderTextureFormat.Default.

Returns​

Promise<number>

A promise that resolves to the created Texture.


Destroy()​

static Destroy(handle): Promise<boolean>;

Destroys a texture.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to destroy.

Returns​

Promise<boolean>

A promise that resolves to true if the texture was destroyed, or false otherwise.


GetTextureSize()​

static GetTextureSize(handle): Promise<vec2>;

Gets the size of a texture.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to inspect.

Returns​

Promise<vec2>

A promise that resolves to the texture size as [width, height].


LoadRGBAImage()​

static LoadRGBAImage(
handle,
rgbaData,
width,
height): Promise<void>;

Sets raw RGBA image data for a texture.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to update.
rgbaDataUint8ArrayRGBA byte data in R, G, B, A order.
widthnumberThe image width, in pixels.
heightnumberThe image height, in pixels.

Returns​

Promise<void>

A promise that resolves when the image data has been changed.


LoadImage()​

static LoadImage(handle, image): Promise<void>;

Loads encoded image data into a texture.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to update.
imageUint8ArrayPNG, JPG, or EXR image data.

Returns​

Promise<void>

A promise that resolves when the image data has been changed.


ReadbackRGBAImage()​

static ReadbackRGBAImage(handle): Promise<ImageReadbackResult>;

Gets image data from a texture in RGBA format.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to read.

Returns​

Promise<ImageReadbackResult>

A promise that resolves to the image data.


ReadbackJPGImage()​

static ReadbackJPGImage(handle, quality?): Promise<ImageReadbackResult>;

Gets image data from a texture in JPEG format.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to read.
quality?numberThe JPEG quality, from 0 to 100. Defaults to 75.

Returns​

Promise<ImageReadbackResult>

A promise that resolves to the image data.


ReadbackPNGImage()​

static ReadbackPNGImage(handle): Promise<ImageReadbackResult>;

Gets image data from a texture in PNG format.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to read.

Returns​

Promise<ImageReadbackResult>

A promise that resolves to the image data.


SetFilterMode()​

static SetFilterMode(handle, mode): Promise<void>;

Sets the filter mode of a texture.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to update.
modeTextureFilterModeThe filter mode to apply.

Returns​

Promise<void>

A promise that resolves when the filter mode has been changed.


SetWrapModeU()​

static SetWrapModeU(handle, wrapMode): Promise<void>;

Sets the wrap mode of a texture on the U axis.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to update.
wrapModeTextureWrapModeThe wrap mode to apply.

Returns​

Promise<void>

A promise that resolves when the wrap mode has been changed.


SetWrapModeV()​

static SetWrapModeV(handle, wrapMode): Promise<void>;

Sets the wrap mode of a texture on the V axis.

Parameters​

ParameterTypeDescription
handlenumberThe Texture to update.
wrapModeTextureWrapModeThe wrap mode to apply.

Returns​

Promise<void>

A promise that resolves when the wrap mode has been changed.