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 |
浏览器兼容性
加载中…