views:

33

answers:

2

So in a OpenGL rendering application, is it usually better to create and maintain a vertex buffer throughout the life of an application and just swap out the data every frame with glBufferData, or is it better to just delete the VBO and recreate it every frame?

Intuition tells me it's better to swap out data, but a few sample programs I've seen does the latter, so I'm kind of confused.

I read Nvidia's whitepaper on VBOs, but as I'm a newbie to opengl, it didn't make a whole lot of sense.

Thanks in advance for and advice

+2  A: 

Since you're generating a whole new set of data each frame the documentation seems to indicate that GL_STREAM_DRAW is the Right Way to go about things.

genpfault
A: 

The significant thing about VBOs is that they are render data buffers that are stored in graphics memory and not in the computer's main memory. That makes their usage very efficient when the data in them isn't being updated (too) frequently, because every time you do that, the computer will have to transfer (potentially huge amounts of) data from main to graphics memory - which is slow.

So the ideal case is to put all required render data into VBOs once and then only manipulate them via OpenGL functions like matrix transformation or via shaders.

So you would e.g. put each mesh's world space coordinates and texture coordinates into VBOs and never directly touch them again; you'd use the modelview matrix, lighting functions and shaders to render them.

You can do more to optimize VBO usage, but that's the basics as I have understood them.

Find some good hints and more details here: http://stackoverflow.com/questions/1728026/how-do-i-use-opengl-3-x-vbos-to-render-a-dynamic-world

karx11erx