0

I need get 4 vertices after vertex shader processing. Primitive(quad) drawing with target: GL_TRIANGLE_STRIP.

My code:

layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 4) out;

in vs_output
{
   vec4 color;
} gs_in[];

out gs_output
{
   vec2 st   ;
   vec4 color;
} gs_out;

void main()
{
   gl_Position  = gl_in[0].gl_Position;
   gs_out.st    = vec2(0.0f, 0.0f);
   gs_out.color = gs_in[0].color;
   EmitVertex();

   gl_Position  = gl_in[1].gl_Position;
   gs_out.st    = vec2(0.0f, 1.0f);
   gs_out.color = gs_in[1].color;
   EmitVertex();

   gl_Position  = gl_in[2].gl_Position;
   gs_out.st    = vec2(1.0f, 0.0f);
   gs_out.color = gs_in[2].color;
   EmitVertex();

   gl_Position  = gl_in[3].gl_Position;
   gs_out.st    = vec2(1.0f, 1.0f);
   gs_out.color = gs_in[3].color;
   EmitVertex();

   EndPrimitive();
}

compiller throw error: "array index out of bounds"

how i can get 4 vertex on geometry shader?

toodef
  • 125
  • 1
  • 11
  • Your code shouldn't compile, since you didn't declare an [input layout qualifier](http://www.opengl.org/wiki/Geometry_Shader#Primitive_in.2Fout_specification). – Nicol Bolas Apr 03 '13 at 23:51
  • Nicol, but i can get 4 vertices if only i use _"lines_adjacency"_. But it's not satisfy **GL_TRIANGLE_STRIP**. I realized that something was wrong? – toodef Apr 04 '13 at 10:43
  • Please change your geometry shader into code *that compiles*. I can't give you advice on clearly broken code. – Nicol Bolas Apr 04 '13 at 11:36
  • I did it. Second option when position translate from vs in structure and on gs execute `gl_Position = gs_in[n].pos`; Thanks! – toodef Apr 04 '13 at 12:21

1 Answers1

2

Primitive(quad) drawing with target: GL_TRIANGLE_STRIP.

The primitive type must match your input primitive type. Just draw with GL_LINES_ADJACENCY, with every 4 vertices being an independent quad.

Even better, stop murdering your performance with a geometry shader. You'd be better off just passing the texture coordinate as an input. Or, failing that, doing this in a vertex shader:

out vec2 st;
const vec2 texCoords[4] = vec2[4](
  vec2(0.0f, 0.0f),
  vec2(0.0f, 1.0f),
  vec2(1.0f, 0.0f),
  vec2(1.0f, 1.0f)
);

void main()
{
  ...

  st = texCoords[gl_VertexID % 4];

  ...
}

Assuming that you rendered this with glDrawArrays rather than glDrawElements.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • @toodef: In general, if you ever think that adding a geometry shader is going to improve performance, you're probably wrong. Not all the time, but usually. – Nicol Bolas Apr 04 '13 at 13:56
  • I add geometry shader for billboard generate. But geometry shader is not called by default in pipeline? – toodef Apr 04 '13 at 14:58
  • @toodef: [No, they're not.](http://gamedev.stackexchange.com/questions/48432/why-does-this-geometry-shader-slow-down-my-program-so-much/48434#48434) – Nicol Bolas Apr 04 '13 at 15:20