Graphics Reference
In-Depth Information
But how does the application get the address for a variable it does not
know about? The application must know the name of the uniform variable
in a linked shader program. It can then get the location (or address) with the
function
GLint glGetUniformLocation(GLuint program, const GLchar *name);
Here program is the value returned from the glCreateProgram( ) func-
tion, and name is the name (a text string) of the uniform variable. This function
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 conduit from your application to the
shader. The location you get from glGetUniformLocation( ) is the place the
conduit gets plugged into. You then use one of the glProgramUniform*( )
functions to put data into the conduit 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
glProgramUniform{i}{t}(GLuint program, 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
glProgramUniform{i}{t}v(GLuint program, 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
glProgramUniformMatrix{i}fv( GLuint program, GLint location,
GLuint count, GLboolean transpose, const GLfloat *val )
Search WWH ::




Custom Search