I’ve been writing programs using OpenGL. Recently, I started learning OpenGL Shading Language. I’m a newbie; so please be detailed in your answers.
My questions are:
- What are different types of variable (qualifiers) in GLSL?
- What are they used for?
- How are they different from one another?
I am only familiar with “varying” variable which is passed from Vertex Shaders to Fragment Shaders to be interpolated between vertices. Other than that, I know nothing else.
In OpenGL 3+ :
varyingis deprecatedconstis for… well, constants !uniformis for per draw call (at most) valuesinis for input from the previous pipeline stage, i.e. per vertex (or per fragment) values at most, per primitive if using glAttribDivisor and hardware instanciationoutis for output to the next stageRegarding outputs for fragment shaders : in OpenGL3 and up, most of the built-in variables for fragment shader output (such as
gl_FragColor, with the notable exception ofgl_FragDepth) are deprecated and should be replaced with user-definedoutvariables.If you are outputting to the default framebuffer, whatever you declare as the output of the fragment shader ends up in the color buffer. If you’ve bound an FBO with multiple color buffers (i.e. multiple render targets), you’ll need to manually bind each of your
outvariables to the correct color buffer index viaglBindFragDataLocationIndexed.All the details you could ever want about both the GLSL (‘server’) side and the OpenGL (‘client’) side can be found :