GPUCanvasContext: getCurrentTexture() method
Khả dụng hạn chế
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
Phương thức getCurrentTexture() của giao diện GPUCanvasContext trả về GPUTexture tiếp theo sẽ được ghép vào tài liệu bởi ngữ cảnh canvas.
Cú pháp
js
getCurrentTexture()
Tham số
Không có.
Giá trị trả về
Phiên bản đối tượng GPUTexture.
Ngoại lệ
InvalidStateErrorDOMException-
Ném ra nếu
getCurrentTexture()được gọi trên ngữ cảnh canvas trước khi nó được cấu hình (tức là trước khiGPUCanvasContext.configure()được gọi).
Ví dụ
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);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebGPU> # dom-gpucanvascontext-getcurrenttexture> |