I want to write a game in which the player shoots projectiles (bullets, etc). Since I don't know how many and when these projectiles will be shot, I wonder how to buffer and render them (and when!).

Normal opengl pipeline (as I understand it):

  1. Create and bind buffers (once)
  2. Buffer data to these buffers (once)
  3. In loop - Draw every frame/period.

What about temporary objects ? I buffer them only when used ? I suppose I get the player input as trigger, and then buffer them and draw them. Is this approach fast enough ?

Thank you


1 Answer 1


Typically you allocate a buffer that's generously sized for the maximum number of items you think you might need.

Then when your temporary objects change, you fill that buffer from one end, with all the items you currently need, leaving space at the far end when you're drawing fewer items than the max. This way you're just paying the cost of a data upload to an existing buffer, not incurring all the cost of re-allocating a fresh one.

If you ever need more items than you have room for in the buffer, then you can...

  • (In a development build): crash with an error message saying the predicted max count was too low, so the developer knows to increase it. Simple, but a bit harsh...

  • Re-allocate a larger buffer automatically, and start using that one instead (and, in a development build, log a warning that the initial max might be too low)

  • Recycle the oldest / most distant / least apparent objects to make room for new/more important ones

  • Stop drawing items beyond the cap (usually a last resort, if you have no more memory to spend or no way to prune less-important items from the buffer)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .