问题描述
我想要一份所有制服的清单 &着色器程序对象使用的属性.glGetAttribLocation()
&glGetUniformLocation()
可用于将字符串映射到位置,但我真正想要的是字符串列表,而无需解析 glsl 代码.
I'd like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation()
& glGetUniformLocation()
can be used to map a string to a location, but what I would really like is the list of strings without having to parse the glsl code.
注意:在 OpenGL 2.0 中 glGetObjectParameteriv()
被替换为 glGetProgramiv()
.枚举是 GL_ACTIVE_UNIFORMS
&GL_ACTIVE_ATTRIBUTES
.
Note: In OpenGL 2.0 glGetObjectParameteriv()
is replaced by glGetProgramiv()
. And the enum is GL_ACTIVE_UNIFORMS
& GL_ACTIVE_ATTRIBUTES
.
推荐答案
两个示例之间共享的变量:
GLint i;
GLint count;
GLint size; // size of the variable
GLenum type; // type of the variable (float, vec3 or mat4, etc)
const GLsizei bufSize = 16; // maximum name length
GLchar name[bufSize]; // variable name in GLSL
GLsizei length; // name length
属性
glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &count);
printf("Active Attributes: %d
", count);
for (i = 0; i < count; i++)
{
glGetActiveAttrib(program, (GLuint)i, bufSize, &length, &size, &type, name);
printf("Attribute #%d Type: %u Name: %s
", i, type, name);
}
制服
glGetProgramiv(program, GL_ACTIVE_UNIFORMS, &count);
printf("Active Uniforms: %d
", count);
for (i = 0; i < count; i++)
{
glGetActiveUniform(program, (GLuint)i, bufSize, &length, &size, &type, name);
printf("Uniform #%d Type: %u Name: %s
", i, type, name);
}
OpenGL 文档/变量类型
代表变量类型的各种宏可以在文档.如GL_FLOAT
、GL_FLOAT_VEC3
、GL_FLOAT_MAT4
等
这篇关于在 OpenGL 中有一种方法可以获取所有制服的列表 &着色器程序使用的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!