2

为什么在编译 GLSL 几何着色器时会出现此错误?

错误:0:15:'gl_VerticesIn':未声明的标识符

这是着色器:

// makes wireframe triangles.


#version 330
#extension GL_ARB_geometry_shader4 : enable


layout(triangles) in;
layout(line_strip, max_vertices = 4) out;


void main(void)
{
    for (int i = 0; i < gl_VerticesIn; i++)
    {
        gl_Position = gl_in[i].gl_Position;
        EmitVertex();
    }

    gl_Position = gl_in[0].gl_Position;
    EmitVertex();

    EndPrimitive();
}

对我来说似乎很简单,但我找不到关于“gl_VerticesIn”的太多信息,我认为它应该是内置的。如果我只是用“3”替换“gl_VerticesIn”,一切正常。

我正在使用 GeForce GTX 765M 和 OpenGL 3.3 核心配置文件。我使用任何其他 GPU 时都没有此错误。我的驱动程序是最新的。

4

1 回答 1

8

First things first, gl_VerticesIn is only declared in GL_ARB_geometry_shader4 and geometry shaders are core in GLSL 3.30. There is no reason to even use the extension form of geometry shaders given your shader version, you are only making the GLSL compiler and linker's job more confusing by doing this.

Now, to actually solve your problem:

    Rather than using gl_VerticesIn, use gl_in.length (). It is really that simple.  

And of course, it would also be a good idea to remove the redundant extension directive.

于 2013-12-22T04:14:46.240 回答