4

I currently have some VAOs and an index list. The idea is to process groups of 4 elements in the geometry shader. The way of picking the groups is if I have the list (1,2,3,4,5,6,7,8,...) then the groups would be ((1,2,3,4),(5,6,7,8),...).

After spending several hours of coding I realized that geometry shaders don't accept 4 vertex primitives. I would like to know if there is a way around it. Maybe choosing a "provoking vertex" and appending the other 3 to it as added properties in the vertex shader stage (I doubt that's possible, though).

Gonzalo
  • 3,674
  • 2
  • 26
  • 28
  • 1
    You can combine your 4 vertices to one big "vertex" and pass them as points to the geometry shader. – dari Oct 12 '15 at 13:30
  • I think that's easy when you don't have an index list. In that case I would just put the required values in the order that I want and set the VAOs to read bigger chunks. In the case of an indexed list (which is necessary in this situation) how would that be done? – Gonzalo Oct 12 '15 at 17:52

1 Answers1

5

Geometry shaders do accept primitives with 4 vertices as input: GL_LINES_ADJACENCY.

This primitive mode might be meant for lines where you need the two neighboring segments for each segments, but it is not limited to any particular use case - it just provides 4 vertices as input, and can be used as such (it could also be used to emulate the deprecated GL_QUADS primitive mode with geometry shaders).

Jongware
  • 22,200
  • 8
  • 54
  • 100
derhass
  • 43,833
  • 2
  • 57
  • 78
  • Thank you! I thought `GL_LINES_ADJACENCY` required some special properties of the rendered mesh. So after all it's just a simple 4 input vertex to the GS and the proper meaning of `GL_LINES_ADJACENCY` may be given in later stages of the pipline (which is not my case, since I'm doing transform feedback). – Gonzalo Oct 12 '15 at 21:26
  • @Gonzalo: Actually, there is no "proper meaning" later down the pipeline. The only thing that can give a geometry shader's input primitive any meaning is the geometry shader itself. The "adjaceny" meaning is only fulfilled if you actually supply the information of the neighboring vertices per input primitive. But the GL really won't care what exactly you put there, and if some other primitive might share the data or not. If you really need adjacency, this means that you have to redundantly specify such neighboring infos per input primitive. – derhass Oct 12 '15 at 21:38
  • Oh, right. I was thinking of lines arriving to the rasterizer, but as you say, geometry shader can output something different from lines with adjacency. So the name `GL_LINES_ADJACENCY` is just a suggestion of how to use that primitive mode, though not limited to adjacency purposes. Thank you! – Gonzalo Oct 12 '15 at 22:26
  • 1
    @Gonzalo: The geometry shader not only can output other primitives than lines with adjacency, it also absolutely _must_ do so. The rasterizer and further stages of the pipeline cannot handle adjacency primitives at all (for obvious reasons). Adjacency primitves are only valid as input for the geometry shaders. It is also not possible to draw such primitives if no GS is in use. – derhass Oct 12 '15 at 22:31
  • @Gonzalo: actually, I might be wrong with my very last statement in the previous comment. It seems like one can draw adjacency primitives without a GS, the adjacent vertices are just ignored. – derhass Oct 12 '15 at 22:38