2
$\begingroup$

Since I am using batch rendering, so I should pack every render units can be batched into one big VBO. But, what if I am in a case where render units are dynamically changed, some new units are added in, and some units are subtracted out. So I should reconstruct my VBO again and again in very frame. So here is the question.

Should I allocate a big enough storage in the first time and update the data in it, and only reallocate when run out of the storage, or allocate storage according to the size on demand in each frame?

$\endgroup$
  • 1
    $\begingroup$ I thought you said, "I will avoid asking more than one question once time later." That rule doesn't only apply to SO; it's all of our sites. Also, all of the other questions asked about that question still apply. $\endgroup$ – Nicol Bolas Jun 8 '17 at 17:26
  • $\begingroup$ Actually, this posting is before that comment I replied.@NicolBolas $\endgroup$ – Francis Jun 9 '17 at 2:56
2
$\begingroup$

Allocate a VBO with a reasonable amount of storage during startup, and update the data in it each frame. This will help the driver manage the memory efficiently. Don't destroy and recreate the buffer unless absolutely necessary; too much resource creation/destruction churn will put more pressure on the driver and can potentially lead to stalls.

To be more specific: for data that will be updated every frame, you probably want to initialize it using glBufferStorage with GL_DYNAMIC_STORAGE_BIT (or, if you're on an older OpenGL version, glBufferData with GL_DYNAMIC_DRAW). Then, to update it each frame, use glMapBufferRange with GL_MAP_INVALIDATE_BUFFER_BIT. This should be an efficient, fast path in the graphics driver.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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