如何找到 OpenGL es 2.0 顶点着色器专业版中所有制服的列表

发布于 2024-10-14 04:01:20 字数 414 浏览 9 评论 0原文

我正在尝试学习如何对顶点着色器进行编程。在苹果的示例项目中,他们有一行来设置 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'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);

Then this value is used in

// 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2024-10-21 04:01:20

统一参数是传递给GL着色器的数据,在绘制调用期间不会改变。

您可以使用以下代码查询链接的 GLSL 程序以获取活动制服列表:

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 );
}

此代码检索许多活动制服并迭代它们,提取名称、类型、值的数量和制服位置。

Uniform parameter is a data passed to GL shader, which doesn't change during the draw call.

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.

写给空气的情书 2024-10-21 04:01:20

除了kvark的回答之外。您可以添加这些代码行来获得不错的结果
以及最常见制服的美观易读的格式:

std::cout << "Uniform Info Name: " << name << " Location: " << location << " Type: ";
        if (type == GL_FLOAT_MAT4)
            std::cout << "mat4";
        else if (type == GL_FLOAT_VEC3)
            std::cout << "vec3";
        else if (type == GL_FLOAT_VEC4)
            std::cout << "vec4";
        else if (type == GL_FLOAT)
            std::cout << "float";
        else if (type == GL_INT)
            std::cout << "int";
        else if (type == GL_BOOL)
            std::cout << "bool";
        else if (type == GL_SAMPLER_2D)
            std::cout << "sampler2d";
        else
            std::cout << type;

        std::cout << std::endl;  

In addition to kvark's answer. You can add these lines of code to get a nice
and beautiful readable format of the most common uniforms:

std::cout << "Uniform Info Name: " << name << " Location: " << location << " Type: ";
        if (type == GL_FLOAT_MAT4)
            std::cout << "mat4";
        else if (type == GL_FLOAT_VEC3)
            std::cout << "vec3";
        else if (type == GL_FLOAT_VEC4)
            std::cout << "vec4";
        else if (type == GL_FLOAT)
            std::cout << "float";
        else if (type == GL_INT)
            std::cout << "int";
        else if (type == GL_BOOL)
            std::cout << "bool";
        else if (type == GL_SAMPLER_2D)
            std::cout << "sampler2d";
        else
            std::cout << type;

        std::cout << std::endl;  
春夜浅 2024-10-21 04:01:20

我认为在该示例代码中,UNIFORM_TRANSLATE 被定义为 0,然后有这样的代码:

uniforms [UNIFORM_TRANSLATE] = glGetUniformLocation (programId, "position");

因此所有制服都按其名称检索 - 在本例中为“位置”。

I think in that example code, UNIFORM_TRANSLATE is defined to 0, and then there's code like this:

uniforms [UNIFORM_TRANSLATE] = glGetUniformLocation (programId, "position");

so all the uniforms are retrieved by their names -- "position" in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文