The code looks something like this:
Code: Select all
void reloadTextures(Ogre::Entity* ent)
{
Ogre::TextureManager* tMgr = Ogre::TextureManager::getSingletonPtr();
Ogre::Entity* oent = ent->getEntity();
for (int i = 0; i < oent->getNumSubEntities(); ++i) {
Ogre::SubEntity* ose = oent->getSubEntity(i);
const Ogre::MaterialPtr& mat = ose->getMaterial();
for (int t = 0; t < mat->getNumTechniques(); t++) {
Ogre::Technique* tec = mat->getTechnique(t);
for (int p = 0; p < tec->getNumPasses(); p++) {
Ogre::Pass* pass = tec->getPass(p);
for (int u = 0; u < pass->getNumTextureUnitStates(); ++u) {
Ogre::TextureUnitState* tu = pass->getTextureUnitState(u);
Ogre::TexturePtr tex = Ogre::TextureManager::getSingletonPtr()->getByName(tu->getTextureName());
tMgr->unload(tex->getName());
tex->reload();
}
}
}
}
}
- This code works, it does reload the textures, both for the GL and GLES2 rendersystems.
- Using GL it works flawlessly. Using GLES2 it leaks memory, big time.
- If I reload 3 512x512 textures, I get a 5MB memory rise in GLES2. In GL memory consumption stays exactly the same.
- If I just do the tex->reload(), and I don't add the tMgr->unload() call, memory rise is bigger still (nearing 15 MB).
Since the snippet works for regular OpenGL, I'm guessing it's not wrong, but maybe there's some other way to do it? I don't want to have all the textures in the resource manager because that would mean keeping track of all the the different file names, this way I can just throw in a new folder with modified textures and it will work.
Has anyone come into something like this before using GLES2? I'll be trying to debug this, but I wanted to know if the code should work as it is right now.