drawPrimitives(primitiveType:vertexStart:vertexCount:instanceCount:)
Encodes a draw command that renders multiple instances of a geometric primitive.
Declaration
func drawPrimitives(primitiveType: MTLPrimitiveType, vertexStart: Int, vertexCount: Int, instanceCount: Int)Parameters
- primitiveType:
A Mtlprimitivetype represents how the command interprets vertex argument data.
- vertexStart:
The lowest value the command passes to your vertex shader function’s parameter with the
vertex_idattribute. - vertexCount:
An integer that represents the number of vertices of
primitiveTypethe command draws. - instanceCount:
An integer that represents the number of times the command draws
primitiveTypeprimitives withvertexCountvertices.
Discussion
The command assigns each vertex a unique vertex_id value within its drawing instance that increases from vertexStart through (vertexStart + vertexCount - 1).
Additionally, the command assigns each drawing instance a unique instance_id value that increases from 0 through (instanceCount - 1).
Your vertex shader can use the vertex_id value to uniquely identify each vertex in each drawing instance, and the instance_id value to identify which instance that vertex belongs to.