Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: gl_VertexID always zero in any useful geometry shader

  1. #1
    Newbie Newbie
    Join Date
    Oct 2016

    gl_VertexID always zero in any useful geometry shader

    I am using indexed rendering and a geometry shader. If I pass gl_VertexID to the geometry shader, it works fine as long as I do not emit any vertices; if I emit one or more vertices, gl_VertexID (passed as any name) is zero. Can anyone tell me why?

    Using the shaders below, the geometry shader will put the correct indices into my feedback buffer, if and only if I comment out both EmitVertex calls. What am I missing?

    (I can work around it, but it is bugging the hell out of me!)

    Code :
    #version 440
    in vec4 position;
    out VSOUT{
      vec4 gl_Position;
      int index;
    } vsout;
    uniform mat4 gl_ModelViewMatrix;
    void main(){
        gl_Position = gl_ModelViewMatrix * position;
        vsout.index = gl_VertexID;
        vsout.gl_Position = gl_Position;

    Code :
    #version 440
    #extension GL_ARB_shader_storage_buffer_object : enable
    layout (lines) in;
    layout (line_strip) out;
    in VSOUT{
       vec4 gl_Position;
      int index;
    } vdata[];
    layout (std430, binding=0) buffer FeedbackBuffer{
        vec2 fb[];
    void main(){
      int i = vdata[0].index;
      int j = vdata[1].index;
      fb[gl_PrimitiveIDIn][0] = vdata[0].index;
      fb[gl_PrimitiveIDIn][1] = vdata[1].index;
      gl_Position = gl_in[0].gl_Position;
      gl_Position = gl_in[1].gl_Position;

    Code :
    #version 440
    out vec4 outputColor;
    void main(){
        outputColor = vec4(.5,.5,.5,.5);

    So this looks like an nVidia implementation thing. If I run these shaders on a GeForce GTX580, behaviour is as described above. Using an AMD FirePro V5900, it behaves as I'd expect, with the correct values in the feedback buffer whether or not I emit vertices.
    Last edited by mickelharpa; 10-27-2016 at 03:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts