

|
GLSL - OpenGL Shading Language also known as GLslang is a high level shading language based on the C programming language. It was created by the OpenGL ARB for programming graphics processing units directly, thus giving developers control of the graphics pipeline at the lowest level.
Contents |
With the recent advancements in graphics cards, new features have been added to allow for increased flexibility in the rendering pipeline at the vertex and fragment level. Programmability at this level is achieved with the use of fragment and vertex shaders.
Originally, this functionality was achieved through the use of shaders written in assembly language. Assembly language is non-intuitive and rather complex for developers to use. The OpenGL ARB created the OpenGL Shading Language to provide a more intuitive method for programming the graphics processing unit while maintaining the open standards advantage that has driven OpenGL throughout its history.
Originally introduced as an extension to OpenGL 1.5, the OpenGL ARB formally included GLSL into the OpenGL 2.0 core. OpenGL 2.0 is the first major revision to OpenGL since the creation of OpenGL 1.0 in 1992.
Some benefits of using GLSL are:
The OpenGL Shading Language Specification defines twenty two basic data types, some are the same as used in the C programming language, while others are specific to graphics processing.
The OpenGL Shading Language provides many operators, familiar to those with a background in using the C programming language. This gives shader developers flexibility when writing shaders. GLSL contains the operators in C and C++, with the exception of bitwise operators and pointers.
Similar to the C programming language, GLSL supports loops and branching, including if, else, if/else, for, do-while, break, continue, etc.
User defined functions are supported, and a wide variety of commonly used functions are provided built-in as well. This allows the graphics card manufacturer the ability to optimize these built in functions at the hardware level if they are inclined to do so. Many of these functions are similar to those found in the C programming language such as exp() and abs() while others are specific to graphics programming such as smoothstep() and texture2D().
GLSL Shaders are not stand-alone applications; they require an application that utilizes the OpenGL API. C++, C and Java all support the OpenGL API and have support for the OpenGL Shading Language.
GLSL shaders themselves are simply a set of strings that are passed to the hardware vendor’s driver for compilation from within an application using the OpenGL API’s entry points. Shaders can be created on the fly from within an application or read in as text files, but must be sent to the driver in the form of a string.
void main(void)
{
gl_Position = ftransform();
}
void main(void)
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}