View Full Version : Render with glDrawArrays in reverse order

02-04-2017, 12:50 PM
I'm working on rendering a bunch of point sprites as terrain, and I noticed a large performance drop when looking in the direction of the origin.
I've since found the problem, and think it can be solved if the glDrawArrays function can render the point sprites in reverse order when looking in the direction of the origin.

Here is a video demonstrating the problem: https://www.youtube.com/watch?v=KgORzkM9U2w
I have disabled alpha testing and I draw each chunk of 8x8 sprites partially over time, so you can see the order in which the sprites are rendered. First the sprites are drawn front-to-back, but when I turn around towards the origin, they are drawn back-to-front, which causes the performance drop.

I've looked around for this functionality, but I can't find anything. If this is not possible, are there any other ways to accomplish the same thing?
It would be possible to also store the VBO data in reverse order, but then you would have the same data twice in video memory...

02-05-2017, 12:36 AM
glDrawElements(...) can draw vertices in "reverse order", or even better: in any order
you have to create another buffer object for that, called "element buffer" or "index buffer", which is part of your vertex array object (if you have one)


02-06-2017, 02:06 AM
Ah, thanks! I've seen it used before, but it didn't occur to me to use it here.