Commit 359ae63b authored by cutealien's avatar cutealien

Add ITexture::getSource which can be used to check where the last...

Add ITexture::getSource which can be used to check where the last IVideoDriver::getTexture call found the texture. Thx @Bobbo for helping me to find a better enum name ;-)


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4705 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 6b4dc7c5
...@@ -86,6 +86,19 @@ enum E_TEXTURE_LOCK_MODE ...@@ -86,6 +86,19 @@ enum E_TEXTURE_LOCK_MODE
ETLM_WRITE_ONLY ETLM_WRITE_ONLY
}; };
//! Where did the last IVideoDriver::getTexture call find this texture
enum E_TEXTURE_SOURCE
{
//! IVideoDriver::getTexture was never called (texture created otherwise)
ETS_UNKNOWN,
//! Texture has been found in cache
ETS_FROM_CACHE,
//! Texture had to be loaded
ETS_FROM_FILE
};
//! Interface of a Video Driver dependent Texture. //! Interface of a Video Driver dependent Texture.
/** An ITexture is created by an IVideoDriver by using IVideoDriver::addTexture /** An ITexture is created by an IVideoDriver by using IVideoDriver::addTexture
or IVideoDriver::getTexture. After that, the texture may only be used by this or IVideoDriver::getTexture. After that, the texture may only be used by this
...@@ -100,7 +113,7 @@ class ITexture : public virtual IReferenceCounted ...@@ -100,7 +113,7 @@ class ITexture : public virtual IReferenceCounted
public: public:
//! constructor //! constructor
ITexture(const io::path& name) : NamedPath(name) ITexture(const io::path& name) : NamedPath(name), Source(ETS_UNKNOWN)
{ {
} }
...@@ -190,6 +203,12 @@ public: ...@@ -190,6 +203,12 @@ public:
//! Get name of texture (in most cases this is the filename) //! Get name of texture (in most cases this is the filename)
const io::SNamedPath& getName() const { return NamedPath; } const io::SNamedPath& getName() const { return NamedPath; }
//! Check where the last IVideoDriver::getTexture found this texture
E_TEXTURE_SOURCE getSource() const { return Source; }
//! Used internally by the engine to update Source status on IVideoDriver::getTexture calls.
void updateSource(E_TEXTURE_SOURCE source) { Source = source; }
protected: protected:
//! Helper function, helps to get the desired texture creation format from the flags. //! Helper function, helps to get the desired texture creation format from the flags.
...@@ -209,6 +228,7 @@ protected: ...@@ -209,6 +228,7 @@ protected:
} }
io::SNamedPath NamedPath; io::SNamedPath NamedPath;
E_TEXTURE_SOURCE Source;
}; };
......
...@@ -425,12 +425,18 @@ ITexture* CNullDriver::getTexture(const io::path& filename) ...@@ -425,12 +425,18 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
ITexture* texture = findTexture(absolutePath); ITexture* texture = findTexture(absolutePath);
if (texture) if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture; return texture;
}
// Then try the raw filename, which might be in an Archive // Then try the raw filename, which might be in an Archive
texture = findTexture(filename); texture = findTexture(filename);
if (texture) if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture; return texture;
}
// Now try to open the file using the complete path. // Now try to open the file using the complete path.
io::IReadFile* file = FileSystem->createAndOpenFile(absolutePath); io::IReadFile* file = FileSystem->createAndOpenFile(absolutePath);
...@@ -447,6 +453,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename) ...@@ -447,6 +453,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
texture = findTexture(file->getFileName()); texture = findTexture(file->getFileName());
if (texture) if (texture)
{ {
texture->updateSource(ETS_FROM_CACHE);
file->drop(); file->drop();
return texture; return texture;
} }
...@@ -456,6 +463,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename) ...@@ -456,6 +463,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
if (texture) if (texture)
{ {
texture->updateSource(ETS_FROM_FILE);
addTexture(texture); addTexture(texture);
texture->drop(); // drop it because we created it, one grab too much texture->drop(); // drop it because we created it, one grab too much
} }
...@@ -481,12 +489,16 @@ ITexture* CNullDriver::getTexture(io::IReadFile* file) ...@@ -481,12 +489,16 @@ ITexture* CNullDriver::getTexture(io::IReadFile* file)
texture = findTexture(file->getFileName()); texture = findTexture(file->getFileName());
if (texture) if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture; return texture;
}
texture = loadTextureFromFile(file); texture = loadTextureFromFile(file);
if (texture) if (texture)
{ {
texture->updateSource(ETS_FROM_FILE);
addTexture(texture); addTexture(texture);
texture->drop(); // drop it because we created it, one grab too much texture->drop(); // drop it because we created it, one grab too much
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment