glViewport Function

Syntax

GL_APICALL void GL_APIENTRY glViewport(
     GLint x,
     GLint y,
     GLsizei width,
     GLsizei height
);

Parameters

Name Description
in x X coordinate of the viewport's lower-left corner
in y Y coordinate of the viewport's lower-left corner
in width Viewport width
in height Viewport height

Return Values

No values are returned.

Description

Configures the viewport.

Set x to the x coordinate of the viewport's lower-left corner. Set y to the y coordinate of the viewport's lower-left corner. Unlike in the OpenGL ES 2.0 standard, x and y must be no less than 0. The values of x and y affect rendering performance. Performance degrades when x and y are not multiples of 4. Specifically, performance drops to approximately one-half for any multiple of 2 that is not a multiple of 4, and drops to approximately one-third for odd numbers. We recommend that you adjust for this using the frustum for perspective projection transformations and that you exclude unnecessary areas via scissoring in order to set x and y to multiples of 4 and thus avoid performance degradation.

To enable the early depth test, you must set the viewport offset (argument x,y) to 0. The depth test will not be performed correctly if a value other than 0 is set. If you need to perform a process equivalent to using the offset, you can offset the viewport by using a model view transform and then delete the unneeded area using scissoring instead.

Set width to the viewport width.

Set height to the viewport height.

Specify a viewport size of 1023 x 1016 or less. If a larger size is specified, polygons may not be rendered properly or the GPU may hang. This restriction is due to a hardware bug and cannot be improved.

This function generates the following errors.

GL_INVALID_VALUEThe x, y, width, or height argument was set to a negative value.
GL_INVALID_OPERATIONThis function was called without any command-list objects bound.

Revision History

2011/02/07
Added information about viewport limitations and size restrictions when an early depth test is enabled.
2010/01/07
Initial version.

CONFIDENTIAL