web api instance method
GPURenderPassEncoder: drawIndexed() method
Secure contextAvailable in workers
The drawIndexed() method of the
GPURenderPassEncoder interface draws indexed primitives based on the vertex and index buffers provided by setVertexBuffer() and setIndexBuffer().
Syntax
drawIndexed(indexCount)
drawIndexed(indexCount, instanceCount)
drawIndexed(indexCount, instanceCount, firstIndex)
drawIndexed(indexCount, instanceCount, firstIndex, baseVertex)
drawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance)
Parameters
indexCount- : A number defining the number of indices to draw.
instanceCountOptional- : A number defining the number of instances to draw. If omitted,
instanceCountdefaults to 1.
- : A number defining the number of instances to draw. If omitted,
firstIndexOptional- : A number defining the offset into the index buffer, in indices, to begin drawing from. If omitted,
firstIndexdefaults to 0.
- : A number defining the offset into the index buffer, in indices, to begin drawing from. If omitted,
baseVertexOptional- : A number added to each index value before indexing into the vertex buffers. If omitted,
baseVertexdefaults to 0.
- : A number added to each index value before indexing into the vertex buffers. If omitted,
firstInstanceOptional- : A number defining the first instance to draw. If omitted,
firstInstancedefaults to 0.
- : A number defining the first instance to draw. If omitted,
Return value
None (undefined).
Examples
In the WebGPU Samples Shadow Mapping example, drawIndexed() is used in two separate render passes in each animation frame, one to populate the shadow buffer and one to draw the primary view of the scene. Study the example code listing for the full context.
// …
const commandEncoder = device.createCommandEncoder();
{
const shadowPass = commandEncoder.beginRenderPass(shadowPassDescriptor);
shadowPass.setPipeline(shadowPipeline);
shadowPass.setBindGroup(0, sceneBindGroupForShadow);
shadowPass.setBindGroup(1, modelBindGroup);
shadowPass.setVertexBuffer(0, vertexBuffer);
shadowPass.setIndexBuffer(indexBuffer, "uint16");
shadowPass.drawIndexed(indexCount);
shadowPass.end();
}
{
const renderPass = commandEncoder.beginRenderPass(renderPassDescriptor);
renderPass.setPipeline(pipeline);
renderPass.setBindGroup(0, sceneBindGroupForRender);
renderPass.setBindGroup(1, modelBindGroup);
renderPass.setVertexBuffer(0, vertexBuffer);
renderPass.setIndexBuffer(indexBuffer, "uint16");
renderPass.drawIndexed(indexCount);
renderPass.end();
}
// …
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.
See also
- The WebGPU API