0

I am setting the following pipeline:

Vertex shader gets as input 4 vertices to draw as full screen quad with triangle strip :

Vertex Shader:

#version 420 core
layout(location = 0)  in vec4 position;
out gl_PerVertex 
{
vec4 gl_Position;

}
;
void main()
{
   gl_Position =  position; 
}

Then I want to do some work on them in geometry shader .But for now I just try to emit the same vertices as triangle strip from the shader just to make sure it work ok.

Geom Shader

#version 420 core

layout(invocations = 1,triangles) in; 
layout(triangle_strip, max_vertices =4) out;


out gl_PerVertex
{

  vec4 gl_Position;

};
void main() 
{

gl_Position = vec4( 1.0, 1.0, 0.0, 1.0 );

EmitVertex();

gl_Position = vec4(-1.0, 1.0, 0.0, 1.0 );

EmitVertex();

gl_Position = vec4( 1.0,-1.0, 0.0, 1.0 );

EmitVertex();

gl_Position = vec4(-1.0,-1.0, 0.0, 1.0 );

EmitVertex();

EndPrimitive(); 

}

And the fragment shader:

 #version 420 core

 layout(binding=0) uniform sampler2D   COLOR_MAP_0;

 out vec4 OUTPUT;

 void main(void) {

  OUTPUT =  vec4(1,0,0,1); 


 }

The client side setup is like this:

    glm::vec4 va[4] ={glm::vec4(1.0, 1.0, 0.0, 1.0),glm::vec4(-1.0, 1.0, 0.0, 1.0),glm::vec4(  1.0,-1.0, 0.0, 1.0),glm::vec4(-1.0,-1.0, 0.0, 1.0)};
        auto ss = sizeof(va); 
    glGenVertexArrays(1,&_dummyVao);
    glBindVertexArray(_dummyVao);
    glGenBuffers(1,&_dummyPoinBuff);
    glBindBuffer(GL_ARRAY_BUFFER, _dummyPoinBuff);
    glBufferData(GL_ARRAY_BUFFER,  ss, &va[0], GL_STATIC_DRAW);
    glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, ((GLubyte *)NULL + (0)));
    glEnableVertexAttribArray(0);
    glBindVertexArray(0);

The draw call:

glBindVertexArray(_dummyVao);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);

The weird thing is that it doesn't work!The output is empty.If I switch to emit points instead ,it does emit them.The vertex data is 100% correct.it draws the quad ok if I detach the geometry shader.What can be possibly wrong here?

UPDATE:

This variation does work.

 const vec2 vert_data[4] = vec2[](
           vec2(-1.0, 1.0), 
           vec2(-1.0, -1.0), 
           vec2(1.0, 1.0), 
           vec2(1.0, -1.0) 
         );


for(int i=0; i<4; i++)
  {
gl_Position = vec4( vert_data[i].xy,0,1);///gl_Position;
EmitVertex();
  }
  EndPrimitive();

Redclare of inputs / outputs in geometry shader still didn't help:

in gl_PerVertex
{
  vec4 gl_Position;

} gl_in[];
out gl_PerVertex
{
  vec4 gl_Position;

};
Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Michael IV
  • 11,016
  • 12
  • 92
  • 223
  • the frag shader doesn't actually use any input from the geom shader, also you shouldn't declare the built-ins yourself – ratchet freak Jan 28 '14 at 12:35
  • I do have to use built-ins as I work with separate shader objects.What do I have to pass to fragment? – Michael IV Jan 28 '14 at 12:52
  • The Geometry shader should have `in gl_PerVertex { vec4 gl_Position; } gl_in [];` if you want to re-declare the built-in. – Andon M. Coleman Jan 28 '14 at 13:22
  • I did,still doesn't work.See my update. – Michael IV Jan 28 '14 at 13:25
  • @MichaelIV: I was responding to Ratchet Freak. That is not going to help in your situation since you are not using anything output from the vertex shader. Regarding the use of outputs from the geometry shader, that is plain wrong - the fragment shader implicitly uses `gl_Position` when the rasterizer generates `gl_FragCoord`. – Andon M. Coleman Jan 28 '14 at 14:12
  • I do have to wonder why you are declaring constant vertex positions in the geometry shader though? That seems rather useless. – Andon M. Coleman Jan 28 '14 at 14:16
  • First, if I don't redefine outputs in geometry shader it won't compile. Second, see my original geometry shader. I didn't use const vertex array. But once I tried it ( see my update at the bottom) it started working. To me looks like huge driver bug. – Michael IV Jan 28 '14 at 14:46
  • First, I was not talking about *your* declaration of `gl_PerVertex`. I was talking about Ratchet Freak's comment again (where he says that the GS output is not used by the FS). Second, both shaders use constant vertex positions. In the sense that the positions are pre-determined, they do not have anything to do with the vertex shader input. Whether it is an array or not makes no difference. I would not be surprised if it is a driver bug, because nobody does this sort of thing - geometry shaders that emit constant vertex positions serve no real purpose. Things that nobody uses go untested. – Andon M. Coleman Jan 28 '14 at 14:54
  • Well, I was doing it in order create geometry shader only full screen quad. Actually I found working example here on SO but it was GLSL 330. Maybe something changed since then? Also if what you say regarding hardcoded vertex position was right then why using for () loop does work? – Michael IV Jan 28 '14 at 15:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/46250/discussion-between-michael-iv-and-andon-m-coleman) – Michael IV Jan 28 '14 at 15:27

0 Answers0