<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4RenderCommandEncoder/setViewports(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "s:So24MTL4RenderCommandEncoderP5MetalE12setViewportsyySaySo11MTLViewportaGF"
  },
  "title" : "setViewports(_:)"
}
-->

# setViewports(_:)

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

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

## Parameters

`viewports`

A Swift array of [`MTLViewport`](/documentation/Metal/MTLViewport) elements.

## 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(_:)`](/documentation/Metal/MTL4RenderCommandEncoder/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)