What is the correct and most efficient approach of streaming vertex data?
- by Martijn Courteaux
Usually, I do this in my current OpenGL ES project (for iOS):
Initialization:
Create two VBO's and one IndexBuffer (since I will use the same indices), same size.
Create two VAO's and configure them, both bound to the same Index Buffer.
Each frame:
Choose a VBO/VAO couple. (Different from the previous frame, so I'm alternating.)
Bind that VBO
Upload new data using glBufferSubData(GL_ARRAY_BUFFER, ...).
Bind the VAO
Render my stuff using glDrawElements(GL_***, ...);
Unbind the VAO
However, someone told me to avoid uploading data (step 3) and render immediately the new data (step 5). I should avoid this, because the glDrawElements call will stall until the buffer is effectively uploaded to VRAM. So he suggested to draw all my geometry I uploaded the previous frame and upload in the current frame what will be drawn in the next frame. Thus, everything is rendered with the delay of one frame.
Is this true or am I using the good approach to work with streaming vertex data?
(I do know that the pipeline will stall the other way around. Ie: when you draw and immediately try to change the buffer data. But I'm not doing that, since I implemented double buffering.)