5. The GLSL Shader Language
GLSL omits some of the capabilities
of C, and some areas where GLSL
has language features that remind
us of the best of earlier generations
of computer languages. This chap-
ter focuses on these dierences and
discusses why they are needed for
the shader environment. There is a
tendency for any discussion like this
to have a strong avor of a language
manual, and you might nd that
you use this chapter more as a refer-
ence than as general reading.
We introduced a number
of GLSL language features in
Chapter 3, but here we take a more thorough approach to the language and
describe it more formally. We are working from the GLSL language specica-
tion  and include those features and capabilities that we believe are most
useful to you, but we are not absolutely complete in our coverage. Once you
are familiar with a good working set of GLSL, you probably should read the
GLSL specication to see what else is there—especially since the language will
continue to evolve over time.
We are indebted to the GLSL Shader Language Specication document
both for the overall information it contains and for its excellent tables of GLSL
functions and operations that we have borrowed from extensively.
Factors that Shape Shader Languages
Shader languages operate in a dierent environment and with dierent goals
than general-purpose languages. Their environment is the processing capabil-
ity of graphics cards, which diers in some important ways from the capability
of a general CPU, and their goals are tightly focused on supporting graphics
operations, rather than more general kinds of computations. These capabilities
shape the language in signicant ways, and it is important that you under-
stand their impacts as you write shaders.
GLSL shader capabilities are very much
a moving target. This chapter and all
our examples are based on GLSL 4.1.
However, we also include many features
that are deprecated in that standard but are
available in compatibility mode, because
they may be helpful to someone learning to
work with shaders for the first time.
In order to keep current on GLSL,
you should consult  from time to time.
You will not need a new copy of glman,
however, because OpenGL will compile
only the GLSL shaders, but you may need
to get a new OpenGL driver.
1. Good resources: “OpenGL.” Khronos. Available at hp://www.khronos.org/opengl/.
“OpenGL 4.2 API Quick Reference Card.” Khronos. Available at hp://www.khronos.org/les/
“OpenGL Shading Language.” OpenGL. Available at hp://www.opengl.org/documentation/glsl/,