Simple question about geometry shader

Hi there,

I have a new question about performance of geometry shader.
My simple problem is that I have to render a grid on the scene floor.
Do you think that I’d rather send all vertices of the grid (two vertices by line) to a couple vertex/fragment shader, or send only 3 vertices with 4 elements designing two lines (one along OX axis, other along OZ axis) and replicate them using geometry shader as GL_LINES_STRIP ?
Which solution may be smoother ?

Best regards

Hmm, it sounds more like a job for the new tessellation shaders. However, unless there are good reasons (e.g. memory is tight and the grid has huge number of lines) I’d probably not bother for that case. I’d say simply fill a VBO with the vertex data for the grid and be done with it :wink:

The typical case of the grid is to have around 10/12 lines in plane (O, OX, OZ) along OX axis and OZ axis.
So, 84 vertices defining 42 lines must be drawn at the end.
Tessellation shaders are in OpenGL 4.X and I have to use only OpenGL 3.3. That’s why I was thinking about using geometry shaders to generate 21 lines after having sent only one line.
But, that implies to generate those lines every time the scene is drawn.
So, I don’t know if it is more efficient to generate vertices every time that size or step of the grid is changed, or let the geometry shader generate those lines every time ?

I’d be surprised if there is any significant impact on frame time no matter which method you use and I don’t know if you’d even be able to measure anything that is not lost in the noise - you’ll have to try both ways and measure yourself I’m afraid.
FWIW this very much sounds like you are jumping through hoops to optimize something that will have no impact whatsoever on the performance of your application overall [1]. In other words it’s not worth bothering and the solution that is simplest to program and maintain is the way to go :wink:

[1] or have you done measurements that show otherwise?

Actually, my measurements agree what you said : whatever the way took for drawing the grid, there is no gain or loss of performance.
I choose instinctively what you said after, simplest solution for developing and maintaining the code :smiley:
Thanks all for your answers !