---
title: "setViewport(_:)"
framework: metal
role: symbol
role_heading: Instance Method
path: "metal/mtlrendercommandencoder/setviewport(_:)"
---

# setViewport(_:)

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

## Declaration

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

## Parameters

- `viewport`: An doc://com.apple.metal/documentation/Metal/MTLViewport instance the command applies to the render pipeline for transformations and clipping.

## Discussion

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(_:)) or the render target’s extents. The viewport’s originX and originY properties, which default to 0.0, represent the number of pixels from the top-left corner of the render target. Positive originX values go to the right and positive originY values go downward. The default values for its width and height properties are the render target’s width and height, respectively. The default values for its znear and 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 setViewports(_:) method.

## See Also

### Configuring viewport and scissor behavior

- [setViewports(_:)](metal/mtlrendercommandencoder/setviewports(_:).md)
- [setScissorRect(_:)](metal/mtlrendercommandencoder/setscissorrect(_:).md)
- [setScissorRects(_:)](metal/mtlrendercommandencoder/setscissorrects(_:).md)
