Graphics Reference
In-Depth Information
General GLSL Language Concepts
GLSL is designed to be similar to C and maintains many of the familiar con-
ventions of that language. The overall syntax is the same, with the same con-
ventions for literals and identifiers, and the same preprocessor capabilities.
You have have the full set of integer and unsigned integer operations, most
of the same operators, and the same operator precedence. The looping and
conditional structures are the same, including the switch statement. Overall,
if you know C, you will find the basic nature of GLSL to be quite comfortable.
However, there are differences between GLSL and C that are driven by
the differences in the special environment and the goals of the language, rather
than by limitations of C. There are five fundamental ways in which GLSL dif-
fers from most conventional languages:
1. The range of conventional operators and functions is extended beyond
those usually found in C or similar languages.
2. The language contains some capabilities, such as name sets and shared
data namespaces that are implicit in the language, rather than explicitly
specified.
3. Data passing between shaders is handled by specifically declaring which
variables are input and which are output, and some variables must be
explicitly passed along from a shader to subsequent shaders.
4. Function parameters are passed by value-return, rather than by value
alone.
5. Some general-purpose language capabilities are omited.
In GLSL, some conventional operators and functions have extended capa-
bilities, and some new functions and operations are introduced that are con-
venient for graphics. GLSL has two new implicit capabilities that come from
extending the variable types to include types that carry specific capabilities
and from using a shared namespace to communicate between shaders. The
GLSL function parameters and omited capabilities from C come from changes
in the processing environment. All these differences are described fully later in
this chapter, but are briefly discussed in the sections below.
Shared Namespace
Shaders operate independently of each other, so an application can use any
shader independently of any other. In order for shaders to communicate, they
Search WWH ::




Custom Search