Skip to main content

GPUCanvasContext

The GPUCanvasContext interface of the WebGPU API represents the WebGPU rendering context of a <canvas> element, returned via an HTMLCanvasElement.getContext() call with a contextType of "webgpu". Available only in secure contexts.

MDN Reference

Methods

configure()

configure(configuration): void;

The configure() method of the GPUCanvasContext interface configures the context to use for rendering with a given GPUDevice. When called the canvas will initially be cleared to transparent black.

MDN Reference

Parameters

ParameterType
configurationGPUCanvasConfiguration

Returns

void


getConfiguration()

getConfiguration(): GPUCanvasConfiguration | null;

The getConfiguration() method of the GPUCanvasContext interface returns the current configuration set for the context.

MDN Reference

Returns

GPUCanvasConfiguration | null


getCurrentTexture()

getCurrentTexture(): GPUTexture;

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

MDN Reference

Returns

GPUTexture


unconfigure()

unconfigure(): void;

The unconfigure() method of the GPUCanvasContext interface removes any previously-set context configuration, and destroys any textures returned via getCurrentTexture() while the canvas context was configured.

MDN Reference

Returns

void

Properties

canvas

readonly canvas:
| HTMLCanvasElement
| OffscreenCanvas;

The canvas read-only property of the GPUCanvasContext interface returns a reference to the canvas that the context was created from.

MDN Reference