GL_CLIPDISTANCE(3G)

NAME
gl_ClipDistance - provides a forward-compatible mechanism for vertex clipping

DECLARATION

gl_ClipDistance is a member of the gl_PerVertex named block:

    out gl_PerVertex {
        vec4 gl_Position;
        float gl_PointSize;
        float gl_ClipDistance[];
    };

In fragment shaders, it is intrinsically declared as: in float gl_ClipDistance[] ;

DESCRIPTION

The gl_ClipDistance variable provides a forward compatible mechanism for controlling user clipping. The element gl_ClipDistance[i] specifies a clip distance for each user clip plane i. A distance of 0.0 means that the vertex is on the plane, a positive distance means that the vertex is insider 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.

The gl_ClipDistance array 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 most gl_MaxClipDistances. The number of varying components consumed by gl_ClipDistance will match the size of the array, no matter how many planes are enabled. The shader must also set all values in gl_ClipDistance that have been enabled via the OpenGL API, or results are undefined. Values written into gl_ClipDistance planes that are not enabled have no effect.

In the vertex, tessellation evaluation and geometry languages, a single global instance of the gl_PerVertex named block is available and its gl_ClipDistance member 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 to gl_ClipDistance will 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, the gl_PerVertex named block is used to construct an array, gl_out[], whose gl_ClipDistance members hold clip distances for each of the control points, which become available as inputs to the subsequent tessellation evaluation shader.

The value of gl_ClipDistance (or the gl_ClipDistance member of the gl_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 written gl_ClipDistance since the last call to EmitVertex() (or hasn't written it at all).

In the tessellation control, tessellation evaluation and geoemetry languages, the gl_PerVertex named 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 the gl_ClipDistance array that correspond to enabled clip planes have defined values.

VERSION SUPPORT
 | OpenGL Shading Language Version
Variable Name | 1.10 | 1.20 | 1.30 | 1.40 | 1.50 | 3.30 | 4.00 | 4.10 | 4.20 | 4.30 | 4.40 | 4.50
gl_ClipDistance | - | - | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔

Versions 1.30 to 1.40 - vertex shader only.

Versions 1.50 to 3.30 - vertex and geometry shaders only.

SEE ALSO

gl_CullDistance(), gl_PointSize()

COPYRIGHT

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. http://opencontent.org/openpub/.

COPYRIGHT
Copyright © 2011-2014 Khronos Group