I'm working with OpenGL ES 2.0 and OpenGL 2.1, and I've run into this issue where I need to sort my vertices for my sprite batch. For example, if I set the depth too high for a sprite where its vertices are at the beginning of the vertex buffer, then it'll draw on top (expected), but any alpha borders will draw on top of it too. I did post a thread on this months ago, but wasn't able to get to it at the time, and forgot. The solution that was proposed was to sort the indices, which I think is a good idea. Currently, I'm not using an IBO or VBO for indices or vertices. Would VBO/IBOs be useful at all? I currently use an STL vector for my vertex array and another for my index array since it's mutable whenever I need to add/remove, possibly reorder or transform the sprites in any way. I'd like give each sprite its own matrix to pass to the shader, but then I'd be uploading huge amounts of uniform matrices when I have many sprites onscreen.
So, would it be wise to re-sort my entire index buffer whenever sprite is added or its depth changes? This would work well for an axis-aligned orthographic camera, but what if the camera rotates? This would happen quite a bit if I ever wanted to use my sprites with a perspective camera. I'd also like to support billboarding with my sprite batch for perspective purposes. If I were to billboard, wouldn't I need to ensure that each billboard is drawn from back-to-front each frame (assuming glDepthFunc is setup that way)? What would be a decent way to sort my sprites by depth? Should I just re-order the index buffer (not the vertices) based on signed distance to the camera drawing them? A dynamic camera could easily change the depth of a sprite's (aka, "billboard's") distance on a frame-to-frame basis simply by moving and re-orientating the camera.
Another issue I'm running into is disabling sprites. What if I don't want to render a sprite? I treat all sprites as a Transform subclass in my code, like models, particles system and other entities my scene manager updates and renders. The differences is that it doesn't own its own geometry data because it's grouped together in a huge batch vector. Would it just be wise to set the alpha for my disabled sprites' vertices to zero, or would it be wise to move its vertices out of the vertex/index vectors until it's re-enabled? Setting alpha to zero can be heavy on mobile hardware, especially if it's a large sprite.
Any thoughts on the matter would be really helpful!