I'm slowly working on a 2D game engine and I wanted to have the capability to scale (and rotate) 2D textures so I can create some extra effects.
So, it may not be used often, but it would be nice if it could be used often (without killing the FPS!)
I keep my sprite textures in a block texture that holds all the frames of the object, and simply draw the source rect that I need at the time (to draw a frame).
I am able to resize as follows:
Code: Select all
irr::video::ITexture* texture1 = driver->getTexture("F:/Coding/Current/Game Engine/Cross Platform Game Library - Irrlicht/media/fire.bmp");
irr::video::ECOLOR_FORMAT colorFormat1 = texture1->getColorFormat();
irr::core::dimension2d<s32> size1 = texture1->getSize();
void* data1 = texture1->lock();
irr::video::IImage* image1 = driver->createImageFromData(colorFormat1, size1, data1, true, true);
irr::video::IImage* tempImage1 = driver->createImage(colorFormat1, irr::core::dimension2d<s32>(128, 128));
image1->copyToScaling(tempImage1);
irr::video::ITexture* tex1 = driver->addTexture("Texture1_Resized", tempImage1);
texture1->unlock();
But my compiler warns me (in the output window) that the
Code: Select all
texture->unlock();
**EDIT** Actually, it specifically says that unlocking non-power of 2 textures is extremely slow.
Is there another way to do this?
At the moment I need to:
1. Lock the Texture. (slow?)
2. Create an IImage (the same size as the Texture!)
3. (then) I have to create an empty IImage of the appropriate Size & Color.
4. (and finally) I get to resize the image!
5. (and really FINALLY) I have to make a new texture again (of course! )
6. Unlock the Texture (slow as apparently?)
As an example, I made a loop, loaded 2 (TWO) textures and resize them in the render loop. BTW, the textures are very small.
It slows down from 70 FPS to 50 something..
Every single texture resize slows it down heaps!
I thought there is one way around it. Use more memory.
I'll have to keep the ITexture, and a copy of the original IImage.
Then I'll never have to lock/unlock the Texture.
I was worried about memory, speed,.. and everything. But man, you have to give up one of them. Memory isn't a problem when people have 4GB of RAM on their systems!
Speed matters!
If you keep the image, then you can create new textures from it, resize it, and never have to lock the main (standard sized) texture to do any of it.
But then, if an IImage must also lock itself when you create a texture from it with addTexture() function, then it may be same thing? God No! Please!
It seems not to.