Portal:OpenGL Shading Language/Intro

From OpenGL Wiki
< Portal:OpenGL Shading Language
Revision as of 15:10, 16 September 2017 by Alfonse (talk | contribs) (SPIR-V notation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to 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.

Shaders are written in GLSL (or with OpenGL 4.6 or ARB_gl_spirv, SPIR-V) In an OpenGL program, GLSL 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.