W3cubDocs

/Web APIs

GPURenderPassEncoder: drawIndexed() method

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.

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.

instanceCount Optional

A number defining the number of instances to draw. If omitted, instanceCount defaults to 1.

firstIndex Optional

A number defining the offset into the index buffer, in indices, to begin drawing from. If omitted, firstIndex defaults to 0.

baseVertex Optional

A number added to each index value before indexing into the vertex buffers. If omitted, baseVertex defaults to 0.

firstInstance Optional

A number defining the first instance to draw. If omitted, firstInstance defaults to 0.

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
drawIndexed
113Currently supported on ChromeOS, macOS, and Windows only.
113Currently supported on ChromeOS, macOS, and Windows only.
141Currently supported on Windows only, in all contexts except for service workers.
99Currently supported on ChromeOS, macOS, and Windows only.
26 121 No 81 26 25.0 121 26

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/GPURenderPassEncoder/drawIndexed