# Replacing client side vertex arrays with glBufferData

I need to replace client side vertex arrays in order to upgrade to a new version of OpenGL but I'm not sure what the best way to buffer data is now.

What I have is a 2D sprite engine which is using batching to push as many vertices to the GPU (using fixed pipeline functions glVertexPointer etc...) but frequently the batch is only a single quad. Because of how sorting works the buffer needs to be updated every frame (or more).

I need to use glBufferData/glVertexAttribPointer now so what is the best way to handle this case? I can allocate the buffer for glBufferData large enough to hold the maximum size of a batch (which is more than maybe 5000 vertices) so should I just push the old vertex array to glBufferData every frame or use another method? Maybe calling glVertexPointer/glBufferData has the same costs associated with them to copy memory to the GPU so I don't need to worry about it but I'd like to know since I'm still pretty new to OpenGL.

CONCLUSION:

In my simple tests I found calling glBufferData every frame with all vertices (OpenGL 4.1) actually slightly faster than client side vertex arrays (OpenGL 2.1).

Thanks.

Basically, you're sending between 4 and 5000 vertices in an array. The time to upload will likely be the same between glBufferData() and other methods. The docs for glBufferData() lay it out pretty nicely. You can specify how the vertex data is going to be handled once it's uploaded:
usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance.
You don't say how you're drawing things, but I would assume that there's some coherence from one frame to the next. You probably aren't drawing completely different sprites on each frame. So you can take advantage of that by not uploading the same geometry every frame. Only upload the new stuff, or change what has changed. You can use glBufferSubData() for that.