Skip to content

Core

VideoTexture ​

Defined in: packages/wtc-gl/src/core/VideoTexture.ts:31

A texture that follows a video. It uploads a new frame only when the video presents one (using requestVideoFrameCallback), so there's no need to set needsUpdate every frame. Where requestVideoFrameCallback isn't supported, it uploads every time it's used while the video is playing.

Until the video has a frame, the texture is a single transparent pixel. Mipmaps are off by default, as regenerating them for every frame is costly.

Extends ​

Constructors ​

Constructor ​

ts
new VideoTexture(gl, options): VideoTexture;

Defined in: packages/wtc-gl/src/core/VideoTexture.ts:45

Create a video texture.

Parameters ​

ParameterTypeDescription
glWTCGLRenderingContextThe WTCGL rendering context.
optionsVideoTextureOptionsTexture options, plus the video to follow; see VideoTextureOptions.

Returns ​

VideoTexture

Overrides ​

Texture.constructor

Properties ​

PropertyTypeDefault valueDescriptionInherited from
anisotropynumberundefinedThe anistropic filtering level for the texture. Default 0Texture.anisotropy
compareFuncnumber | nullundefinedFor a depth texture, compare against a reference value when sampled instead of returning the depth: gl.LEQUAL, gl.LESS and so on. A shader reads it with a sampler2DShadow, and LINEAR filtering then gives 2×2 percentage-closer filtering for free. Null for no comparison. Default nullTexture.compareFunc
dataTextureData | nullnullTyped array data for a data texture. Needs width and height.Texture.data
flipYbooleanundefinedWhether to flip the Y direction of the textureTexture.flipY
formatnumberundefinedThe texture format. Default gl.RGBATexture.format
generateMipmapsbooleanundefinedWhether to generate mipmaps for this texture. WebGL2 can mipmap textures of any size. Default trueTexture.generateMipmaps
glWTCGLRenderingContextundefinedThe WTCGL rendering context.Texture.gl
heightnumber0The height of the texture. 0 until known.Texture.height
idnumberundefinedA unique ID for the texture object, allows us to determine whether a texture has already been bound or not.Texture.id
image?| TextureImage | TextureImage[]undefinedThe image representing the texture. Can be an HTML image, video or canvas, an ImageBitmap or an OffscreenCanvas.Texture.image
internalFormatnumberundefinedthe texture internal format. Default gl.RGBATexture.internalFormat
levelnumberundefinedA GLint specifying the level of detail. Level 0 is the base image level and level n is the nth mipmap reduction level. Only relevant if we have mipmaps. Default 0Texture.level
magFilternumberundefinedThe filter to use when rendering larger.Texture.magFilter
minFilternumberundefinedThe filter to use when rendering smaller.Texture.minFilter
needsUpdatebooleanundefinedWhether the texture needs an update in memoryTexture.needsUpdate
premultiplyAlphabooleanundefinedWhether the texture is interpolated as having premultiplied alpha. Default falseTexture.premultiplyAlpha
stateWTCGLTextureStateundefinedTexture state, contains the basic texture properties.Texture.state
storeobjectundefinedThe image storeTexture.store
store.image?| TextureImage | TextureImage[]undefinedThe image last uploaded, compared with image to see if it changed.-
targetnumberundefinedThe binding point for the texture. Default gl.TEXTURE_2DTexture.target
textureWebGLTextureundefinedThe WebGL texture object containing the data and state for WebGLTexture.texture
typenumberundefinedThe texture type. Typically one of gl.UNSIGNED_BYTE, gl.FLOAT, gl.HALF_FLOAT Default gl.UNSIGNED_BYTETexture.type
unpackAlignment1 | 2 | 4 | 8undefinedThe unpack alignment for pixel stores.Texture.unpackAlignment
videoHTMLVideoElementundefinedThe video being followed.-
widthnumber0The width of the texture. 0 until known.Texture.width
wrapSnumberundefinedWrapping. Normally one of gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED REPEAT Default gl.CLAMP_TO_EDGETexture.wrapS
wrapTnumberundefinedWrapping. Normally one of gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED REPEAT Default gl.CLAMP_TO_EDGETexture.wrapT

Methods ​

bind() ​

ts
bind(): void;

Defined in: packages/wtc-gl/src/core/Texture.ts:370

Bind the texture. Skips over if it's determined that the texture is already bound.

Returns ​

void

Inherited from ​

Texture.bind


remove() ​

ts
remove(): void;

Defined in: packages/wtc-gl/src/core/VideoTexture.ts:80

Stop following the video and delete the texture.

Returns ​

void

Overrides ​

Texture.remove


restoreContext() ​

ts
restoreContext(): void;

Defined in: packages/wtc-gl/src/core/Texture.ts:357

Recreate the WebGL texture after the context has been restored and re-upload the image or data on next use. Called by the renderer.

Returns ​

void

Inherited from ​

Texture.restoreContext


update() ​

ts
update(textureUnit?): void;

Defined in: packages/wtc-gl/src/core/VideoTexture.ts:67

Upload the current frame if there's a new one, then bind the texture. Called when the uniform is bound.

Parameters ​

ParameterTypeDefault valueDescription
textureUnit?number0The texture unit to update against.

Returns ​

void

Overrides ​

Texture.update


fromBlob() ​

ts
static fromBlob(
   gl, 
   blob, 
   options?
): Promise<Texture>;

Defined in: packages/wtc-gl/src/core/Texture.ts:263

Decode an image blob into a texture, as fromURL does once it has fetched one.

Parameters ​

ParameterTypeDescription
glWTCGLRenderingContextThe WTCGL rendering context.
blobBlobThe encoded image, e.g. a PNG or JPEG.
options?Partial<TextureOptions>Texture options.

Returns ​

Promise<Texture>

Inherited from ​

Texture.fromBlob


fromURL() ​

ts
static fromURL(
   gl, 
   url, 
   options?
): Promise<Texture>;

Defined in: packages/wtc-gl/src/core/Texture.ts:242

Load an image from a URL into a texture. It's fetched, then decoded off the main thread with createImageBitmap, which also does the flipping and premultiplying (flipY and premultiplyAlpha here). Rejects if the request fails.

ts
const texture = await Texture.fromURL(gl, '/photo.jpg', { wrapS: gl.REPEAT })

Parameters ​

ParameterTypeDescription
glWTCGLRenderingContextThe WTCGL rendering context.
urlstringWhere the image is.
options?TextureLoadOptionsTexture options, plus a signal to abort the request.

Returns ​

Promise<Texture>

Inherited from ​

Texture.fromURL