OpenGL Shading Language

From Wikipedia, the free encyclopedia
  (Redirected from GLSL)
Jump to: navigation, search
Video games outsource rendering calculations to the GPU over OpenGL in real-time. Shaders are written in OpenGL Shading Language and compiled. The compiled programs are executed on the GPU.

OpenGL Shading Language (abbreviated: GLSL or GLslang), is a high-level shading language based on the syntax of the C programming language. It was created by the OpenGL ARB (OpenGL Architecture Review Board) to give developers more direct control of the graphics pipeline without having to use ARB assembly language or hardware-specific languages.

Background[edit]

With advances 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 by writing shaders in ARB assembly language – a complex and unintuitive task. 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.4, GLSL was formally included into the OpenGL 2.0 core by the OpenGL ARB. It was the first major revision to OpenGL since the creation of OpenGL 1.0 in 1992.

Some benefits of using GLSL are:

  • Cross-platform compatibility on multiple operating systems, including GNU/Linux, Mac OS X and Windows.
  • The ability to write shaders that can be used on any hardware vendor's graphics card that supports the OpenGL Shading Language.
  • Each hardware vendor includes the GLSL compiler in their driver, thus allowing each vendor to create code optimized for their particular graphics card’s architecture.

Versions[edit]

GLSL versions have evolved alongside specific versions of the OpenGL API. It is only with OpenGL versions 3.3 and above that the GLSL and OpenGL major and minor version numbers match. These versions for GLSL and OpenGL are related in the following table:

GLSL Version OpenGL Version Date Shader Preprocessor
1.10.59[1] 2.0 April 2004 #version 110
1.20.8[2] 2.1 September 2006 #version 120
1.30.10[3] 3.0 August 2008 #version 130
1.40.08[4] 3.1 March 2009 #version 140
1.50.11[5] 3.2 August 2009 #version 150
3.30.6[6] 3.3 February 2010 #version 330
4.00.9[7] 4.0 March 2010 #version 400
4.10.6[8] 4.1 July 2010 #version 410
4.20.11[9] 4.2 August 2011 #version 420
4.30.8[10] 4.3 August 2012 #version 430
4.40[11] 4.4 July 2013 #version 440
4.50[12] 4.5 August 2014 #version 450

Operators[edit]

GLSL contains the operators in C and C++, with the exception of pointers. Bitwise operators were added in version 1.30.

Functions and control structures[edit]

Similar to the C programming language, GLSL supports loops and branching, for instance: if-else, for, switch, etc. Recursion is forbidden.

User-defined functions are supported and built-in functions are provided. The graphics card manufacturer may optimize built-in functions at the hardware level. Many of these functions are similar to those in the math library of the C programming language while others are specific to graphics programming.

Compilation and execution[edit]

GLSL shaders are not stand-alone applications; they require an application that utilizes the OpenGL API, which is available on many different platforms (e.g., GNU/Linux, Mac OS X, Windows). There are language bindings for C, C++, C#, Delphi, Java and many more.

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.

The set of APIs used to compile, link, and pass parameters to GLSL programs are specified in three OpenGL extensions, and became part of core OpenGL as of OpenGL Version 2.0. The API was expanded with geometry shaders in OpenGL 3.2, tessellation shaders in OpenGL 4.0 and compute shaders in OpenGL 4.3. These OpenGL APIs are found in the extensions:

See also[edit]

Other shading languages[edit]

  • ARB assembly language, a low-level shading language
  • Cg, a high-level shading language for programming vertex and pixel shaders
  • HLSL, a high-level shading language for use with Direct3D
  • TGSI, a low-level intermediate language introduced by Gallium3D
  • AMDIL, a low-level intermediate language used internally at AMD

References[edit]

Notes

Books[edit]

  • Rost, Randi J. (30 July 2009). OpenGL Shading Language (3rd ed.). Addison-Wesley. ISBN 978-0-321-63763-5. 
  • Kessenich, John; Baldwin, David; Rost, Randi. The OpenGL Shading Language. Version 1.10.59. 3Dlabs, Inc. Ltd. 

External links[edit]

IDE[edit]