Portal:OpenGL Shading Language/Intro

From OpenGL.org
Jump to: navigation, search

The OpenGL Shading Language (GLSL) is a C-like language used to define programmable parts of the OpenGL Rendering Pipeline. The rendering pipeline defines a number of locations where programmable code can be inserted to do user-defined processing. These locations are called shader stages, and each one has its own unique elements and purposes.

All shaders are written in GLSL. In an OpenGL program, shader code is (usually) provided to OpenGL as a series of C strings. These strings are then compiled; OpenGL has a fairly complicated compilation model that allows the user many different choices for how to build their shaders. The code for one or more shader stages is compiled and linked into a special object called a program object. Any errors produced during this process are available for the user to detect and respond to. And you should.

Shaders have a number of interfaces to external code. These represent settings that previous or later stages of the rendering pipeline attach themselves to, or hooks for the user to insert user-defined data. GLSL has an extensive querying API to iterate through all of the user-visible interfaces between a linked program and the user.

Shader stages have similar capabilities, for the most part. Some shader stages are clearly defined for various purposes, but they have roughly equivalent functionality. Each shader stage has its quirks and its required behavior from the user-specified code.