GPURenderPassEncoder: phương thức draw()
Limited availability
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 draw() của giao diện GPURenderPassEncoder vẽ các nguyên thủy dựa trên các bộ đệm đỉnh được cung cấp bởi setVertexBuffer().
Cú pháp
draw(vertexCount)
draw(vertexCount, instanceCount)
draw(vertexCount, instanceCount, firstVertex)
draw(vertexCount, instanceCount, firstVertex, firstInstance)
Tham số
vertexCount-
Một số xác định số lượng đỉnh cần vẽ.
instanceCountOptional-
Một số xác định số lượng thực thể cần vẽ. Nếu bỏ qua,
instanceCountmặc định là 1. firstVertexOptional-
Một số xác định độ lệch vào các bộ đệm đỉnh, tính bằng đỉnh, để bắt đầu vẽ từ đó. Nếu bỏ qua,
firstVertexmặc định là 0. firstInstanceOptional-
Một số xác định thực thể đầu tiên cần vẽ. Nếu bỏ qua,
firstInstancemặc định là 0.
Giá trị trả về
Không có (Undefined).
Ví dụ
Trong demo kết xuất cơ bản của chúng tôi, một số lệnh được ghi lại thông qua GPUCommandEncoder. Hầu hết các lệnh này xuất phát từ GPURenderPassEncoder được tạo thông qua GPUCommandEncoder.beginRenderPass(). draw() được dùng để chỉ định rằng ba đỉnh sẽ được vẽ để tạo tam giác của chúng tôi.
// …
const renderPipeline = device.createRenderPipeline(pipelineDescriptor);
// Create GPUCommandEncoder to issue commands to the GPU
// Note: render pass descriptor, command encoder, etc. are destroyed after use, fresh one needed for each frame.
const commandEncoder = device.createCommandEncoder();
// Create GPURenderPassDescriptor to tell WebGPU which texture to draw into, then initiate render pass
const renderPassDescriptor = {
colorAttachments: [
{
clearValue: clearColor,
loadOp: "clear",
storeOp: "store",
view: context.getCurrentTexture().createView(),
},
],
};
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
// Draw the triangle
passEncoder.setPipeline(renderPipeline);
passEncoder.setVertexBuffer(0, vertexBuffer);
passEncoder.draw(3);
// End the render pass
passEncoder.end();
// End frame by passing array of command buffers to command queue for execution
device.queue.submit([commandEncoder.finish()]);
// …
Thông số kỹ thuật
| Specification |
|---|
| WebGPU> # dom-gpurendercommandsmixin-draw> |