Instance Method


Sets the viewport used for transformations and clipping.



func setViewport(_ viewport: MTLViewport)



The viewport used for transformations and clipping.


The viewport transforms vertices from normalized device coordinates to window coordinates. It also clips fragments that lie outside of its boundaries.

The x/y rectangle of the viewport must lie entirely within the current attachment size. The values for znear and zfar must be between 0.0 and 1.0. Flipping is allowed.

The default values for the viewport are:

  • originX = 0.0

  • originY = 0.0

  • width = w

  • height = h

  • znear = 0.0

  • zfar = 1.0

Calling setViewport(_:) after calling setViewports(_:count:), and vice versa, overrides previously set viewports.

See Also

Setting Viewport and Scissor Behavior

Rendering to Multiple Viewports in a Draw Command

Select viewports and their corresponding scissor rectangles in your vertex shader.

func setViewports([MTLViewport])

Sets an array of viewports.

func setScissorRect(MTLScissorRect)

Sets the scissor rectangle for a fragment scissor test.


func setScissorRects([MTLScissorRect])

Sets an array of scissor rectangles.

struct MTLViewport

A 3D rectangular region for the viewport clipping.

struct MTLScissorRect

A rectangle for the scissor fragment test.