gl::drawStrokedTriangle is gone?


I’m just updating from an earlier release of Cinder to the newest one (from 0.8.7 if I remember right) and I’m going through and updating everything to its newer equivalent but I can’t find any equivalent to gl::drawStrokedTriangle. Was it removed or renamed? gl::drawSolidTriangle exists so I’d assume a stroked version would exist, like with the other shapes (i.e. gl::drawStrokedRect and gl::drawSolidRect, etc.), but I can’t find anything.


You can replicate the function like this:

gl::begin( GL_LINE_STRIP );
gl::vertex( pointA );
gl::vertex( pointB );
gl::vertex( pointC );
gl::vertex( pointA );


Yeah, I figured as such, I was more curious where it went. Was it so simple it was just dropped?


It could have been an oversight, as most of the OpenGL code was written from scratch for the v0.9.0 update. Then again, rendering a single triangle is not very efficient, nor common, so I can see why it was skipped.


How is it inefficient? Do you mean that’s inefficient when drawing loads of polygons, or just the function drawing a triangle itself is slow?


Both, actually.

To draw just one triangle, Cinder has to create a temporary Vao, fill it with data, create a temporary shader, set the proper uniforms and draw the triangle. That is a lot of work for just one triangle.

If all you need is a single triangle, then that’s OK. But in most cases, you’d like to draw more than that. Then it’s much more efficient to combine a lot of primitives into a single draw call. You could, for example, add lots of vertices between the call to gl::begin() and gl::end(). But then you’re still copying all that data every time you draw it. So it’s even better to store all the information in a Vbo or VboMesh, so that you can reuse it time and again. And if you want to reduce the amount of work even more, you could combine the VboMesh and the GlslProg shader into a gl::Batch, so that we don’t even have to bind uniforms all the time. This can be combined with instanced rendering if you want to draw the same mesh multiple times in different locations, or with different colors.

You get the best performance when you reduce the number of draw calls to the absolute minimum.


P.S.: there are other optimizations you can do as well, of course. For example, on iOS and Android devices it’s a good idea to reduce overdraw as much as possible, due to the nature of their GPU (Tile Based Rendering).