Free JavaScript Editor Ajax Editor

↑

Main Page

## 4.4. Built-in ConstantsThe OpenGL Shading Language defines a number of built-in constants. These values can be accessed from within either vertex shaders or fragment shaders. Values for lights, clip planes, and texture units are values that are equivalent to those that would be returned by OpenGL's glGet function for the underlying implementation. Implementation-dependent values that are new with the OpenGL Shading Language are the number of floatingpoint values that could be stored as uniform values accessible by the vertex shader and by the fragment shader, the number of floating-point values that could be defined as varying variables, the number of texture image units that are accessible by the vertex processor and by the fragment processor, the total number of texture image units available to the vertex processor and the fragment processor combined, the number of texture coordinates sets that are supported, and the number of draw buffers that are accessible. All these new implementation-dependent constants can also be obtained in application code with the OpenGL glGet function (see Section 7.12). OpenGL defines minimum values for each implementation-dependent constant. The minimum value informs application writers of the lowest value that is permissible for a conforming OpenGL implementation. The minimum value for each of the built-in constants is shown here. // // Implementation dependent constants. The values below // are the minimum values allowed for these constants. // const int gl_MaxLights = 8; const int gl_MaxClipPlanes = 6; const int gl_MaxTextureUnits = 2; const int gl_MaxTextureCoords = 2; const int gl_MaxVertexAttribs = 16; const int gl_MaxVertexUniformComponents = 512; const int gl_MaxVaryingFloats = 32; const int gl_MaxVertexTextureImageUnits = 0; const int gl_MaxTextureImageUnits = 2; const int gl_MaxFragmentUniformComponents = 64; const int gl_MaxCombinedTextureImageUnits = 2; const int gl_MaxDrawBuffers = 1; These values can occasionally be useful within a shader. For instance, a shader might include a general-purpose lighting function that loops through the available OpenGL lights and adds contributions from each enabled light source. The loop can easily be set up with the built-in constant gl_MaxLights. More likely, however, is that an application will use OpenGL's glGet function to obtain these implementation-dependent constants and decide, based on those values, whether to even load a shader (see Section 7.12). |

↓

Ajax Editor JavaScript Editor