GPUCanvasContext: getCurrentTexture() 方法
注意:此功能在 Web Workers 中可用。
GPUCanvasContext 接口的 getCurrentTexture() 方法返回下一个将由 canvas 上下文合成到文档中的 GPUTexture。
语法
js
getCurrentTexture()
参数
无。
返回值
一个 GPUTexture 对象实例。
异常
InvalidStateErrorDOMException-
如果在配置 canvas 上下文之前(即在调用
GPUCanvasContext.configure()之前)调用getCurrentTexture(),则会抛出此错误。
示例
js
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);
规范
| 规范 |
|---|
| WebGPU # dom-gpucanvascontext-getcurrenttexture |
浏览器兼容性
加载中…