Used to create GPUTexture or GPUExternalTexture, specially made to handle different kinds of DOM elements sources, like HTMLImageElement, HTMLVideoElement or HTMLCanvasElement.

Handles the various sources loading and uploading, GPU textures creation,texture model matrix binding and GPU texture binding.

Example

// set our main GPUCurtains instance
const gpuCurtains = new GPUCurtains({
container: '#canvas' // selector of our WebGPU canvas container
})

// set the GPU device
// note this is asynchronous
await gpuCurtains.setDevice()

// create a DOM texture
const imageTexture = new DOMTexture(gpuCurtains, {
label: 'My image texture',
name: 'imageTexture',
})

// load an image
await imageTexture.loadImage(document.querySelector('img'))

Hierarchy (view full)

Constructors

Properties

transforms: Object3DTransforms
children: Object3D[]

Children Object3D in the scene graph, used to compute their own world matrix

object3DIndex: number

Index (order of creation) of this Object3D. Used in the parent / children relation.

matricesNeedUpdate: boolean

Whether at least one of this Object3D matrix needs an update.

type: string

The type of the DOMTexture

uuid: string

The universal unique id of this DOMTexture

renderer: Renderer

Renderer used by this DOMTexture

texture: GPUTexture

The GPUTexture used if any

externalTexture: GPUExternalTexture

The GPUExternalTexture used if any

The DOMTexture source to use

The GPUTexture, matching the source size (with 1 for depth)

Options used to create this DOMTexture

textureMatrix: BufferBinding

A buffer binding that will hold the texture model matrix

The bindings used by this DOMTexture, i.e. its textureMatrix and its GPU texture binding

_parentMesh: DOMTextureParent

DOMTexture parentMesh if any

_sourceLoaded: boolean

Whether the source has been loaded

_sourceUploaded: boolean

Whether the source has been uploaded to the GPU, handled by the GPUDeviceManager texturesQueue array

shouldUpdate: boolean

Whether the texture should be uploaded to the GPU

videoFrameCallbackId: number

HTMLVideoElement.requestVideoFrameCallback | requestVideoFrameCallback returned id if used

#parentRatio: Vec3 = ...

Private vector used for {@link#modelMatrix} calculations, based on parentMesh size

#sourceRatio: Vec3 = ...

Private vector used for modelMatrix calculations, based on source size

#coverScale: Vec3 = ...

Private vector used for modelMatrix calculations, based on #parentRatio and #sourceRatio

#rotationMatrix: Mat4 = ...

Private rotation matrix based on texture quaternion

Accessors

Methods

  • Load an HTMLImageElement from a URL and create an ImageBitmap to use as a source

    Parameters

    • url: string

      URL of the image to load

    Returns Promise<ImageBitmap>

    • the newly created ImageBitmap

    Async

  • Load and create an ImageBitmap from a URL or HTMLImageElement, use it as a source and create the GPUTexture

    Parameters

    • source: string | HTMLImageElement

      the image URL or HTMLImageElement to load

    Returns Promise<void>

    • the newly created ImageBitmap

    Async

  • Callback to run when a HTMLVideoElement has loaded (when it has enough data to play). Set the HTMLVideoElement as a source and create the GPUTexture or GPUExternalTexture

    Parameters

    • video: HTMLVideoElement

      the newly loaded HTMLVideoElement

    Returns void

  • Load a video from a URL or HTMLVideoElement and register onVideoLoaded callback

    Parameters

    • source: string | HTMLVideoElement

      the video URL or HTMLVideoElement to load

    Returns void

  • Load a HTMLCanvasElement, use it as a source and create the GPUTexture

    Parameters

    • source: HTMLCanvasElement

      the HTMLCanvasElement to use

    Returns void