Scissor Test

From OpenGL.org
Jump to: navigation, search

The Scissor Test is a Per-Sample Processing operation that discards Fragments that fall outside of a certain rectangular portion of the screen.

To activate the scissor test, first enable the GL_SCISSOR_TEST enumerator. Once enabled, pixels outside of the scissor box will be discarded. To define the scissor box, use this function:

void glScissor(GLint x​, GLint y​, GLsizei width​, GLsizei height​);

The x​ and y​ is the window-space lower-left position of the scissor box, and width​ and height​ define the size of the rectangle.

Scissor array

Viewport Arrays
Core in version 4.5
Core since version 4.1
Core ARB extension ARB_viewport_array

When multiple viewports are used, each viewport in the array has its own separate scissor box. The glScissor above sets the scissor box for all viewports.

Each viewport also has its own enable state for the scissor test, as set by glEnablei/Disablei. Using the non-indexed glEnable/Disable will enable or disable scissoring for all viewports.

To set the scissor box for a specific viewport, use one of these functions:

void glScissorIndexed(GLuint index​, GLint left​, GLint bottom​, GLsizei width​, GLsizei height​);

void glScissorIndexedv(GLuint index​, const GLint *v​);

index​ must be less than GL_MAX_VIEWPORTS. The array version takes 4 integers, in the same order as the parameters for glScissorIndexed.

The scissor box for several viewports can be set with this function:

void glScissorArrayv(GLuint first​, GLsizei count​, const GLint *v​);

This sets each viewport's scissor box starting from first​ up to (but not including) first​ + count​. v​ is an array, where every 4 elements of the array are the scissor box for a single viewport. Therefore, v​ is expected to contain 4 * count​ elements.

Affected commands

The scissor test affects all Rendering Commands that write values to the current draw Framebuffer. Compute shader dispatches are rendering commands, but they do not write to the framebuffer. Even if they write to an image that happens to be within a framebuffer, they are not considered to be writing to the framebuffer.