Portal:OpenGL Shading Language/Core Language

From OpenGL Wiki
Jump to navigation Jump to search

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.