Graphics Reference
In-Depth Information
not deleted until after it has been detached. But it is probably much beter to
be systematic in removing program and shader objects, both to make your
code easier to understand, and to avoid instances where the system might not
adequately protect you.
Passing Data into Shaders
As you write any program with the OpenGL API, even if you don't intend
that program to use GLSL shaders, you create data that the system will use in
creating a scene. This is generally graphical data that describes the scene. For
example, you can specify the color for each vertex, or you can create an array
of vertices and a parallel array with data such as elevations, temperature, or
any measured data. The data could be used in fixed-function operations by
manipulating primitives based on your data, or with shader-based operations
by puting the data into user-deined atribute or uniform data that you can
access within the shader function(s). In these sections, we describe how you
can create atribute, uniform, or sampler data for shaders, and we give some
examples that show these in action.
Defining Uniform Variables in Your Application
GLSL uniform variables contain information that can change at most with
each graphics primitive. You can think of these uniform variables as a sort of
“global variables” that are available to all the shaders currently being used.
If you want a shader to have data and that data isn't directly available from
OpenGL, you can define your own uniform variables to give that data to a
shader. Uniform variables are defined within a shader, and their values are
set by the application. Uniform variables can hold any kind of data, including
structs and arrays, as we saw with the built-in uniform variables.
The mechanism for defining and using your own uniform variables is
indirect and somewhat unusual. When you define a uniform variable in your
shader program, you simply declare the variable in the usual way:
uniform type name;
This associates a name and a type with the variable, but does not asso-
ciate an address. An address is only assigned when the shader program is
linked. Once linking has been done, an address is available for each variable.
You query the address and then use it to set the variable from your application.
Search WWH ::




Custom Search