I need to render objects in libgdx (average of 20-30) on screen, all sorted by Y value, so the sprites with the lowest Y values are rendered first. ( think about this perspective: http://i.stack.imgur.com/m1VQA.gif )
The game utilizes texture atlases, each has the size of 2048*2048.
I currently have three atlases. One for the playable characters, one for the NPC characters, and one for animals/monsters. Eventually we plan add a lot of different objects, npc sets and so on, so mixing up all the sprites to one big atlas is not an option (can get very limited on both design, and hardware).
The current rendering method first sorts the objects on screen every frame by Y value, and then draws them. This works perfectly, except for the fact, that this way, many texture switching can occour.
For example, rendering: - 3 animals - 2 npc's - player - 1 npc - 1 animal - 1 npc - 2 animal,
would need 7 texture switching. This entirely depends on the objects position on screen.
Sorting the sprites by atlas is not an option (first drawing the animals, then npc's, then the player), because this would make Y sorting impossible.
(The first thing I had in mind was increasing the texture atlas to 8192*8192, but many older desktop pc's, and mobile devices would be unable to run the game. The second thing I thought of was some kind of depth buffering, but I am unsure how to do that, if possible.)
What method must be used to achieve the desired result (sorted sprites from multiple textures), while maintaining stable frame rates? Is there any viable openGL trick to do this? Should I be worried about having 6-7 texture switches per frame?