yoo2001818
yoo2001818

Reputation: 115

Is it possible to draw lines and triangles in a single draw call in OpenGL?

In Blender and many other 3D modeling programs, there are 3D manipulator widgets (handles) which look like this.

Example of a 3D manipulator widget

However, as you can see, these widgets consist of polygon handles and lines connected to them from the origin point. However, in OpenGL, draw calls like glDrawElements or glDrawArrays can use only one primitive mode (such as GL_TRIANGLES, GL_POINTS, GL_LINES, ...) per single draw call.

So in order to draw the 3D widgets consisting of triangles and lines, it needs at least two VBOs, one for polygons and one for lines. However I think it's pretty awkward to make draw call twice for that. (Or, without instancing or merging VBOs, we need 2 draw calls per one axis.)

Is it possible to draw both lines and triangles in single draw call in a case like this? There won't be too much performance penalty for drawing widgets though, but I'm curious if there is an efficient method to draw it.

Upvotes: 2

Views: 3016

Answers (1)

Graham Rushton
Graham Rushton

Reputation: 136

Is it possible to draw both lines and triangles in single draw call in a case like this?

Yes, you could use geometry shaders. These would allow you to emit new output primitives that don't have to match the input primitives.

Is it worth it in this case? I would suggest not, it would be horribly complicated for little benefit.

Use a single VBO/IBO for all the axi's geometry data. Include a colour in the vertex data then draw the three axi's lines in one call, then draw the three axi's boxes in another.

Upvotes: 3

Related Questions