Instance Method

setViewport(_:)

Sets the viewport used for transformations and clipping.

Required.

Declaration

func setViewport(_ viewport: MTLViewport)

Parameters

viewport

The viewport used for transformations and clipping.

Discussion

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.

Required.

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software