---
title: "drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4rendercommandencoder/drawindexedprimitives(primitivetype:indexcount:indextype:indexbuffer:indexbufferlength:)"
---

# drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:)

Encodes a draw command that renders an instance of a geometric primitive with indexed vertices.

## Declaration

```swift
func drawIndexedPrimitives(primitiveType: MTLPrimitiveType, indexCount: Int, indexType: MTLIndexType, indexBuffer: MTLGPUAddress, indexBufferLength: Int)
```

## Parameters

- `primitiveType`: A doc://com.apple.metal/documentation/Metal/MTLPrimitiveType representing how the command interprets vertex argument data.
- `indexCount`: An integer that represents the number of vertices the command reads from indexBuffer.
- `indexType`: A doc://com.apple.metal/documentation/Metal/MTLIndexType instance that represents the index format.
- `indexBuffer`: GPUAddress of a doc://com.apple.metal/documentation/Metal/MTLBuffer instance that contains indexCount indices of indexType format. You are responsible for ensuring this address is aligned to 2 bytes if the indexType format is doc://com.apple.metal/documentation/Metal/MTLIndexType/uint16, and aligned to 4 bytes if the format is doc://com.apple.metal/documentation/Metal/MTLIndexType/uint32.
- `indexBufferLength`: An integer that represents the length of indexBuffer, in bytes. You are responsible for ensuring this this size is a multiple of 2 if the indexType format is doc://com.apple.metal/documentation/Metal/MTLIndexType/uint16, and a multiple of 4 if the format is doc://com.apple.metal/documentation/Metal/MTLIndexType/uint32. If this draw call causes Metal to read indices at or beyond the indexBufferLength, Metal continues to execute them assigning a value of 0 to the vertex_id attribute.

## Discussion

Discussion Use this method to perform indexed drawing, where an index buffer determines how Metal assembles primitives. Metal imposes some restrictions on the index buffer’s address, which needs to be 2- or 4-byte aligned, and its length in bytes, which needs to be a multiple of 2 or 4, depending on whether the format of the index is MTLIndexType.uint16 or MTLIndexType.uint32. Use an instance of MTLResidencySet to mark residency of the index buffer the indexBuffer parameter references.

## See Also

### Drawing with indexed vertices

- [drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:)](metal/mtl4rendercommandencoder/drawindexedprimitives(primitivetype:indexcount:indextype:indexbuffer:indexbufferlength:instancecount:).md)
- [drawIndexedPrimitives(primitiveType:indexCount:indexType:indexBuffer:indexBufferLength:instanceCount:baseVertex:baseInstance:)](metal/mtl4rendercommandencoder/drawindexedprimitives(primitivetype:indexcount:indextype:indexbuffer:indexbufferlength:instancecount:basevertex:baseinstance:).md)
- [drawIndexedPrimitives(primitiveType:indexType:indexBuffer:indexBufferLength:indirectBuffer:)](metal/mtl4rendercommandencoder/drawindexedprimitives(primitivetype:indextype:indexbuffer:indexbufferlength:indirectbuffer:).md)
