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, respectively. Flipping is allowed.

The default values for the viewport are originX = 0.0; originY = 0.0; width = w; height = h; znear = 0.0; and zfar = 1.0, where w and h are the x and y dimensions of the attachment, respectively.

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

See Also

Setting Viewport and Scissor Behavior

func setViewports([MTLViewport])

Sets an array of viewports.

struct MTLViewport

A 3D rectangular region for the viewport clipping.

func setScissorRect(MTLScissorRect)

Sets the scissor rectangle for a fragment scissor test.


struct MTLScissorRect

A rectangle for the scissor fragment test.