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 setIndexBuffer() method of the GPURenderBundleEncoder interface sets the current GPUBuffer that will provide index data for subsequent drawing commands.
Note: This method is functionally identical to its equivalent on GPURenderPassEncoder — setIndexBuffer().
setIndexBuffer(buffer, indexFormat, offset, size)
bufferA GPUBuffer representing the buffer containing the index data to use for subsequent drawing commands.
indexFormatAn enumerated value that defines the format of the index data contained in buffer. Possible values are:
"uint16""uint32"offset OptionalA number representing the offset, in bytes, into buffer where the index data begins. If omitted, offset defaults to 0.
size OptionalA number representing the size, in bytes, of the index data contained in buffer. If omitted, size defaults to the buffer's GPUBuffer.size - offset.
indexFormat determines both the data type of index values in a buffer and, when used with a pipeline that specifies a strip primitive topology ("line-strip" or "triangle-strip"), also determines the primitive restart value. The primitive restart value is an index value indicating that a new primitive should be started rather than continuing to construct the strip with the prior indexed vertices. The value is 0xFFFF for "uint16", or 0xFFFFFFFF for "uint32".
None (Undefined).
The following criteria must be met when calling setIndexBuffer(), otherwise a GPUValidationError is generated and the GPURenderBundleEncoder becomes invalid:
buffer's GPUBuffer.usage contains the GPUBufferUsage.INDEX flag.offset + size is less than or equal to the buffer's GPUBuffer.size.offset is a multiple of indexFormat's byte size (2 for "uint16", 4 for "uint32").// … const bundleEncoder = device.createRenderBundleEncoder(descriptor); bundleEncoder.setPipeline(pipeline); bundleEncoder.setBindGroup(0, sceneBindGroupForRender); bundleEncoder.setBindGroup(1, modelBindGroup); bundleEncoder.setVertexBuffer(0, vertexBuffer); bundleEncoder.setIndexBuffer(indexBuffer, "uint16"); bundleEncoder.drawIndexed(indexCount); const renderBundle = bundleEncoder.finish(); // …
| Specification |
|---|
| WebGPU> # dom-gpurendercommandsmixin-setindexbuffer> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
setIndexBuffer |
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 |
© 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/GPURenderBundleEncoder/setIndexBuffer