Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am dealing with geometry shaders using GL_ARB_geometry_shader4 extension.

My code goes like :

GLfloat vertices[] =
    {   
        0.5,0.25,1.0,
        0.5,0.75,1.0,
        -0.5,0.75,1.0,
        -0.5,0.25,1.0,
        0.6,0.35,1.0,
        0.6,0.85,1.0,
        -0.6,0.85,1.0,
        -0.6,0.35,1.0
    };

glProgramParameteriEXT(psId, GL_GEOMETRY_INPUT_TYPE_EXT, GL_TRIANGLES);

glProgramParameteriEXT(psId, GL_GEOMETRY_OUTPUT_TYPE_EXT, GL_TRIANGLE_STRIP);

glLinkProgram(psId);

glBindAttribLocation(psId,0,"Position");

glEnableVertexAttribArray (0);

glVertexAttribPointer(0, 3, GL_FLOAT, 0, 0, vertices);

glDrawArrays(GL_TRIANGLE_STRIP,0,4);

My vertex shader is :

#version 150

in vec3 Position;

void main()
{       
    gl_Position = vec4(Position,1.0);

}

Geometry shader is :

#version 150
#extension GL_EXT_geometry_shader4 : enable

in vec4 pos[3];

void main()
{
   int i;
   vec4 vertex;

    gl_Position = pos[0];
    EmitVertex();

    gl_Position = pos[1];
    EmitVertex();

    gl_Position = pos[2];
    EmitVertex();

    gl_Position = pos[0] + vec4(0.3,0.0,0.0,0.0);
    EmitVertex();

    EndPrimitive();
}

Nothing is rendered with this code. What exactly should be the mode in glDrawArrays() ? How does the GL_GEOMETRY_OUTPUT_TYPE_EXT parameter will affect glDrawArrays() ?

What I expect is 3 vertices will be passed on to Geometry Shader and using those we construct a primitive of size 4 (assuming GL_TRIANGLE_STRIP requires 4 vertices). Can somebody please throw some light on this ?

share|improve this question
3  
You tagged this post openGL ES but openGL ES does not support geometry shaders. –  Thelvyn Dec 19 '12 at 12:37
1  
@Thelvyn: My bad. Wont happen next time. –  maverick9888 Dec 20 '12 at 8:16
    
Is there a reason you're using the old EXT extension instead of the GL 3.2 core functionality? I mean, you're already using GLSL 1.50; geometry shaders are a core feature for you. And they don't work like that. –  Nicol Bolas Jan 8 '13 at 12:55

1 Answer 1

Your vec4 pos[3] variable in your geometry shader doesn't appear to be getting set, unless you didn't post the code for that. If it's being initialized to zero and never set, that could be why nothing shows up. If you want the geometry shader to get the positions output from the vertex shader, you need to use the built-in variable gl_PositionIn[] for that.

The input to glDrawArrays and similar must match the input primitive type of the geometry shader. Since you've written a geometry shader that works on triangles, you can use a triangle list, strip or fan in glDrawArrays. Each triangle generated by the draw call is sent to the geometry shader and processed separately, after being vertex-shaded.

So the way you have it now, you're drawing a triangle strip of 4 vertices, which creates 2 triangles; each of these is then passed to the geometry shader, which turns it into a strip of 2 triangles. So you end up with 4 triangles drawn altogether.

share|improve this answer
    
Thanks ,that was pretty useful. Somehow vertex shader wasn't happy with vec3 Position . When I changed it to vec4 Position , it worked fine. –  maverick9888 Dec 20 '12 at 8:19
    
If this solved your problem, mark the answer as correct. –  Jari Komppa Jan 8 '13 at 8:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.