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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值