Firefox Tomorrow

web api instance method

GPUCanvasContext: getCurrentTexture() method

View on MDN ↗

Secure contextAvailable in workers

The getCurrentTexture() method of the GPUCanvasContext interface returns the next GPUTexture to be composited to the document by the canvas context.

Syntax

getCurrentTexture()

Parameters

None.

Return value

A GPUTexture object instance.

Exceptions

  • InvalidStateError DOMException
    • : Thrown if getCurrentTexture() is called on the canvas context before it is configured (i.e., before configure() has been called).

Examples

const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");

context.configure({
  device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  alphaMode: "premultiplied",
});

// …
// Later on
const commandEncoder = device.createCommandEncoder();

const renderPassDescriptor = {
  colorAttachments: [
    {
      clearValue: [0, 0, 0, 1], // Opaque black
      loadOp: "clear",
      storeOp: "store",
      view: context.getCurrentTexture().createView(),
    },
  ],
};

const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also