---
title: "setViewports(_:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtl4rendercommandencoder/setviewports(_:)"
---

# setViewports(_:)

Sets an array of viewports to transform vertices from normalized device coordinates to window coordinates.

## Declaration

```swift
func setViewports(_ viewports: [MTLViewport])
```

## Parameters

- `viewports`: A Swift array of doc://com.apple.metal/documentation/Metal/MTLViewport elements.

## Discussion

Discussion Metal clips fragments that lie outside of the viewport, and optionally clamps fragments outside of z-near/z-far range, depending on the value you assign to setDepthClipMode(_:). Metal selects the viewport to use from the [[ viewport_array_index ]] attribute you specify in the pipeline state’s vertex shader function in the Metal Shading Language.

## See Also

### Configuring viewport and scissor behavior

- [setViewport(_:)](metal/mtl4rendercommandencoder/setviewport(_:).md)
- [setScissorRect(_:)](metal/mtl4rendercommandencoder/setscissorrect(_:).md)
- [setScissorRects(_:)](metal/mtl4rendercommandencoder/setscissorrects(_:).md)
