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 |
瀏覽器相容性
載入中…