Hi Fellow creators!
I've been using ID3DXSPRITE class on my 2D engine and have been happy with its performance. However i come to a point where i want to take it to the next level and implement a sprite class that will allow me with more controls on 2D rendering. Therefore i replace it with using custom vertex quads.
It has a Begin() function that initializes render states and projections, End() function that pushes the batched vertices into the locked d3d vertices and performing a single draw primitive call to draw all the quads at once. I also have a Flush() function to force rendering of currently batched quads.
On tests it performs well compared to ID3DXSPRITE by about 10% in frame rate when rendering 100 to 1000 sprites while using a single texture.
However when i try toggling texture on every draw call, my frame rate significantly dropped. This is expected as my sprite class is not smart enough to handle change in textures. Whenever a texture is changed, it immediately Flush() the currently batched sprites and starts batching the succeeding ones until a change in texture occurs or End()/Flush() is called.
I believe ID3DXSPRITE has a mechanism to batch sprites using the same textures (D3DXSPRITE__SORT_TEXTURE??).
Now my question is what's a good way to batch sprite quads in terms of textures?