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
new VideoTexture(gl, options): VideoTexture;Defined in: packages/wtc-gl/src/core/VideoTexture.ts:45
Create a video texture.
Parameters
| Parameter | Type | Description |
|---|---|---|
gl | WTCGLRenderingContext | The WTCGL rendering context. |
options | VideoTextureOptions | Texture options, plus the video to follow; see VideoTextureOptions. |
Returns
VideoTexture
Overrides
Properties
| Property | Type | Default value | Description | Inherited from |
|---|---|---|---|---|
anisotropy | number | undefined | The anistropic filtering level for the texture. Default 0 | Texture.anisotropy |
compareFunc | number | null | undefined | For 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 null | Texture.compareFunc |
data | TextureData | null | null | Typed array data for a data texture. Needs width and height. | Texture.data |
flipY | boolean | undefined | Whether to flip the Y direction of the texture | Texture.flipY |
format | number | undefined | The texture format. Default gl.RGBA | Texture.format |
generateMipmaps | boolean | undefined | Whether to generate mipmaps for this texture. WebGL2 can mipmap textures of any size. Default true | Texture.generateMipmaps |
gl | WTCGLRenderingContext | undefined | The WTCGL rendering context. | Texture.gl |
height | number | 0 | The height of the texture. 0 until known. | Texture.height |
id | number | undefined | A unique ID for the texture object, allows us to determine whether a texture has already been bound or not. | Texture.id |
image? | | TextureImage | TextureImage[] | undefined | The image representing the texture. Can be an HTML image, video or canvas, an ImageBitmap or an OffscreenCanvas. | Texture.image |
internalFormat | number | undefined | the texture internal format. Default gl.RGBA | Texture.internalFormat |
level | number | undefined | A 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 0 | Texture.level |
magFilter | number | undefined | The filter to use when rendering larger. | Texture.magFilter |
minFilter | number | undefined | The filter to use when rendering smaller. | Texture.minFilter |
needsUpdate | boolean | undefined | Whether the texture needs an update in memory | Texture.needsUpdate |
premultiplyAlpha | boolean | undefined | Whether the texture is interpolated as having premultiplied alpha. Default false | Texture.premultiplyAlpha |
state | WTCGLTextureState | undefined | Texture state, contains the basic texture properties. | Texture.state |
store | object | undefined | The image store | Texture.store |
store.image? | | TextureImage | TextureImage[] | undefined | The image last uploaded, compared with image to see if it changed. | - |
target | number | undefined | The binding point for the texture. Default gl.TEXTURE_2D | Texture.target |
texture | WebGLTexture | undefined | The WebGL texture object containing the data and state for WebGL | Texture.texture |
type | number | undefined | The texture type. Typically one of gl.UNSIGNED_BYTE, gl.FLOAT, gl.HALF_FLOAT Default gl.UNSIGNED_BYTE | Texture.type |
unpackAlignment | 1 | 2 | 4 | 8 | undefined | The unpack alignment for pixel stores. | Texture.unpackAlignment |
video | HTMLVideoElement | undefined | The video being followed. | - |
width | number | 0 | The width of the texture. 0 until known. | Texture.width |
wrapS | number | undefined | Wrapping. Normally one of gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED REPEAT Default gl.CLAMP_TO_EDGE | Texture.wrapS |
wrapT | number | undefined | Wrapping. Normally one of gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED REPEAT Default gl.CLAMP_TO_EDGE | Texture.wrapT |
Methods
bind()
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
remove()
remove(): void;Defined in: packages/wtc-gl/src/core/VideoTexture.ts:80
Stop following the video and delete the texture.
Returns
void
Overrides
restoreContext()
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
update()
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
textureUnit? | number | 0 | The texture unit to update against. |
Returns
void
Overrides
fromBlob()
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
| Parameter | Type | Description |
|---|---|---|
gl | WTCGLRenderingContext | The WTCGL rendering context. |
blob | Blob | The encoded image, e.g. a PNG or JPEG. |
options? | Partial<TextureOptions> | Texture options. |
Returns
Promise<Texture>
Inherited from
fromURL()
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.
const texture = await Texture.fromURL(gl, '/photo.jpg', { wrapS: gl.REPEAT })Parameters
| Parameter | Type | Description |
|---|---|---|
gl | WTCGLRenderingContext | The WTCGL rendering context. |
url | string | Where the image is. |
options? | TextureLoadOptions | Texture options, plus a signal to abort the request. |
Returns
Promise<Texture>