Texture switching with a entity system
        Posted  
        
            by 
                GameDev-er
            
        on Game Development
        
        See other posts from Game Development
        
            or by GameDev-er
        
        
        
        Published on 2012-06-22T22:29:18Z
        Indexed on 
            2012/06/23
            3:24 UTC
        
        
        Read the original article
        Hit count: 784
        
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?
© Game Development or respective owner