So, I decided to mix and match the constructor and destructor of irr::video::C3D9Texture to make a reload function. I have plans to expand it to OpenGL and potentially the other drivers eventually. Also, I made this in about 30 minutes, so no guarantees on stability. I know almost for sure that it won't like it if you reload a texture loaded from an archive.
Here's the diff:
Code: Select all
diff -r 773c89d96480 include/ITexture.h
--- a/include/ITexture.h Tue Mar 16 01:22:23 2010 -0500
+++ b/include/ITexture.h Thu Apr 08 13:59:50 2010 -0500
@@ -158,6 +158,9 @@
//! Get name of texture (in most cases this is the filename)
const io::SNamedPath& getName() const { return NamedPath; }
+
+ //!Reload the texture from disk
+ virtual void reload() {}
protected:
diff -r 773c89d96480 source/Irrlicht/CD3D9Texture.cpp
--- a/source/Irrlicht/CD3D9Texture.cpp Tue Mar 16 01:22:23 2010 -0500
+++ b/source/Irrlicht/CD3D9Texture.cpp Thu Apr 08 13:59:50 2010 -0500
@@ -53,7 +53,7 @@
u32 flags, const io::path& name, void* mipmapData)
: ITexture(name), Texture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
TextureSize(0,0), ImageSize(0,0), Pitch(0), ColorFormat(ECF_UNKNOWN),
- HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
+ HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false), creationFlags(flags)
{
#ifdef _DEBUG
setDebugName("CD3D9Texture");
@@ -102,6 +102,49 @@
Device->Release();
}
+//!Reload the texture from disk
+void CD3D9Texture::reload()
+{
+ //Pre-Creation
+ if (IsRenderTarget)
+ {
+ os::Printer::log("Can't reload a RTT!",ELL_WARNING);
+ return;
+ }
+ os::Printer::log("Reloading DIRECT3D9 Texture!");
+
+ IImage* image = Driver->createImageFromFile(NamedPath);
+ if (!image)
+ {
+ os::Printer::log("Could not reload the image!",ELL_ERROR);
+ return;
+ }
+
+ //Destruction
+ if (Texture) {Texture->Release();}
+ if (RTTSurface) {RTTSurface->Release();}
+ //Not sure if I need to do that depth buffer thing
+ if (Device) {Device->Release();}
+
+ //Creation
+ //We should be able to safely skip over 99% of the rubbish constructor init list stuff
+ Device = Driver->getExposedVideoData().D3D9.D3DDev9;
+ if (Device) {Device->AddRef();}
+
+ if (createTexture(creationFlags,image))
+ {
+ if (copyTexture(image))
+ {
+ regenerateMipMapLevels(0);
+ }
+ }
+ else
+ {
+ os::Printer::log("Could not recreate DIRECT3D9 Texture.", ELL_WARNING);
+ }
+ image->drop();
+}
+
void CD3D9Texture::createRenderTarget(const ECOLOR_FORMAT format)
{
diff -r 773c89d96480 source/Irrlicht/CD3D9Texture.h
--- a/source/Irrlicht/CD3D9Texture.h Tue Mar 16 01:22:23 2010 -0500
+++ b/source/Irrlicht/CD3D9Texture.h Thu Apr 08 13:59:50 2010 -0500
@@ -74,6 +74,9 @@
//! Returns pointer to the render target surface
IDirect3DSurface9* getRenderTargetSurface();
+
+ //!Reload the texture from disk
+ virtual void reload();
private:
friend class CD3D9Driver;
@@ -114,6 +117,7 @@
bool HasMipMaps;
bool HardwareMipMaps;
bool IsRenderTarget;
+ irr::u32 creationFlags;
};
Also, this is for Irrlicht 1.7 (Non SVN) the diff was made by our Mercurial repo we keep Irrlicht in.
~David