On my windows pc the same way (same Ogre setup using RTShader system) is just working fine (all textures are scaled and the performance increased as expected) but on my android device there are strange graphical errors after resizing as you can see on the screenshot.
The internal resource might not be recreated in the right way - but i dont know why. Is there a better way to resize the textures (all textures are .png files)?
Code: Select all
void Settings::setTextureQuality(TextureQuality quality)
{
if(quality == mTextureQuality) return;
Ogre::ResourceManager::ResourceMapIterator it = Ogre::TextureManager::getSingletonPtr()->getResourceIterator();
std::vector<Ogre::TexturePtr> textures;
while(it.hasMoreElements())
{
Ogre::TexturePtr texture = it.getNext().staticCast<Ogre::Texture>();
if(texture->getGroup().compare("General") == 0)
{
Ogre::Image image;
image.load(texture->getName(), texture->getGroup());
int factor = quality;
if(texture->getWidth() <= 64) continue;
if(texture->getWidth() <= 128 && quality != TQ_HIGH) factor = 2.0f;
int width = texture->getWidth();
int height = texture->getHeight();
width = width / factor;
height = height / factor;
if(texture->isLoaded())
texture->unload();
texture->freeInternalResources();
int pixelSize = image.getBPP() / 8;
char* buffer = new char[pixelSize * width * height];
Ogre::PixelBox* pixelBox = new Ogre::PixelBox(width, height, image.getDepth(), image.getFormat(), (void*) buffer);
Ogre::Image::scale(image.getPixelBox(), *pixelBox);
Ogre::DataStreamPtr dataStreamPtr(new Ogre::MemoryDataStream(pixelBox->data, pixelSize * width * height));
texture->setWidth(width);
texture->setHeight(height);
texture->loadRawData(dataStreamPtr, (Ogre::ushort) width, (Ogre::ushort) height, pixelBox->format);
//texture->createInternalResources();
image.freeMemory();
delete pixelBox;
delete[] buffer;
}
}
mTextureQuality = quality;
}