Geometry shader + glDrawInstacedArrray ()

Hi, I have already used both geometry shaders and instanced rendering in some applications, but I was wondering if I could mix them

  • Basically, I would like to create a generic line rendering system, where I simply push vertices (vec3 position, vec4 color) to a buffer, and draw several lines in a single draw call (if 0, 1, 2, …, n are the vertices index, I would like to draw lines between (0, 1), (2, 3), …, but not (1, 2), (3, 4) …)

  • I think I can do it with a ‘line VAO’, which would hold two vertices : ((0, 0, 0), (0, 0, 1)) , draw instancely and apply a different transformation matrix in each instance.
    The VAO method would lead to many calculation cpu-side, to process the transformation matrix for each line: distance between the two points (line model scaling), angle between the standart model and the line (rotation), translate the model to the line origin

I would like to skip those calculation with a geometry shader, as coordinates are already ‘world-relative’ CPU-side

I hope it made sense and English was correct, maybe I’m searching the wrong way, so feel free to give me alternative solution. Thank you for your reading

That’s what you get from glDrawArrays(GL_LINES). No need for a geometry shader or instancing.

If you use a geometry shader, each invocation will get two vertices, i.e. 0 and 1, 2 and 3, 4 and 5, and so on.

Instancing lets you use a single element from an attribute array for all vertices of an instance, so it can reduce the size of the attribute arrays. But if you’re using a geometry shader, you could just use GL_POINTS where each “point” contains all of the information required for a line segment, and have the geometry shader convert each point to to a line segment.

In any case, there’s no reason why the two can’t be mixed.