drawIndexedPrimitives(type:indexType:indexBuffer:indexBufferOffset:indirectBuffer:indirectBufferOffset:)
Encodes a draw command that renders multiple instances of a geometric primitive with indexed vertices and indirect arguments.
Declaration
func drawIndexedPrimitives(type primitiveType: MTLPrimitiveType, indexType: MTLIndexType, indexBuffer: any MTLBuffer, indexBufferOffset: Int, indirectBuffer: any MTLBuffer, indirectBufferOffset: 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.
- indexType:
An Mtlindextype instance that represents the index’s format, including Uint16 and Uint32.
- indexBuffer:
An Mtlbuffer instance that contains the vertex indices of the
indexTypeformat. - indexBufferOffset:
An integer that represents the location that’s a multiple of the index size from the start of
indexBufferwhere the vertex indices begin. - indirectBuffer:
An Mtlbuffer instance with data that matches the layout of the Mtldrawindexedprimitivesindirectarguments structure.
- indirectBufferOffset:
An integer that represents the location, in bytes, from the start of
indirectBufferwhere the indirect arguments structure begins.See the Metal Feature Set Tables to check for offset alignment requirements for buffers in
deviceandconstantaddress space.
Discussion
Indirect drawing methods may help your app avoid expensive latency costs. This is because the command reads arguments from an MTLBuffer instance instead of using the CPU to pass parameters to the command.
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.