Page 1 of 1

Resize textures on Android devices causes graphical errors

Posted: Sat Jan 04, 2014 3:29 pm
by technique
I want to provide different texture quality settings in my game to optimize performance on slow devices. Since there is no build in way to dynamicly resize textures i just reload it as image scale the image and destroy the old texture and loadRawData from image buffer.

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;
		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;

			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->loadRawData(dataStreamPtr, (Ogre::ushort) width, (Ogre::ushort) height, pixelBox->format);
			delete pixelBox;
			delete[] buffer;
	mTextureQuality = quality;

Re: Resize textures on Android devices causes graphical erro

Posted: Sat Jan 04, 2014 4:26 pm
by Wolfmanfx
Before you create the textrue make sure you destroy the RTSS techs from the material which are referencing the texture - I am not sure but this could be the problem.

Re: Resize textures on Android devices causes graphical erro

Posted: Sat Jan 04, 2014 8:09 pm
by technique
I already tried to invalidate the whole material scheme after resizing textures - this should reinitialize all RTSS materials?

(Ogre::RTShader::ShaderGenerator::invalidateScheme ( const String & schemeName) )

If not - i m not sure what you exactly mean. I had a look on the Ogre::RTShader::ShaderGenerator class definition i dont know how to do this (i m still not into the whole rtss-thing at all).

Re: Resize textures on Android devices causes graphical erro

Posted: Sat Jan 04, 2014 9:19 pm
by Wolfmanfx
I mean mShaderGenerator->removeAllShaderBasedTechniques(...) from a specific material

Re: Resize textures on Android devices causes graphical erro

Posted: Mon Jan 06, 2014 9:00 pm
by technique
Hard to get all materials which uses the resized textures :/. After removing - should i recreate the RTSS-techniques manually for each material like in the (RTShaderHelper) ShaderGeneratorTechniqueResolverListener::handleSchemeNotFound method?