1Name 2 3 ARB_cull_distance 4 5Name Strings 6 7 GL_ARB_cull_distance 8 9Contact 10 11 Brian Paul, VMware Inc. (brianp 'at' vmware.com) 12 13Contributors 14 15 Brian Paul, VMware 16 Daniel Rakos, AMD 17 Pat Brown, NVIDIA 18 Piers Daniell, NVIDIA 19 20Notice 21 22 Copyright (c) 2014 The Khronos Group Inc. Copyright terms at 23 http://www.khronos.org/registry/speccopyright.html 24 25Specification Update Policy 26 27 Khronos-approved extension specifications are updated in response to 28 issues and bugs prioritized by the Khronos OpenGL Working Group. For 29 extensions which have been promoted to a core Specification, fixes will 30 first appear in the latest version of that core Specification, and will 31 eventually be backported to the extension document. This policy is 32 described in more detail at 33 https://www.khronos.org/registry/OpenGL/docs/update_policy.php 34 35Status 36 37 Complete. 38 Approved by the ARB on June 26, 2014. 39 Ratified by the Khronos Board of Promoters on August 7, 2014. 40 41Version 42 43 Date: June 17, 2014 44 Revision: 9 45 46Number 47 48 ARB Extension #162 49 50Dependencies 51 52 OpenGL 3.0 is required. 53 54 The extension is written against the OpenGL 4.4 Specification, Core 55 Profile, March 19, 2014. 56 57 The extension is written against the OpenGL Shading Language 4.40 58 Specification, January 22, 2014. 59 60Overview 61 62 This extension adds a new GLSL gl_CullDistance shader output, similar 63 to gl_ClipDistance, but used for whole primitive culling. 64 65 This new stage in the pipeline is added as part of the primitive clipping 66 stage. 67 68IP Status 69 70 No known IP claims. 71 72New Procedures and Functions 73 74 None 75 76New Types 77 78 None 79 80New Tokens 81 82 Accepted by the <pname> parameter of GetBooeleanv, GetDoublev, GetFloatv 83 GetIntegerv, and GetInteger64v: 84 85 MAX_CULL_DISTANCES 0x82F9 86 MAX_COMBINED_CLIP_AND_CULL_DISTANCES 0x82FA 87 88Additions to Chapter 7 of the OpenGL 4.4 (Core Profile) Specification (Programs and Shaders) 89 90 Modify Section 7.4.1, Shader Interface Matching 91 92 (modify last sentence of third paragraph on p. 112) 93 94 If either shader redeclares the built-in array gl_CullDistance[] or 95 gl_ClipDistance[], the array must have the same size in both shaders. 96 97Additions to Chapter 11 of the OpenGL 4.4 (Core Profile) Specification (Programmable Vertex Processing) 98 99 Modify Section 11.1.3.10, Shader Outputs 100 101 (replace the first sentence of the third paragraph on p. 358) 102 103 The built-in output variables gl_ClipDistance and glCullDistance hold the 104 clip distance(s) and cull distance(s), respectively, used in the culling 105 stage, as described in section 13.5. 106 107 Modify Section 11.2.1.2.2, Tessellation Control Shader Inputs 108 109 (modify last sentence of first paragraph on p. 365) 110 111 The members of each element of the gl_in array are gl_Position, 112 gl_PointSize, gl_ClipDistance, gl_CullDistance, and gl_ClipVertex. 113 114 Modify Section 11.2.1.2.3, Tessellation Control Shader Outputs 115 116 (modify last sentence of first paragraph on p. 366) 117 118 The members of each element of the gl_out array are gl_Position, 119 gl_PointSize, gl_ClipDistance, and gl_CullDistance, and behave identically 120 to equivalently named vertex shader outputs (section 11.1.3). 121 122 Modify Section 11.2.3.3, Tessellation Evaluation Shader Inputs 123 124 (modify last sentence of first paragraph on p. 380) 125 126 The members of each element of the gl_in array are gl_Position, 127 gl_PointSize, gl_ClipDistance, and gl_CullDistance. 128 129 Modify Section 11.2.3.4, Tessellation Evaluation Shader Ouputs 130 131 (modify last sentence of first paragraph on p. 381) 132 133 These variables are gl_Position, gl_PointSize, gl_ClipDistance, and 134 gl_CullDistance, and all behave identically to equivalently named vertex 135 shader outputs (see section 11.1.3). 136 137 Modify Section 11.3.4.4, Geometry Shader Inputs 138 139 (add after first bullet in first paragraph on p. 387) 140 141 * Structure member gl_CullDistance[] holds the per-vertex array of cull 142 distances, as written by the vertex shader to its built-in output 143 variable gl_CullDistance[]. 144 145 Modify Section 11.3.4.5, Geometry Shader Outputs 146 147 (replace second paragraph on p. 389) 148 149 The built-in outputs gl_ClipDistance and gl_CullDistance hold the clip 150 distance(s) and cull distance(s), respectively, used in the clipping 151 stage, as described in section 13.5. 152 153Additions to Chapter 13 of the OpenGL 4.4 (Core Profile) Specification (Fixed-Function Vertex Post-Processing) 154 155 Modify Section 13.5, Primitive Clipping 156 157 (replace first sentence of first paragraph on p. 404) 158 159 Primitives are culled against the cull volume and then clipped against the 160 clip volume. 161 162 (replace the second, third, and fourth paragraph on p. 404) 163 164 This view volume may be further restricted by as many as <n> client- 165 defined half-spaces. <n> is an implementation-dependent maximum that must 166 be at least 8, and maybe determined by calling GetIntegerv with the 167 symbolic constant MAX_COMBINED_CLIP_AND_CULL_DISTANCES. 168 169 The cull volume is the intersection of up to MAX_CULL_DISTANCES client- 170 defined half-spaces (if no client-defined cull half-spaces are enabled, 171 culling against the cull volume is skipped). The number of enabled cull 172 half-spaces is determined by the explicit or implicit size of the built-in 173 array gl_CullDistance in the last shader stage before rasterization that 174 has an active program. 175 176 A shader may write a single cull distance for each enabled cull half-space 177 to elements of the gl_CullDistance[] array. If the cull distance for any 178 enabled cull half-space is negative for all of the vertices of the 179 primitive under consideration, the primitive is discarded. Otherwise the 180 primitive is clipped against the clip volume as defined below. 181 182 The clip volume is the intersection of up to MAX_CLIP_DISTANCES client- 183 defined half-spaces with the view volume (if no client-defined clip half- 184 spaces are enabled, the clip volume is the view volume). Client-defined 185 clip half-spaces are enabled or disabled by calling Enable or Disable with 186 <target> CLIP_DISTANCE<i>, where <i> is an integer between 0 and <n> - 1; 187 specifying a value of <i> enables or disables the client-defined clip 188 half-space with index <i>. The constants obey CLIP_DISTANCE<i> = 189 CLIP_DISTANCE0 + <i>. 190 191 A shader may write a single clip distance for each enabled clip half-space 192 to elements of the gl_ClipDistance[] array. Clip half-space <i> is then 193 given by the set of points satisfying the inequality 194 195 c[i](P) >= 0, 196 197 where c[i](P) is the value of clip distance <i> at point P. For point 198 primitives, c[i](P) is simply the clip distance for the vertex in 199 question. For line and triangle primitives, per-vertex clip distances are 200 interpolated using a weighted mean, with weights derived according to the 201 algorithms described in sections 14.5 and 14.6. 202 203 Depth clamping ... 204 205Additions to the OpenGL Shading Language 206 207 Including the following line in a shader can be used to control the 208 language features described in this extension: 209 210 #extension GL_ARB_cull_distance : <behavior> 211 212 where <behavior> is as specified in section 3.3. 213 214 New preprocessor #define is added to the OpenGL Shading Language: 215 216 #define GL_ARB_cull_distance 1 217 218Additions to Chapter 7 of the OpenGL Shading Language 4.40 Specification (Built-in Variables) 219 220 Modify Section 7.1, Built-In Language Variables 221 222 (add a new field to the end of the declaration of "gl_PerVertex" for 223 all language input and output blocks on p. 120-122) 224 225 float gl_CullDistance[]; 226 227 (add new declaration to the built-in variables available in the fragment 228 language on p. 122) 229 230 in float gl_CullDistance[]; 231 232 (add after second paragraph on p. 124) 233 234 The variable gl_CullDistance provides a mechanism for controlling user 235 culling. The element gl_CullDistance[i] specifies a cull distance for 236 plane <i>. A distance of 0 means the vertex is on the plane, a positive 237 distance means the vertex is inside the cull volume, and a negative 238 distance means the point is outside the cull volume. Primitives whose 239 vertices all have a negative clip distance for plane <i> will be 240 discarded. 241 242 The gl_CullDistance array is predeclared as unsized and must be sized by 243 the shader either redeclaring it with a size or indexing it only with 244 integral constant expressions. The size determines the number and set of 245 enabled cull distances and can be at most gl_MaxCullDistances. The number 246 of varying components (see gl_MaxVaryingComponents) consumed by 247 gl_CullDistance will match the size of the array. Shaders writing 248 gl_CullDistance must write all enabled distances, or culling results are 249 undefined. 250 251 As an output variable, gl_CullDistance provides the place for the shader 252 to write these distances. As an input in all but the fragment language, 253 it reads the values written in the previous shader stage. In the 254 fragment language, gl_CullDistance array contains linearly interpolated 255 values for the vertex values written by a shader to the gl_CullDistance 256 vertex output variable. 257 258 It is a compile-time or link-time error for the set of shaders forming 259 a program to have the sum of the sizes of the gl_ClipDistance and 260 gl_CullDistance arrays to be larger than 261 gl_MaxCombinedClipAndCullDistances. 262 263 Modify Section 7.1.1, Compatibility Profile Built-In Language Variables 264 265 (modify last sentence on p. 128) 266 267 It is a compile-time or link-time error for the set of shaders forming 268 a program to statically read or write both gl_ClipVertex and 269 either gl_ClipDistance or gl_CullDistance. 270 271 Modify Section 7.3, Built-In Constants 272 273 (add to the list of implementation-dependent constants after 274 gl_MaxClipDistances on p. 132) 275 276 const int gl_MaxCullDistances = 8; 277 const int gl_MaxCombinedClipAndCullDistances = 8; 278 279Additions to the AGL/EGL/GLX/WGL Specifications 280 281 None 282 283Errors 284 285 None 286 287New State 288 289 None. 290 291New Implementation Dependent State 292 293 (add to table 23.53, Implementation Dependent Values) 294 295 Get Value Type Get Command Minimum value Description Sec. 296 ------------------------------------ ---- ----------- ------------- --------------------------------- ---- 297 MAX_CULL_DISTANCES Z+ GetIntegerv 8 Max no. of user culling planes 13.5 298 MAX_COMBINED_CLIP_AND_CULL_DISTANCES Z+ GetIntegerv 8 Max combined no. of user clipping 13.5 299 and culling planes 300 301Issues 302 303 (1) Why is this extension necessary? 304 305 RESOLVED: This feature is supported by a competing graphics API. One 306 could implement some of this functionality with a geometry shader but 307 that doesn't work well in all circumstances, or is very difficult. 308 309 (2) Should there be enable flags for cull distances as there are for 310 clip distances? 311 312 RESOLVED: The clip plane enables still exist for OpenGL 4.4 core 313 profile, but they are mostly there because of backwards compatibility 314 reasons. The proposal is to not have separate enables for cull 315 distances, instead usage in the shader should determine this. 316 317 (3) How many cull distances are supported? 318 319 RESOLVED: Eight. But as resources used by cull distances and clip 320 distances may be aliased on some implementations we also introduce a 321 combined resource limit of eight. 322 323 (4) How do we determine the number of enabled cull distances? 324 325 RESOLVED: Redeclaring the gl_CullDistance array with a size of <n> 326 automatically enables the first <n> cull distances. 327 328 (5) Which shader stage determines the number of enabled cull distances in 329 case multiple shader stages redeclare gl_CullDistance? 330 331 RESOLVED: The implicit or explicit size of gl_CullDistance in the 332 very last shader stage before rasterization determines the number 333 of enabled cull distances. 334 335 (6) How should we validate that we don't go over resource limits? 336 337 RESOLVED: There is an implicit or explicit size for both 338 gl_ClipDistance and gl_CullDistance in the shader. If the sum of the 339 sizes of the two arrays is over MAX_COMBINED_CLIP_AND_CULL_DISTANCES 340 it results in a compile-time or link-time error. 341 342 (7) Should there be a built-in gl_CullDistance in the fragment language? 343 344 RESOLVED: Yes, just like gl_ClipDistance is available in the fragment 345 language. 346 347Revision History 348 349 Revision 9, 2014/06/17 (Daniel Rakos) 350 - Added missing tokens. 351 352 Revision 8, 2014/06/06 (Daniel Rakos) 353 - Resolved issues (5) and (7). 354 - Clarified language describing the number of enabled cull distances. 355 356 Revision 7, 2014/05/30 (Daniel Rakos) 357 - Resolved issues (2), (3), (4), and (6). 358 359 Revision 6, 2014/05/22 (Daniel Rakos) 360 - Minor language cleanup. 361 362 Revision 5, 2014/05/19 (Daniel Rakos) 363 - Added language to explicitly disallow the use of gl_ClipVertex and 364 gl_CullDistance at the same time. 365 366 Revision 4, 2014/05/16 (Daniel Rakos) 367 - Added missing language about #extension and #define for the feature. 368 369 Revision 3, 2014/04/25 (Daniel Rakos) 370 - Renamed to ARB_cull_distance. 371 - Added implementation-dependent states MAX_CULL_DISTANCES and 372 MAX_COMBINED_CLIP_AND_CULL_DISTANCES. 373 - Rewrote language based on discussion. 374 - Added issues (3) to (7). 375 376 Revision 2, 2014/04/10 (Brian Paul) 377 - Fleshed out edits to chapter 13 of the spec. 378 - Added issue (2). 379 380 Revision 1, 2014/02/03 (Brian Paul) 381 - Initial revision. 382