Resize textures on Android devices causes graphical errors

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Resize textures on Android devices causes graphical errors

Post by technique » Sat Jan 04, 2014 3:29 pm

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;
	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;
}
Attachments
Screenshot_2014-01-04-15-27-53.jpg
Screenshot_2014-01-04-15-27-53.jpg (136.46 KiB) Viewed 1491 times
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: Resize textures on Android devices causes graphical erro

Post by Wolfmanfx » Sat Jan 04, 2014 4:26 pm

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.
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Resize textures on Android devices causes graphical erro

Post by technique » Sat Jan 04, 2014 8:09 pm

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).
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: Resize textures on Android devices causes graphical erro

Post by Wolfmanfx » Sat Jan 04, 2014 9:19 pm

I mean mShaderGenerator->removeAllShaderBasedTechniques(...) from a specific material
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: Resize textures on Android devices causes graphical erro

Post by technique » Mon Jan 06, 2014 9:00 pm

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?
0 x
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender

Post Reply