Graphics Reference
In-Depth Information
must use memory on the graphics card, so the application and its shaders must
create names for variables in on-card memory. Sharing these names between
shaders that are linked into a single shader program then creates the between-
shader communication that shaders need. The set of names of variables used
by a set of shaders is called a shared namespace .
A namespace may hold atribute variables , created by the appliction to
define per-vertex data and available only to the vertex shader as in variables;
uniform variables , created by the application to be used as read-only variables
by any shader; and shader-defined variables , created as out variables to pass on
as in variables to later shaders. (The concept of out and in variables is dis-
cussed later in this chapter.) Some variables created in vertex-processing shad-
ers are intended to be used by fragment shaders by being interpolated across
a fragment as a geometric primitive is processed.
You can deine atribute variables in your application through the
OpenGL API function glVertexAttrib*( ) and make them accessible to the
vertex shader. This lets you define per-vertex data that can be used to define
colors or other properties of vertices. You can also define uniform variables to
communicate from your OpenGL application to vertex or fragment shaders.
Because of limitations on the memory on the graphics card, there is a limit
to the total amount of uniform data available to you. Defining and accessing
user-deined atribute and uniform variables will be discussed when we pres-
ent the GLSL API in Chapter 14.
The types and initializers of variables with the same name must match
across all shaders that are linked into a single executable. It is legal for some
shaders to provide an initializer for a particular variable, while other shaders
do not, but all provided initializers must be equal. This is checked as the pro-
gram is linked.
There are a few specific variables that GLSL uses for very specific capa-
bilities; these may be seen as basic parts of the namespace for one or more
kinds of shader. These are described in the chapters on the different shaders.
Extended Function and Operator Capabilities
GLSL extends some of the operators and functions of C to act on vectors and
matrices. The standard scalar arithmetic operators are extended to vectors by
applying the original operation componentwise. The additive operators are
also extended to componentwise operations on matrices, but the multiply
operator is taken to mean the standard linear algebra matrix multiplication.
Many familiar functions on scalars are similarly extended to vectors by acting
componentwise.
Search WWH ::




Custom Search