Search code examples
javaandroidopengl-eslibgdx

Optimizing alternating textures in libgdx opengl


I'm making a game using libgdx and each of the characters on screen is made up of two textures (body and head images) when drawing thousands of these textures the amount of render calls is very high because the texture needs to keep rebinding as alternating textures are drawn. If I draw the heads all first then the bodies I only make 2 render calls and my frame rate is great. However doing this makes the z order wrong which can easily be seen when the characters pass by each other. Is there anyway to optimize or cache these textures so that they can be drawn in the right order and also minimize opengl binds?


Solution

  • Use Texture packing to reduce the amount of opengl rebind. See :

    https://github.com/libgdx/libgdx/wiki/Texture-packer