User Clip Planes is mechanism provided by OpenGL that allows application to provide information about additional clipping planes, against which rendered geometry will be clipped. Each user specified clip plane can be turned on and off separately, and for each of them four plane equation coefficients can be provided using OpenGL API:

void glEnable(GLenum  cap);

where cap is GL_CLIP_DISTANCEi ( i == 0 to N-1 )

void glClipPlane(GLenum  plane, const GLdouble *  equation);

where plane is GL_CLIP_PLANEi ( i == 0 to N-1 )

Number of clip planes, currently supported by the HW, can be queried using API enum GL_MAX_CLIP_DISTANCES (GL_MAX_CLIP_PLANES in deprecated model), or by using built in variable gl_MaxClipDistances in GLSL shader (gl_MaxClipPlanes in deprecated model). Each OpenGL and OpenGL ES specification defines minimum amount of user clip planes that need to be supported by the hardware:

OpenGL GLSL GL_MAX_CLIP_PLANES gl_MaxClipDistances (gl_MaxClipPlanes)
1.0 – 1.5 None 6+* None
2.0 1.10 6+ 6+
2.1 1.20
3.0 1.30 8+ 8+
3.1 1.40
3.2 1.50
3.3 3.30
4.0 4.00
4.5 4.50

*) N+ means support for minimum N elements or more

1.0 None 1+* None
2.0 1.10 1+
3.0 3.00 0 0

*) N+ means support for minimum N elements or more

Current statistics about actual HW support can be found under this link: (search for GL_MAX_CLIP_PLANES).

There are three usage models that support user specified Clip Planes in GLSL (or ARB assembly):

Mode Available in Description
Default OpenGL 1.0 – 3.1OpenGL 3.2+ in Compatibility Mode By default clipping is performed by the last active geometry stage (it can be Vertex Shader, Tessellation Evaluation Shader or Geometry Shader). Final vertex position stored in gl_Position is used to compute clip distances of this vertex for each active user clip plane.
Specified Clip Vertex OpenGL 2.0 – 3.1OpenGL 3.2+ in Compatiblity Mode If there is gl_ClipVertex specified in the last geometry stage, it is used for computation of clip distances instead of vertex stored in gl_Position.
Specified Clip Distances OpenGL 3.2+ If there is gl_ClipDistance[] specified in the last geometry stage, then it’s value is immediately treated as a result of clip distance calculation.

Why there are three different modes that can be used? It’s all because of legacy support. At the beginning OpenGL was Fixed Function state machine based API. There were no shaders, and specifying parameters of plane equations for user clip planes through the API calls was the way to go. Thats „default” mode. Then OpenGL started to support shaders, but was still focused more on fixed functionality. With introduction of shaders, there was idea that user can specify different position for clipping than for transformation and rasterization. That’s how second mode showed up. Time went by, and GPU’s transformed from Fixed Function units to fully programmable processors. Most of old Fixed Function mechanisms are now emulated in shaders, by additional instructions inserted to shader code by the driver. When Fixed Function state changes (like for example turning on and off one of user clip planes) shader code needs to be recompiled. This means that shader is tied up with some Fixed Function state, and each state change requires shader recompilation (which in most cases happen during frame rendering and causes stuttering of animation). Such state is called Non Orthogonal State and both previous Clip Plane modes had it. Therefore third mode was introduced, where shader computes vertex distance from clip plane on it’s own and only outputs result of this computation – clip distance. For each user specified Clip Plane, clip distance less than 0.0, means that current vertex is outside clipping plane and should be rejected. Clip distance greater or equal to 0.0 means that vertex is inside clipping plane and it passed test for that plane.

OpenGL 4.5 introduces also notion of Cull Distances for compatibility with DirectX.