Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

  1. Choose a VBO/VAO couple. (Different from the previous frame, so I'm alternating.)
  2. Bind that VBO
  3. Upload new data using glBufferSubData(GL_ARRAY_BUFFER, ...).
  4. Bind the VAO
  5. Render my stuff using glDrawElements(GL_***, ...);
  6. 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.)

share|improve this question
    
What you can do is upload the buffer data as early in the frame as possible, and render the buffer as late in the frame as possible, so that there is some CPU-bound work in between the two operations. This will remove the 1-frame latency and stop wasting time if the GPU takes a while. –  Boreal Jul 27 '13 at 7:42
    
There's ultimately no way to know, since OpenGL ES runs on an extremely wide variety of hardware. –  Nicol Bolas Jul 27 '13 at 8:54
    
@NicolBolas: What do you do in general. This way or not? –  Martijn Courteaux Jul 27 '13 at 10:16
add comment

1 Answer

Since you've mentioned iOS in your question, I'm going to refer you to Apple's guidelines, particularly at here: Use Double Buffering to Avoid Resource Conflicts.

Note that they comment: "Although shown for textures, this solution works for almost any type of OpenGL ES object".

In OpenGL ES 3.0 you would have glMapBufferRange, which is a better solution for streaming, but in the absence of that I would say to run with Apple's own current guidelines.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.