web api instance method
GPURenderBundleEncoder: setIndexBuffer() method
Secure contextAvailable in 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().
Syntax
setIndexBuffer(buffer, indexFormat, offset, size)
Parameters
buffer- : A
GPUBufferrepresenting the buffer containing the index data to use for subsequent drawing commands.
- : A
indexFormat- : An enumerated value that defines the format of the index data contained in
buffer. Possible values are:"uint16""uint32"
- : An enumerated value that defines the format of the index data contained in
offsetOptional- : A number representing the offset, in bytes, into
bufferwhere the index data begins. If omitted,offsetdefaults to 0.
- : A number representing the offset, in bytes, into
sizeOptional- : A number representing the size, in bytes, of the index data contained in
buffer. If omitted,sizedefaults to thebuffer’ssize-offset.
- : A number representing the size, in bytes, of the index data contained in
Note on indexFormat
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".
Return value
None (undefined).
Validation
The following criteria must be met when calling setIndexBuffer(), otherwise a GPUValidationError is generated and the GPURenderBundleEncoder becomes invalid:
buffer’susagecontains theGPUBufferUsage.INDEXflag.offset+sizeis less than or equal to thebuffer’ssize.offsetis a multiple ofindexFormat’s byte size (2 for"uint16", 4 for"uint32").
Examples
// …
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
Browser compatibility
See also
- The WebGPU API