I’m making a Sprite Batcher and I was looking for some opinions
I’m using VBOs (2 for double buffer) and a IBO to handle my draw data. The VBOs are DYNAMIC_DRAW buffers and IBO is a STATIC_DRAW buffer.
When I init the VBOs I use glBufferData with a NULL param for the data, where with the IBO I pre-fill it based on my initial max buffer size.
Now, I’m not sure what to do when I hit my max buffer size. I was wondering what you guys think would be best or maybe something else
Idea 1:
In my Draw() method that fills up a float array that holds my vertex data. I check to see if I have enough space left in my vertex buffer.
If I do continue to fill up the data until we run out of room.
If we DONT have enough room, double the size of the buffer. This means I reallocate space for the float array that holds my vertex data, the actual VBO buffers, and the IBO buffer. In addition I prefill the index buffer again
Idea 2:
In my Draw() method that fills up a float array that holds my vertex data. I check to see if I have enough space left in my vertex buffer.
If I do continue to fill up the data until we run out of room.
If we DONT have enough room, flush the batch and send all the data off to the GPU. Then continue on fill the vertex data in the float array
I see down sides to these both methods.
On Idea 1, thats a lot of reallocation! It will cause a major performance hit for a couple of seconds, but it will only have if and when needed.
On Idea 2, thats a lot of potential GPU calls! If I don’t have enough room in the first go then any slack will have to get picked up in the next go. And if this a is a constant slack then I will always have a performance hit.
What do you guys think? Is there a even better solution?
Also I should mention that I’m using OpenGL ES 2.0
Where my vertex data is transferred over to the gpu using glBufferSubData