From OpenGL Reference
Jump to navigation Jump to search

Provides a forward-compatible mechanism for vertex clipping.



Thegl_ClipDistancevariable provides a forward compatible mechanism for controlling user clipping. The element gl_ClipDistance [i] specifies a clip distance for each user clip planei. A distance of 0.0 means that the vertex is on the plane, a positive distance means that the vertex is inside the clip plane, and a negative distance means that the point is outside the clip plane. The clip distances will be linearly interpolated across the primitive and the portion of the primitive with interpolated distances less than 0.0 will be clipped.

Thegl_ClipDistancearray is initially predeclared as unsized and must be sized by the shader either by redeclaring it with an explicit size, or by indexing it with only integral constant expressions. The array must be sized to include all clip planes that are enabled via the OpenGL API; if the size does not include all enabled planes, results are undefined. The size may be at mostgl_MaxClipDistances. The number of varying components consumed bygl_ClipDistancewill match the size of the array, no matter how many planes are enabled. The shader must also set all values ingl_ClipDistancethat have been enabled via the OpenGL API, or results are undefined. Values written intogl_ClipDistanceplanes that are not enabled have no effect.

In the vertex, tessellation evaluation and geometry languages, a single global instance of thegl_PerVertexnamed block is available and itsgl_ClipDistancemember is an output that receives the clip distances for the current vertex. It may be written at any time during shader execution. The value written togl_ClipDistancewill be used by primitive assembly, clipping, culling and other fixed functionality operations, if present, that operate on primitives after vertex processing has occurred.

In the tessellation control language, thegl_PerVertexnamed block is used to construct an array,gl_out[], whosegl_ClipDistancemembers hold clip distances for each of the control points, which become available as inputs to the subsequent tessellation evaluation shader.

The value ofgl_ClipDistance(or thegl_ClipDistancemember of thegl_out[]array, in the case of the tessellation control shader) is undefined after the vertex, tessellation control, and tessellation evaluation shading stages if the corresponding shader executable does not write to gl_ClipDistance. It is also undefined after the geometry processing stage if the geometry shader executable calls EmitVertex without having writtengl_ClipDistancesince the last call to EmitVertex (or hasn't written it at all).

In the tessellation control, tessellation evaluation and geoemetry languages, thegl_PerVertexnamed block is used to construct an array,gl_in[]of per-vertex or per-control point inputs whose content represents the corresponding outputs written by the previous stage. Only elements of thegl_ClipDistancearray that correspond to enabled clip planes have defined values.

Version Support[edit]

gl_ClipDistance 1.3+

Versions 1.30 to 1.40 - vertex shader only.

Versions 1.50 to 3.30 - vertex and geometry shaders only.

See Also[edit]

 gl_CullDistance , gl_PointSize 


Copyright© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999.