I am currently working on my rendering code (using OpenGL 3.2, in case it matters) and I am wondering which of these approaches would be best (or if any better alternatives exist).
In both methods I store data about each object (position, colour etc) in a VBO, lets call it objectsVBO.
Method A, double-buffered VBO:
objectsVBO[0] and objectsVBO[1] are the two VBO buffers.
unsigned int buf = 0;
updatedObjects is an array of all objects, after having been updated by gameplay & physics code
every frame:
sort updatedObjects back to front, remove objects not in view
glBufferData to put updatedObjects into objectsVBO[buf]
glDrawArrays(objectsVBO[buf], 0, num_objects_in_view);
buf = 1 - buf;
EDIT: Looks like this method may be a better way to accomplish the above.
Method B, updating part of VBO:
objectsVBO is a VBO storing all objects
updatedObjects is an array of objects that have changed, after having been updated by gameplay & physics code
every frame:
glBufferSubData to put updatedObjects into objectsVBO (possibly only objects that are on screen)
indices = index of each object in objectsVBO that is on screen, sorted back to front
glDrawElements(objectsVBO, indices);
Method A means only objects to be drawn ever need to be pushed to the gpu and since its double buffered, hopefully the next frame can be prepared before the first frame is fully rendered.
Method B means only objects which have actually changed need to be pushed to the gpu while unchanged objects are still there from the previous frame but I do not have double buffering.
Both methods only render whats on screen and render back to front as required. Static geometry will be kept in a separate VBO in both cases.
Any help or ideas appreciated as I don't have an awful lot of experience with 3D rendering yet.