2

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.

KTC
  • 420
  • 5
  • 15

1 Answers1

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.

Community
  • 1
  • 1
Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • That did it! But I still wonder why I couldn't figure that out by just Googling "gl_VerticesIn" or something. – KTC Dec 22 '13 at 04:33
  • 3
    @KTC: Google's not always the best way to find answers to OpenGL questions. http://www.opengl.org/registry/ has the formal specifications for every version of OpenGL ever released. If you look at the [GLSL 3.30 spec.](http://www.opengl.org/registry/doc/GLSLangSpec.3.30.6.clean.pdf), on pg. 36 it has a plethora of useful information on the subject in a much more authoritative format than Google would give you. – Andon M. Coleman Dec 22 '13 at 04:49