Portal:OpenGL Shading Language/Core Language: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
Language intro.
 
Slightly shorter.
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
The '''Core Language''' of GLSL is grammatically very similar to C, with some elements from C++. It contains the same looping and conditional keywords as C/C++. Variables are declared in a fashion very similarly to C/C++, though GLSL has many more qualifiers and built-in types than those languages.
The '''Core Language''' of GLSL is grammatically very similar to C, with some elements from C++. It contains the same looping and conditional keywords as C/C++.


One big difference is that GLSL shaders must start with a [[Core_Language_%28GLSL%29#Version|version declaration]], which tells the compiler what version of the language to compile the rest. A shader that does not begin with a version declaration will be assumed to be the (very ancient) version 1.10.
One big difference is that GLSL shaders must start with a [[Core_Language_%28GLSL%29#Version|version declaration]], which tells the compiler what version of the language to compile the rest. A shader that does not begin with a version declaration will be assumed to be the (very ancient) version 1.10.


Another large difference between C/C++ and GLSL is how [[Core_Language_%28GLSL%29Functions|functions]] work. The general syntax is similar, but the parameter passing conventions are quite different, allowing functions to have dedicated output parameters without pointers. A more difficult issue is that GLSL does not support ''recursion'' at all; a function must never call itself or call another function that calls itself.
Another large difference between C/C++ and GLSL is how [[Core_Language_%28GLSL%29#Functions|functions]] work. The general syntax is similar, but the parameter passing conventions are quite different, allowing functions to have dedicated output parameters without pointers. A more difficult issue is that GLSL does not support ''recursion'' at all; a function must never call itself or call another function that calls itself.

Latest revision as of 04:31, 25 July 2013

The Core Language of GLSL is grammatically very similar to C, with some elements from C++. It contains the same looping and conditional keywords as C/C++.

One big difference is that GLSL shaders must start with a version declaration, which tells the compiler what version of the language to compile the rest. A shader that does not begin with a version declaration will be assumed to be the (very ancient) version 1.10.

Another large difference between C/C++ and GLSL is how functions work. The general syntax is similar, but the parameter passing conventions are quite different, allowing functions to have dedicated output parameters without pointers. A more difficult issue is that GLSL does not support recursion at all; a function must never call itself or call another function that calls itself.