drawPrimitives(type:vertexStart:vertexCount:instanceCount:)
Encodes a draw command that renders multiple instances of a geometric primitive.
Declaration
func drawPrimitives(type primitiveType: MTLPrimitiveType, vertexStart: Int, vertexCount: Int, instanceCount: 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.
- vertexStart:
The lowest value the command passes to your vertex shader’s parameter with the
vertex_idattribute. The command assigns each vertex a uniquevertex_idvalue within its drawing instance that increases fromvertexStartthrough(vertexStart + vertexCount - 1). Your shader can use that value to identify a vertex in each drawing instance.For more information about the
vertex_idargument attribute for vertex shaders, see the Metal Shading Language Specification. - vertexCount:
An integer that represents the number of vertices of
primitiveTypethe command draws per instance. - instanceCount:
An integer that represents the number of times the command draws
primitiveTypewithvertexCountvertices.The command assigns each drawing instance a unique
instance_idvalue that increases from0through(instanceCount - 1). Your shader can use that value to identify which instance the vertex belongs to.For more information about the
instance_idargument attribute for vertex shaders, the Metal Shading Language Specification.
Discussion
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.