Graphics Reference
In-Depth Information
returns the address of the named variable within the named program object,
so it can be used in the application. The uniform variable must be a simple
variable, not an array or struct; these are handled differently. A uniform vari-
able (either built-in or user-defined) is called active if the link operation finds
that it can be accessed during program execution; a link operation must have
been done (though it might not have succeeded) before the uniform variables
in the shader program can be active.
You can think of this as creating a pipe from your application to the
shader. The location you get from glGetUniformLocation( ) is the place the
pipe goes. You then use one of the glUniform*( ) functions to put data into
the pipe to get it to the shader.
The application can set the value of a uniform variable whose location is
known in three ways. The first way sets scalar or simple vector data with the
function
glUniform{i}{t}(GLint location, TYPE val)
where i can be 1, 2, 3, or 4, depending on the dimension of the variable, and
t can be either f or i , depending on whether the type's base is floating-point
or integer. The function causes the value of the parameter val to be loaded into
the location indicated. This parameter can be a simple vec1 , vec2 , vec3 , vec4 ,
ivec1 , ivec2 , ivec3 , or ivec4 , but not an array of these types.
The second way sets array (vector) data with
glUniform{i}{t}v( GLint location, GLuint length, const TYPE
*val )
where the meanings i and t are the same, but the data in val is a vector of the
specified type (including vec* and ivec* ) whose length is length .
Finally, the third way sets matrices, and is
glUniformMatrix{i}fv( GLint location, GLuint count,
GLboolean transpose, const GLfloat *val )
If i has the value 2, *val must be a 2 × 2 matrix; if 3, a 3 × 3 matrix; and if 4, a
4 × 4 matrix. If transpose has value GLfalse , the matrix is taken to be in stan-
dard OpenGL column matrix order, while if transpose has value GLtrue , the
matrix is taken to be in row-major order. The value of count is the number of
matrices that are being passed, so if you are only passing a single matrix, that
value is 1.
When you develop vertex shaders, it is sometimes nice to be able to
separate the Model and the Viewing matrices, instead of having them pre-
combined into one ModelView matrix, as OpenGL does. If you are willing
Search WWH ::




Custom Search