GPURenderPassEncoder: phương thức setVertexBuffer()
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 setVertexBuffer() của giao diện GPURenderPassEncoder đặt hoặc bỏ đặt GPUBuffer hiện tại cho vị trí đã cho sẽ cung cấp dữ liệu đỉnh cho các lệnh vẽ tiếp theo.
Cú pháp
setVertexBuffer(slot, buffer, offset, size)
Tham số
slot-
Một số tham chiếu vị trí bộ đệm đỉnh để đặt bộ đệm đỉnh cho.
buffer-
Một
GPUBufferbiểu diễn bộ đệm chứa dữ liệu đỉnh để sử dụng cho các lệnh vẽ tiếp theo, hoặcnull, trong trường hợp đó bất kỳ bộ đệm đã đặt trước đó trong vị trí đã cho sẽ bị bỏ đặt. offsetOptional-
Một số biểu diễn độ lệch, tính bằng byte, vào
buffernơi dữ liệu đỉnh bắt đầu. Nếu bỏ qua,offsetmặc định là 0. sizeOptional-
Một số biểu diễn kích thước, tính bằng byte, của dữ liệu đỉnh chứa trong
buffer. Nếu bỏ qua,sizemặc định làGPUBuffer.sizecủabuffertrừoffset.
Giá trị trả về
Không có (Undefined).
Xác thực
Các tiêu chí sau phải được đáp ứng khi gọi setVertexBuffer(), nếu không GPUValidationError sẽ được tạo ra và GPURenderPassEncoder sẽ không hợp lệ:
GPUBuffer.usagecủabufferchứa cờGPUBufferUsage.VERTEX.slotnhỏ hơn giới hạnmaxVertexBufferslimit củaGPUDevice.offset+sizenhỏ hơn hoặc bằngGPUBuffer.sizecủabuffer.offsetlà bội số của 4.
Ví dụ
>Đặt bộ đệm đỉnh
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(). setVertexBuffer() được sử dụng phù hợp để đặt nguồn dữ liệu đỉnh.
// …
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()]);
// …
Bỏ đặt bộ đệm đỉnh
// Set vertex buffer in slot 0
passEncoder.setVertexBuffer(0, vertexBuffer);
// Later, unset vertex buffer in slot 0
passEncoder.setVertexBuffer(0, null);
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| WebGPU> # dom-gpurendercommandsmixin-setvertexbuffer> |