Class: Texture2D

Texture2D(webglContext, optionsopt)

`Texture2D` is a thin wrapper around a `WebGLTexture`. It supports a placeholder pixel (1x1), and can asynchronously upload the image from URL.

Constructor

new Texture2D(webglContext, optionsopt)

Parameters:
Name Type Attributes Description
webglContext WebGL2RenderingContext WebGL2 rendering context, used to create and manage the GPU resources.
options Texture2DOptions <optional>
Optional texture creation options.
Source:
Throws:
When provided arguments do not match expected types or supported enums.
Type
TypeError

Classes

Texture2D

Members

height

Returns the height of the uploaded image (or placeholder height until loaded).
Source:

isDisposed

Indicates whether this instance has been disposed.
Source:

isLoaded

Indicates whether the image has been uploaded.
Source:

texture

Returns the underlying `WebGLTexture` object.
Source:

width

Returns the width of the uploaded image (or the placeholder width until loaded).
Source:

Methods

bind(textureUnitIndex)

Binds this texture to a texture unit.
Parameters:
Name Type Description
textureUnitIndex number Index of the texture unit.
Source:

dispose()

Releases the WebGL texture.
Source:

(async) loadFromUrl(url, optionsopt) → {Promise.<void>}

Loads an image from the given URL and uploads it into this WebGL texture.
Parameters:
Name Type Attributes Description
url string Image URL (relative or absolute).
options Texture2DLoadOptions <optional>
Optional load options.
Source:
Throws:
When arguments are invalid.
Type
TypeError
Returns:
- Promise, that resolves after successful GPU upload, or rejects on `load/decode/upload` error.
Type
Promise.<void>

setSamplerParams(optionsopt)

Updates sampler parameters for this texture.
Parameters:
Name Type Attributes Description
options Texture2DOptions <optional>
Sampler options to update.
Source:
Throws:
When provided arguments do not match expected types or supported enums.
Type
TypeError