开发者

Optimizing texture swapping on opengles for the iPhone

I have 2 1024x1024 sprite sheets, one containing several 480x320 background images and another containing a variety of smaller elements as entities and interface. My framerate drops like a rock whenever I enter a scene in which I have to display sprites from both textures (forcing me to re-bind twice per frame, interface texture->bg texture->interface texture).

- (void)setCurrentTexture:(int)texID{
 if(currentTex == texID)
  return;
 else
  curre开发者_高级运维ntTex = texID;

 // Bind the texture name. 
 glBindTexture(GL_TEXTURE_2D, [Graphics getTexture:texID]);
 // Speidfy a 2D texture image, provideing the a pointer to the image data in memory
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, [Graphics getTexWidth:texID], [Graphics getTexHeight:texID], 0, GL_RGBA, GL_UNSIGNED_BYTE, [Graphics getTexData:texID]);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}

Is there something wrong with the way I'm swapping my textures?

Edit: I've removed half of the state changes I've been making. Removing any of the above 3 results in my polygons being textured with nothing (i.e. the show up white). The biggest hitter is glTexImage2D... but trying to set it elsewhere once (at init, for example) ends up with my models/quads not being textured at all.


Unless you're updating the data in the textures you should only call glTexImage2D once for each texture when your application startup.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜