Frage

Why do I get this error compiling a GLSL geometry shader?

ERROR: 0:15: 'gl_VerticesIn' : undeclared identifier

Here's the shader:

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

Seems straightforward to me, but I can't find much information on "gl_VerticesIn", which I thought was supposed to be a built-in. If I just replace "gl_VerticesIn" with "3", everything works.

I'm using a GeForce GTX 765M and OpenGL 3.3 core profile. I don't have this error using any other GPU. My drivers are up to date.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top