The OpenGL Shading Language (GLSL) allows writing custom programs for vertex and fragment processors
The custom GLSL programs thereby replace parts of the OpenGL pipeline that were previously performed by the fixed-function pipeline
The per-vertex-operations are partially replaced by a vertex shader and the per-pixel-operations by a fragment shader
Reiteration: OpenGL Pipeline
Fragment Shader
Parallel Processing
In the vertex and fragment shaders the data is processed in parallel
Today’s GPUs have up to 10000 processing units that can perform parallel calculations on the data
For all data exactly the same shader code is executed in parallel (“Stream Processing”)
The parallel processing is possible because the operations have a defined goal (either a transformed vertex or fragment), which can be written without conflicts
Creation of the Shaders Program in OpenGL
The shader programs are compiled at runtime and passed to the graphics card
To create a shader program that may contain vertex and fragment shaders, the following command is used
progID = glCreateProgram();
Creating, assigning, and compiling of shader code for a vertex and fragment shader is done with:
To activate a shader program the following command is used
glUseProgram(progID);
In this case, OpenGL behaves again as a state-machine, i.e., all subsequent rendering function are using the currently active shader program
This also means that swapping between different shader program at runtime is possible (and often occurs in practice). For example, different shaders are used to simulate different materials
댓글