Contents

drawPrimitives(primitiveType:vertexStart:vertexCount:instanceCount:baseInstance:)

Encodes a draw command that renders multiple instances of a geometric primitive, starting with a custom instance identification number.

Declaration

func drawPrimitives(primitiveType: MTLPrimitiveType, vertexStart: Int, vertexCount: Int, instanceCount: Int, baseInstance: Int)

Parameters

  • primitiveType:

    A Mtlprimitivetype representing how the command interprets vertex argument data.

  • vertexStart:

    The lowest value the command passes to your vertex shader function’s parameter with the vertex_id attribute.

  • vertexCount:

    An integer that represents the number of vertices of primitiveType the command draws.

  • instanceCount:

    An integer that represents the number of times the command draws primitiveType with vertexCount vertices.

  • baseInstance:

    The lowest value the command passes to your vertex shader function’s parameter with the instance_id attribute.

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 baseInstance through (baseInstance + 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.

See Also

Drawing with vertices