I’m working on some code for creating Vertex Array Objects (VAO) and array buffers to put in the VAO’s. I don’t have much experience in these area’s yet. I do have code that works, but I don’t have a clue about what choices would be best when considering performance. So basically I’m looking for some general guidelines to follow with respect to array buffers and vao’s for gaining good performance in most situations. Personal experiences are very welcome, or if you have some pointers to good online resources I’d be interested as well.
Questions that come to my mind when thinking about these things are:
-
What is considered a good size for an Array Buffer? I guess to small isn’t good, but too large might not be good either?
-
What is the difference between GL_DYNAMIC_DRAW and GL_STREAM_DRAW? Am I correct when I’m thinking that dynamic draw is used when data changes every now and then, but between changes the data is used many times? And stream draw is for data that changes almost always between draws?
-
Is interleaved data for vertices, color, normals and texture coordinates always better? What if they don’t have to be updated at the same time? For example say mostly when I have to update the data I only update the color… would it be better to interleave the color? Or would it be better to put color data in the end of the array buffer? Or would it be better to get a second array buffer specifically for the color?
-
Which function to use for updating data in array buffers? I understood that glBufferSubData should be considered even if changing all data. What about glMapBuffer? I found a blog on the internet that said glMapBuffer is more efficient when having more than 32k data points in a buffer (see this blog post from 2007). Is this still considered valid?
-
In old code I used VBO’s. But I think these are completely replaced by VAO’s for OpenGL 3.0/3.1 now? Or is there still a use for VBO’s?
-
I guess mostly I’ll use an ELEMENT_ARRAY_BUFFER as well to draw using indices, any particular situations in which this might be a bad choice? When using indices for drawing, does it matter a lot whether I’d be drawing triangles or triangle strips?
Anything else I should know about VAO’s or array buffers for gaining good performance? Perhaps good to mention that I’m targeting OpenGL 3.0 class hardware.