Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Queries regarding Geometry Shaders

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6

    Queries regarding Geometry Shaders

    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 ?

  2. #2
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    761
    If you do not set GL_GEOMETRY_VERTICES_OUT, then the default is zero and you can't emit anything. Link should have failed, and the link log should tell you this.

    You should also call
    glBindAttribLocation before glLinkProgram; as it is, you are probably lucky that the attribute is at index zero, but there is no guarantee.

    Also, you're mixing up three different things; EXT_geometry_shader4, ARB_geometry_shader4, and GLSL 150. It is probably simplest to just use the core 150 style: explicitly declare the layouts in the shader and stop using
    glProgramParameteriEXT.


  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    The mode passed to draw calls obviously has to match GEOMETRY_INPUT_TYPE, as that's the input to the geometry shader.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  4. #4
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6
    You are totally right about glBindAttribLocation(). The problem was weird when I changed vec3 Position to vec4 Position it worked ! No idea why is it so . I will also try to avoid mixing EXT_geometry_shader4, ARB_geometry_shader4, and GLSL 150. That was useful thanks a lot.

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    6
    Quote Originally Posted by arekkusu View Post
    If you do not set GL_GEOMETRY_VERTICES_OUT, then the default is zero and you can't emit anything. Link should have failed, and the link log should tell you this.

    You should also call
    glBindAttribLocation before glLinkProgram; as it is, you are probably lucky that the attribute is at index zero, but there is no guarantee.

    Also, you're mixing up three different things; EXT_geometry_shader4, ARB_geometry_shader4, and GLSL 150. It is probably simplest to just use the core 150 style: explicitly declare the layouts in the shader and stop using
    glProgramParameteriEXT.

    You are totally right about glBindAttribLocation(). The problem was weird when I changed vec3 Position to vec4 Position it worked ! No idea why is it so . I will also try to avoid mixing EXT_geometry_shader4, ARB_geometry_shader4, and GLSL 150. That was useful thanks a lot.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    Just some clarification so that my previous post doesn't mislead you, GEOMETRY_OUTPUT_TYPE does not affect the mode passed to draw calls, the input does, namely, it has to be as such:

    - If GEOMETRY_INPUT_TYPE is TRIANGLES, then mode has to be either TRIANGLES, TRIANGLE_STRIP or TRIANGLE_FAN
    - If GEOMETRY_INPUT_TYPE is LINES, then mode has to be either LINES, LINE_STRIP or LINE_LOOP
    - If GEOMETRY_INPUT_TYPE is POINTS, then mode has to be POINTS

    Similar rules apply for adjacency primitives.

    The only exception is when tessellation is used as then the mode is PATCHES, but the GEOMETRY_INPUT_TYPE can be anything as long as it matches the output type of the tessellation evaluation shader.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

Tags for this Thread

Posting Permissions

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