GPUCanvasContext
注意:此功能在 Web Workers 中可用。
GPUCanvasContext 介面是 WebGPU API 的一部分,它代表了 <canvas> 元素的 WebGPU 渲染上下文。該上下文透過呼叫 HTMLCanvasElement.getContext() 並指定 contextType 為 "webgpu" 來獲取。
例項屬性
canvas只讀-
返回一個指向建立此上下文的 canvas 的引用。
例項方法
configure()-
配置上下文以使用給定的
GPUDevice進行渲染,並將 canvas 清除為透明黑色。 getConfiguration()-
返回當前為上下文設定的配置。
getCurrentTexture()-
返回由 canvas 上下文合成到文件中的下一個
GPUTexture。 unconfigure()-
移除所有先前設定的上下文配置,並銷燬 canvas 上下文配置期間生成的任何紋理。
示例
js
const canvas = document.querySelector("#gpuCanvas");
const context = canvas.getContext("webgpu");
context.configure({
device,
format: navigator.gpu.getPreferredCanvasFormat(),
alphaMode: "premultiplied",
});
規範
| 規範 |
|---|
| WebGPU # gpucanvascontext |
瀏覽器相容性
載入中…