Texture switching with a entity system
- by GameDev-er
I'm using thinking of using an entity system in my game. So far I've been using Artemis with success. However, I have a question about texture switching. I read that switching textures too often is bad. So I load all the textures when the game loads like so:
import org.newdawn.slick.opengl.TextureLoader;
...
public HashMap<String, Texture> Textures;
...
Then for each texture I do this:
Texture tex = TextureLoader.getTexture("PNG", this.getClass().getResourceAsStream(texturePath));
Textures.put(textureName, tex);
Then when drawing entities I do this:
drawEntity() {
glBindTexture(GL_TEXTURE_2D, Textures.get(entityTexture).getTextureID());
...
}
Say I have 50 entities, using 10 different 3D models, each with their own texture. When the drawEntity system runs, it doesn't group by which entities use which texture. So I could be switching textures before drawing each entity! Is there a more efficient way to switch textures between entities? Or is glBindTexture() a good option?