drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:)
Encodes a draw command that renders an instance of a geometric primitive with indexed vertices.
Declaration
func drawIndexedPrimitives(type primitiveType: MTLPrimitiveType, indexCount: Int, indexType: MTLIndexType, indexBuffer: any MTLBuffer, indexBufferOffset: Int)Parameters
- primitiveType:
An Mtlprimitivetype instance that represents how the command interprets vertex argument data.
See the Setvertexbuffer(_:offset:index:) method and its siblings for more information about setting an entry in the vertex shader argument table for buffers.
- indexCount:
An integer that represents the number of vertices the command reads from
indexBuffer. - indexType:
An Mtlindextype instance that represents the index’s format, including Uint16 and Uint32.
- indexBuffer:
An Mtlbuffer instance that contains the
indexCountvertex indices of theindexTypeformat. - indexBufferOffset:
An integer that represents the location that’s a multiple of the index size from the start of
indexBufferwhere the vertex indices begin.
Discussion
You can complete a primitive and start a new one by passing a sentinel index value that’s the largest unsigned integer possible for indexType. For example, the largest unsigned integer for MTLIndexType.uint16 and MTLIndexType.uint32 is 0xFFFF and 0xFFFFFFFF, respectively. The command finishes the current primitive and begins drawing a new one each time the command reads a sentinel index value.
The method records the encoder’s current rendering state and resources the command needs as it runs. You can safely change the encoder’s render pipeline state to encode other commands after calling this method. Subsequent changes to the state don’t affect the commands already in the encoder’s MTLCommandBuffer.
See Also
Drawing with indexed vertices
drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:)drawIndexedPrimitives(type:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:baseVertex:baseInstance:)drawIndexedPrimitives(type:indexType:indexBuffer:indexBufferOffset:indirectBuffer:indirectBufferOffset:)