<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLRenderCommandEncoder/setViewport(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTLRenderCommandEncoder(im)setViewport:"
  },
  "title" : "setViewport(_:)"
}
-->

# setViewport(_:)

Configures the render pipeline with a viewport that applies a transformation and a clipping rectangle.

```
func setViewport(_ viewport: MTLViewport)
```

## Parameters

`viewport`

An [`MTLViewport`](/documentation/Metal/MTLViewport) instance the command applies to the render pipeline for transformations and clipping.

## Discussion

The render pipeline linearly maps vertex positions from normalized device coordinates to viewport coordinates by applying a viewport during the rasterization stage. It applies the transform first and then rasterizes the primitive while clipping any fragments outside the scissor rectangle (see [`setScissorRect(_:)`](/documentation/Metal/MTLRenderCommandEncoder/setScissorRect(_:))) or the render target’s extents.

The viewport’s [`originX`](/documentation/Metal/MTLViewport/originX) and [`originY`](/documentation/Metal/MTLViewport/originY) properties, which default to `0.0`, represent the number of pixels from the top-left corner of the render target. Positive [`originX`](/documentation/Metal/MTLViewport/originX) values go to the right and positive [`originY`](/documentation/Metal/MTLViewport/originY) values go downward. The default values for its [`width`](/documentation/Metal/MTLViewport/width) and [`height`](/documentation/Metal/MTLViewport/height) properties are the render target’s width and height, respectively. The default values for its [`znear`](/documentation/Metal/MTLViewport/znear) and [`zfar`](/documentation/Metal/MTLViewport/zfar) properties are `0.0` and `1.0`, respectively, which you can flip.

> Note:
> You can change the render pass’s viewport configuration by calling this method again, or by calling the ``doc://com.apple.metal/documentation/Metal/MTLRenderCommandEncoder/setViewports(_:)`` method.

---

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)