setViewport(_:)
Configures the render pipeline with a viewport that applies a transformation and a clipping rectangle.
Declaration
func setViewport(_ viewport: MTLViewport)Parameters
- viewport:
An Mtlviewport instance the command applies to the render pipeline for transformations and clipping.
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.