Index: Irrlicht/include/IVideoDriver.h
===================================================================
--- Irrlicht/include/IVideoDriver.h (revision 5189)
+++ Irrlicht/include/IVideoDriver.h (working copy)
@@ -1494,6 +1494,18 @@
*/
virtual void convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,
void* dP, ECOLOR_FORMAT dF) const =0;
+ /**
+ Change who texture is loaded, if "DefferedTextureLoader" is used
+ @getTexture(...) return a FakeTexture type and then cached
+ when DefferedTextureLoader is returned to false, the cache is cleanup
+ and all texture is reloaded at the same address by a driver dependent texture
+ */
+ virtual void setDeferredTextureLoader(bool) = 0;
+
+ /**
+ return the current state of "DefferedTextureLoader"
+ */
+ virtual bool useDeferredTextureLoader() const = 0;
};
} // end namespace video
Index: Irrlicht/source/Irrlicht/CNullDriver.cpp
===================================================================
--- Irrlicht/source/Irrlicht/CNullDriver.cpp (revision 5189)
+++ Irrlicht/source/Irrlicht/CNullDriver.cpp (working copy)
@@ -81,11 +81,65 @@
//! creates a writer which is able to save ppm images
IImageWriter* createImageWriterPPM();
+ FakeTexture::FakeTexture(irr::video::IVideoDriver *driver, IImage* surface,
+ const io::path& name) :
+ ITexture(name), Image(surface), MipData(0), Driver(driver)
+ {
+ Image->grab();
+ }
+ FakeTexture::~FakeTexture()
+ {
+ // Image droped when this object is transformed to a driver dependent texture
+ }
+ void* FakeTexture::lock(E_TEXTURE_LOCK_MODE mode, u32 mipmapLevel) _IRR_OVERRIDE_
+ {
+ return Image->getData();
+ }
+ void FakeTexture::unlock() _IRR_OVERRIDE_
+ {
+ }
+ void FakeTexture::regenerateMipMapLevels(void* data, u32 layer)
+ {
+ Image->setMipMapsData(data, true, false);
+ }
+ const core::dimension2d<u32>& FakeTexture::getOriginalSize() const
+ {
+ return Image->getDimension();
+ }
+ const core::dimension2d<u32>& FakeTexture::getSize() const
+ {
+ return Image->getDimension();
+ }
+ E_DRIVER_TYPE FakeTexture::getDriverType() const
+ {
+ return Driver->getDriverType();
+ };
+ ECOLOR_FORMAT FakeTexture::getColorFormat() const
+ {
+ return Image->getColorFormat();
+ }
+ u32 FakeTexture::getPitch() const
+ {
+ return Image->getPitch();
+ }
+ bool FakeTexture::hasMipMaps() const
+ {
+ return MipData;
+ }
+ bool FakeTexture::hasAlpha() const
+ {
+ return true; /* ??? */
+ }
+ bool FakeTexture::isRenderTarget() const
+ {
+ return false;
+ }
+
//! constructor
CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize)
: SharedRenderTarget(0), CurrentRenderTarget(0), CurrentRenderTargetSize(0, 0), FileSystem(io), MeshManipulator(0),
ViewPort(0, 0, 0, 0), ScreenSize(screenSize), PrimitivesDrawn(0), MinVertexCountForVBO(500),
- TextureCreationFlags(0), OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false)
+ TextureCreationFlags(0), OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false), DeferredLoader(false)
{
#ifdef _DEBUG
setDebugName("CNullDriver");
@@ -231,7 +285,25 @@
removeAllHardwareBuffers();
}
+/**
+Change who texture is loaded, if "DefferedTextureLoader" is used
+@getTexture(...) return a FakeTexture type and then cached
+when DefferedTextureLoader is returned to false, the cache is cleanup
+and all texture is reloaded at the same address by a driver dependent texture
+*/
+void CNullDriver::setDeferredTextureLoader(bool i)
+{
+ DeferredLoader = i;
+}
+/**
+return the current state of "DefferedTextureLoader"
+*/
+bool CNullDriver::useDeferredTextureLoader() const
+{
+ return DeferredLoader;
+}
+
//! Adds an external surface loader to the engine.
void CNullDriver::addExternalImageLoader(IImageLoader* loader)
{
Index: Irrlicht/source/Irrlicht/CNullDriver.h
===================================================================
--- Irrlicht/source/Irrlicht/CNullDriver.h (revision 5189)
+++ Irrlicht/source/Irrlicht/CNullDriver.h (working copy)
@@ -38,6 +38,42 @@
class IImageLoader;
class IImageWriter;
+ class IVideoDriver;
+
+ class FakeTexture : public ITexture
+ {
+ public:
+ FakeTexture(irr::video::IVideoDriver *driver, IImage* surface, const io::path& name);
+
+ virtual ~FakeTexture();
+
+ virtual void* lock(E_TEXTURE_LOCK_MODE mode=ETLM_READ_WRITE, u32 mipmapLevel=0) _IRR_OVERRIDE_;
+
+ virtual void unlock() _IRR_OVERRIDE_;
+
+ virtual void regenerateMipMapLevels(void* data = 0, u32 layer = 0);
+
+ virtual const core::dimension2d<u32>& getOriginalSize() const;
+
+ virtual const core::dimension2d<u32>& getSize() const;
+
+ virtual E_DRIVER_TYPE getDriverType() const;
+
+ virtual ECOLOR_FORMAT getColorFormat() const;
+
+ virtual u32 getPitch() const;
+
+ virtual bool hasMipMaps() const;
+
+ virtual bool hasAlpha() const;
+
+ virtual bool isRenderTarget() const;
+ public:
+ IImage* Image;
+ void* MipData;
+ IVideoDriver* Driver;
+ };
+
class CNullDriver : public IVideoDriver, public IGPUProgrammingServices
{
public:
@@ -669,6 +705,19 @@
const c8* name=0);
virtual bool checkDriverReset() _IRR_OVERRIDE_ {return false;}
+
+ /**
+ Change who texture is loaded, if "DefferedTextureLoader" is used
+ @getTexture(...) return a FakeTexture type and then cached
+ when DefferedTextureLoader is returned to false, the cache is cleanup
+ and all texture is reloaded at the same address by a driver dependent texture
+ */
+ virtual void setDeferredTextureLoader(bool);
+
+ /**
+ return the current state of "DefferedTextureLoader"
+ */
+ virtual bool useDeferredTextureLoader() const;
protected:
//! deletes all textures
@@ -872,6 +921,9 @@
bool RangeFog;
bool AllowZWriteOnTransparent;
+ bool DeferredLoader;
+ core::list<FakeTexture*> CachedDefferedLoader;
+
bool FeatureEnabled[video::EVDF_COUNT];
};
Index: Irrlicht/source/Irrlicht/COpenGLDriver.cpp
===================================================================
--- Irrlicht/source/Irrlicht/COpenGLDriver.cpp (revision 5189)
+++ Irrlicht/source/Irrlicht/COpenGLDriver.cpp (working copy)
@@ -2554,20 +2554,64 @@
//! returns a device dependent texture from a software surface (IImage)
video::ITexture* COpenGLDriver::createDeviceDependentTexture(IImage* surface, const io::path& name)
{
- COpenGLTexture* texture = 0;
+ if(DeferredLoader)
+ {
+ //! sizeof(FakeTexture) < sizeof(COpenGLTexture)
+ video::FakeTexture *tmp = (FakeTexture*) ::operator new (sizeof(COpenGLTexture));
+ new ((void*)tmp) FakeTexture(this, surface, name);
+ CachedDefferedLoader.push_back(tmp);
+ return tmp;
+ }
+ else
+ {
+ COpenGLTexture* texture = 0;
- if (surface && checkColorFormat(surface->getColorFormat(), surface->getDimension()))
- {
- core::array<IImage*> imageArray(1);
- imageArray.push_back(surface);
+ if (surface && checkColorFormat(surface->getColorFormat(), surface->getDimension()))
+ {
+ core::array<IImage*> imageArray(1);
+ imageArray.push_back(surface);
- texture = new COpenGLTexture(name, imageArray, this);
- }
+ texture = new COpenGLTexture(name, imageArray, this);
+ }
- return texture;
+ return texture;
+ }
}
+/**
+Change who texture is loaded, if "DefferedTextureLoader" is used
+@getTexture(...) return a FakeTexture type and then cached
+when DefferedTextureLoader is returned to false, the cache is cleanup
+and all texture is reloaded at the same address by a driver dependent texture
+*/
+void COpenGLDriver::setDeferredTextureLoader(bool i)
+{
+ CNullDriver::setDeferredTextureLoader(i);
+ if(!i)
+ {
+ os::Printer::log("load deferred texture", ELL_WARNING);
+ for(core::list<FakeTexture*>::Iterator it = CachedDefferedLoader.begin();
+ it != CachedDefferedLoader.end(); ++it)
+ {
+ video::FakeTexture *tmp = *it;
+
+ IImage* Image = tmp->Image;
+ void* MipData = tmp->MipData;
+ const io::SNamedPath& name = tmp->getName();
+
+ tmp->~FakeTexture();
+
+ core::array<IImage*> imageArray(1);
+ imageArray.push_back(Image);
+
+ new ((void*)tmp) COpenGLTexture(name, imageArray, this);
+ Image->drop();
+ }
+ CachedDefferedLoader.clear();
+ }
+}
+
//! Sets a material. All 3d drawing functions draw geometry now using this material.
void COpenGLDriver::setMaterial(const SMaterial& material)
{
@@ -4800,7 +4844,7 @@
case ECF_G32R32F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_rg))
{
- internalFormat = GL_RG32F;
+ internalFormat = GL_RG32F;
pixelFormat = GL_RG;
pixelType = GL_FLOAT;
}
@@ -4810,7 +4854,7 @@
case ECF_A32B32G32R32F:
if (queryOpenGLFeature(COpenGLExtensionHandler::IRR_ARB_texture_float))
{
- internalFormat = GL_RGBA32F_ARB;
+ internalFormat = GL_RGBA32F_ARB;
pixelFormat = GL_RGBA;
pixelType = GL_FLOAT;
}
Index: Irrlicht/source/Irrlicht/COpenGLDriver.h
===================================================================
--- Irrlicht/source/Irrlicht/COpenGLDriver.h (revision 5189)
+++ Irrlicht/source/Irrlicht/COpenGLDriver.h (working copy)
@@ -411,6 +411,13 @@
COpenGLCacheHandler* getCacheHandler() const;
+ /**
+ Change who texture is loaded, if "DefferedTextureLoader" is used
+ @getTexture(...) return a FakeTexture type and then cached
+ when DefferedTextureLoader is returned to false, the cache is cleanup
+ and all texture is reloaded at the same address by a driver dependent texture
+ */
+ virtual void setDeferredTextureLoader(bool);
private:
bool updateVertexHardwareBuffer(SHWBufferLink_opengl *HWBuffer);