files/en-us/web/api/gpurenderbundleencoder/setindexbuffer/index.md
{{APIRef("WebGPU API")}}{{SecureContext_Header}}{{AvailableInWorkers}}
The setIndexBuffer() method of the
{{domxref("GPURenderBundleEncoder")}} interface sets the current {{domxref("GPUBuffer")}} that will provide index data for subsequent drawing commands.
[!NOTE] This method is functionally identical to its equivalent on {{domxref("GPURenderPassEncoder")}} — {{domxref("GPURenderPassEncoder.setIndexBuffer", "setIndexBuffer()")}}.
setIndexBuffer(buffer, indexFormat, offset, size)
buffer
indexFormat
buffer. Possible values are:
"uint16""uint32"offset {{optional_inline}}
buffer where the index data begins. If omitted, offset defaults to 0.size {{optional_inline}}
buffer. If omitted, size defaults to the buffer's {{domxref("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 ({{jsxref("Undefined")}}).
The following criteria must be met when calling setIndexBuffer(), otherwise a {{domxref("GPUValidationError")}} is generated and the {{domxref("GPURenderBundleEncoder")}} becomes invalid:
buffer's {{domxref("GPUBuffer.usage")}} contains the GPUBufferUsage.INDEX flag.offset + size is less than or equal to the buffer's {{domxref("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();
// …
{{Specifications}}
{{Compat}}