如何在 OpenGL es 2.0 vertex shader pro 中找到所有制服的列表 [英] How can I find a list of all the uniforms in OpenGL es 2.0 vertex shader pro
问题描述
我正在尝试学习如何编写顶点着色器.在 Apple 的示例项目中,他们有一行设置
I'm trying to learn how to program vertex shaders. In Apple's sample project they have a line to set a
glUniform1f(uniforms[UNIFORM_TRANSLATE], (Glfloat)transY);
然后在
// value passt in f
// glUniform1f(uniforms[UNIFORM_TRANSLATE](Glfloat)transY);
uniform float translate;
void main()
{
gl_Position.y+=sin( translate);
…
我无法找到所有制服的所有制服列表.
I was unable to find a list of all uniforms of all the uniforms.
有谁知道我在哪里可以找到所有制服的列表和一本关于学习如何编写顶点着色器的好书或教程.
Does any one know where I can find a list of all the uniforms and a good book or tutorial on learning how to program vertex shaders.
推荐答案
统一参数是传递给 GL 着色器的数据,在绘制调用期间不会改变.
Uniform parameter is a data passed to GL shader, which doesn't change during the draw call.
您可以使用以下代码查询链接的 GLSL 程序以获取活动制服列表:
You can query a linked GLSL program for a list of active uniforms with the following code:
int total = -1;
glGetProgramiv( program_id, GL_ACTIVE_UNIFORMS, &total );
for(int i=0; i<total; ++i) {
int name_len=-1, num=-1;
GLenum type = GL_ZERO;
char name[100];
glGetActiveUniform( program_id, GLuint(i), sizeof(name)-1,
&name_len, &num, &type, name );
name[name_len] = 0;
GLuint location = glGetUniformLocation( program_id, name );
}
此代码检索许多活动的制服并对其进行迭代,提取名称、类型、值的数量和制服的位置.
This code retrieves a number of active uniforms and iterates though them, extracting name, type, number of values and uniform locations.
这篇关于如何在 OpenGL es 2.0 vertex shader pro 中找到所有制服的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!