Instance Method


Sets an array of viewports.



- (void)setViewports:(const MTLViewport *)viewports count:(NSUInteger)count;



An array of viewports.


The number of viewports in the array.


Use this method to specify multiple active viewports and corresponding scissor rectangles, enabling you to draw into separate areas of an image using a single draw call.

The maximum number of supported viewports and scissor rectangles varies by device. For more information, see Using Metal Feature Set Tables.

The rendering pipeline uses only one of the viewports to transform and clip vertices. You select this viewport per primitive by specifying a [[viewport_array_index]] attribute on an output value from your vertex function.

Calling this method with an array of length 1 is equivalent to calling the setViewport: method. Calling setViewport: after calling setViewports:count:, and vice versa, overrides previously set viewports.

You can call the setScissorRect: method to set a single scissor rectangle for all viewports. Otherwise, you can call the setScissorRects:count: method to set different scissor rectangles for different viewports. The number of scissor rectangles must match the number of 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.

- setViewport:

Sets the viewport used for transformations and clipping.


- setScissorRect:

Sets the scissor rectangle for a fragment scissor test.


- setScissorRects:count:

Sets an array of scissor rectangles.



A 3D rectangular region for the viewport clipping.


A rectangle for the scissor fragment test.