Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Shading Language Different Types of Variable (Qualifiers)

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:

  1. What are different types of variable (qualifiers) in GLSL?
  2. What are they used for?
  3. 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.

like image 915
Einiosaurus Avatar asked Jun 01 '11 03:06

Einiosaurus


People also ask

Which of the following storage qualifiers are available with OpenGL shading language?

There are three precision qualifiers: highp, mediump, and lowp.

What shading language does OpenGL use?

The OpenGL Shading Language (GLSL) is the principal shading language for OpenGL. While, thanks to OpenGL Extensions, there are several shading languages available for use in OpenGL, GLSL (and SPIR-V) are supported directly by OpenGL without extensions. GLSL is a C-style language.

What is the difference between OpenGL and GLSL?

The short version is: OpenGL is an API for rendering graphics, while GLSL (which stands for GL shading language) is a language that gives programmers the ability to modify pipeline shaders. To put it another way, GLSL is a (small) part of the overall OpenGL framework.


1 Answers

In OpenGL 3+ :

  • varying is deprecated
  • const is for... well, constants !
  • uniform is for per draw call (at most) values
  • in is for input from the previous pipeline stage, i.e. per vertex (or per fragment) values at most, per primitive if using glAttribDivisor and hardware instanciation
  • out is for output to the next stage

Regarding 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 of gl_FragDepth) are deprecated and should be replaced with user-defined out variables.

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 out variables to the correct color buffer index via glBindFragDataLocationIndexed.

All the details you could ever want about both the GLSL ('server') side and the OpenGL ('client') side can be found :

  • in the OpenGL specification, specifically pages 248-250 for color buffer output on fragment shaders.
  • in the GLSL specs, page 38 and on for shader outputs.
like image 185
Nicolas Lefebvre Avatar answered Sep 27 '22 17:09

Nicolas Lefebvre