Thursday, June 16, 2011

VBOs and Vertex Array Objects

So I decided on using Vertex Buffer Objects (VBOS) to store the state information on each particle in my system. This should give me both a speed advantage as well as a simplicity advantage in the long run. I'd originally considered something akin to a complex Particle object to store information about each particle as well as siblings in a linked list of some sort. The downside to this is that the PC memory cache is not really optimized (read: at all) for things like linked lists where we're jumping all over the place between objects. A static (or in my case, semi-static) linear allocation of memory is far more efficient and ultimately makes certain things like multithreading a lot easier in the future.




Vertex Array Objects are likewise very useful for keeping things simple overall. They allow you to wrap one or more VBOs up together so that they can be enabled / disables just by enabling the parent Vertex Array Object. They also maintain all of the set state variables of the VBOs they include, so VBOs can easily be reused or swapped between VAOs with little work involved.



That's not to say that either of these is simple to implement for someone like myself who is just getting into the more advanced OpenGL concepts. Getting a running example of their usage is cake, but truly utilizing them in a way that streamlines your system can be a challenge. I spent three days contemplating, writing, and then re-writing classes and functions to wrap the state-based OpenGL functionality of these two objects into something I could tolerate using. What I finally came up with is by no means perfect, but it's useful and gets the job done.



I might write more about the technical side of what I've just briefly described at a later date. At the moment I know how it all works, and I'm guessing I'm the only one reading this at all, so what's the use. The point is that it works and it makes my life easier and my code simpler. I can't ask for more.



Pic related: THREE particles, all with different colors, managed by my system driven by VBOs and VAOs underneath.

I could tell you this is a static shot of them moving in real-time...but I'd be lying

No comments:

Post a Comment