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.

// 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 Summary)

Constructors

Properties

externalTexture: GPUExternalTexture

The GPUExternalTexture used if any.

The MediaTexture sources to use if any.

Size of the texture source, usually our sources first element size (since for cube maps, all sources must have the same size).

Options used to create this MediaTexture.

videoFrameCallbackIds: Map<number, number>

Array of requestVideoFrameCallback returned ids if used.

offset: Vec2

Vec2 offset to apply to the Texture if useTransform parameter has been set to true.

scale: Vec2

Vec2 scale to apply to the Texture if useTransform parameter has been set to true.

transformOrigin: Vec2

Vec2 transformation origin to use when applying the transformations to the Texture if useTransform parameter has been set to true. A value of (0.5, 0.5) corresponds to the center of the texture. Default is (0, 0), the upper left.

modelMatrix: Mat3

Mat3 transformation matrix to apply to the Texture if useTransform parameter has been set to true.

transformBinding?: BufferBinding

BufferBinding to send the transformation matrix to the shaders if useTransform parameter has been set to true.

type: string

The type of the Texture.

uuid: string

The universal unique id of this Texture.

texture: GPUTexture

The GPUTexture used.

Array of bindings that will actually only hold one texture binding.

Accessors

Methods

  • Upload a source to the GPU and use it for our texture.

    Parameters

    • parameters: {
          source: GPUCopyExternalImageSource;
          width?: number;
          height?: number;
          depth?: number;
          origin?: GPUOrigin3D;
          colorSpace?: PredefinedColorSpace;
      }

      parameters used to upload the source.

      • source: GPUCopyExternalImageSource

        source to use for our texture.

      • Optionalwidth?: number

        source width.

      • Optionalheight?: number

        source height.

      • Optionaldepth?: number

        source depth.

      • Optionalorigin?: GPUOrigin3D
      • OptionalcolorSpace?: PredefinedColorSpace

    Returns void

  • Use data as the texture source and upload it to the GPU.

    Parameters

    • parameters: {
          width?: number;
          height?: number;
          depth?: number;
          origin?: GPUOrigin3D;
          data?: Float32Array;
      }

      parameters used to upload the source.

    Returns void