query uniform

The block of code in Example 4-3 demonstrates how one would go about
querying for uniform information on a program object using the functions
we have described.
Example 4-3 Querying for Active Uniforms
GLint maxUniformLen;
GLint numUniforms;
char *uniformName;
GLint index;
glGetProgramiv(progObj, GL_ACTIVE_UNIFORMS, &numUniforms);
glGetProgramiv(progObj, GL_ACTIVE_UNIFORM_MAX_LENGTH,
&maxUniformLen);
uniformName = malloc(sizeof(char) * maxUniformLen);
for(index = 0; index < numUniforms; index++)
{
GLint size;
GLenum type;
GLint location;
// Get the Uniform Info
glGetActiveUniform(progObj, index, maxUniformLen, NULL,
&size, &type, uniformName);
// Get the uniform location
location = glGetUniformLocation(progObj, uniformName);
switch(type)
{
case GL_FLOAT:
// ...
break;
case GL_FLOAT_VEC2:
// ...

break;

case GL_FLOAT_VEC3:
// ...
break;
case GL_FLOAT_VEC4:
// ...
break;
case GL_INT:
// ...
break;
// ... Check for all the types ...
default:
// Unknown type
break;
}
}



void glUniform1f(GLint location, GLfloat x)
void glUniform1fv(GLint location, GLsizei count,
const GLfloat* v)
void glUniform1i(GLint location, GLint x)
void glUniform1iv(GLint location, GLsizei count,
const GLint* v)
void glUniform2f(GLint location, GLfloat x, GLfloat y)
void glUniform2fv(GLint location, GLsizei count,
const GLfloat* v)
void glUniform2i(GLint location, GLint x, GLint y)
void glUniform2iv(GLint location, GLsizei count,
const GLint* v)
void glUniform3f(GLint location, GLfloat x, GLfloat y,
GLfloat z)
void glUniform3fv(GLint location, GLsizei count,
const GLfloat* v)
void glUniform3i(GLint location, GLint x, GLint y,
GLint z)

void glUniform3iv(GLint location, GLsizei count,

const GLint* v)
void glUniform4f(GLint location, GLfloat x, GLfloat y,
GLfloat z, GLfloat w);
void glUniform4fv(GLint location, GLsizei count,
const GLfloat* v)
void glUniform4i(GLint location, GLint x, GLint y,
GLint z, GLint w)
void glUniform4iv(GLint location, GLsizei count,
const GLint* v)
void glUniformMatrix2fv(GLint location, GLsizei count,
GLboolean transpose,
const GLfloat* value)
void glUniformMatrix3fv(GLint location, GLsizei count,
GLboolean transpose,
const GLfloat* value)
void glUniformMatrix4fv(GLint location, GLsizei count,
GLboolean transpose,
const GLfloat* value)
location the location of the uniform to load with a value
count for the functions that take a pointer value, there is also a
count. The count specifies the number of array elements to
load from the pointer. For single element uniforms, this
value will always be 1. For arrays, it should be the size
returned by glGetActiveUniform
transpose the transpose argument for the matrix variants of these
functions MUST BE FALSE in OpenGL ES 2.0. This argument
was kept for function interface compatibility with desktop
OpenGL, but does not function in OpenGL ES 2.0

void glGetActiveUniform(GLuint program, GLuint index,
GLsizei bufSize, GLsizei* length,
GLint* size, GLenum* type,
char* name)
program handle to the program object
index the uniform index to be queried
bufSize the number of characters in the name array
length if not NULL, will be written with the number of characters
written into the name array (less the null terminator)
size if the uniform variable being queried is an array, this variable
will be written with the maximum array element used in the
program (plus 1). If the uniform variable being queried is not
an array, this value will be 1
type will be written with the uniform type, can be:
GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4,
GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4, GL_BOOL,
GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4,
GL_FLOAT_MAT2, GL_FLOAT_MAT3, GL_FLOAT_MAT4,
GL_SAMPLER_2D, GL_SAMPLER_CUBE

name will be written with the name of the uniform up to bufSize
number of characters. This will be a null terminated string

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章