I have implemented a sprite batching system in OpenGL which will batch sprites based on their texture. However, when I'm rendering ~5000 sprites all using the same texture I'm getting roughly 30fps.
The process is as followed
Create sprite batch which also create a VBO with a set size and also creates the shaders as well
Call begin and initialise the render mode (at the moment just setting alpha on)
Call Draw with a sprite. This checks to see if the texture of the sprite has already been loaded and if so it just creates a pointer to the batch item and adds the new sprite coords. If not then it creates a new batch item and adds the sprite coords to that; it adds the batch item to the main batch. If the max sprite count is reached render will be called
Call end which calls render to render the left over sprites in the batch, and also resets the buffer offset
Render loops through each item in the batch and will bind the texture of the batch item, map the data to the buffer and then draw the array. The buffer will then be offset by the amount of sprites drawn.
I have a feeling that it could be the method I'm using to store the batched sprites or it could be something else that i'm missing but I still can work it out.
The class files are at these URLs:
On top of this, I'm also getting a weird issue where two sprites are batched on after the other the second sprite will use the same coordinates as the last. But, the one that is drawn after it is fine. I can't seem to find what is causing this issue.