GPUCanvasContext: getCurrentTexture() method

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

Syntax

js

getCurrentTexture()

Parameters

None.

Return value

A GPUTexture object instance.

Examples

js

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

context.configure({
  device: 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

Specification
WebGPU
# dom-gpucanvascontext-getcurrenttexture

Browser compatibility

BCD tables only load in the browser

See also