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
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.
/** An ITexture is created by an IVideoDriver by using IVideoDriver::addTexture
or IVideoDriver::getTexture. After that, the texture may only be used by this
......@@ -100,7 +113,7 @@ class ITexture : public virtual IReferenceCounted
public:
//! constructor
ITexture(const io::path& name) : NamedPath(name)
ITexture(const io::path& name) : NamedPath(name), Source(ETS_UNKNOWN)
{
}
......@@ -190,6 +203,12 @@ public:
//! Get name of texture (in most cases this is the filename)
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:
//! Helper function, helps to get the desired texture creation format from the flags.
......@@ -209,6 +228,7 @@ protected:
}
io::SNamedPath NamedPath;
E_TEXTURE_SOURCE Source;
};
......
......@@ -425,12 +425,18 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
ITexture* texture = findTexture(absolutePath);
if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture;
}
// Then try the raw filename, which might be in an Archive
texture = findTexture(filename);
if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture;
}
// Now try to open the file using the complete path.
io::IReadFile* file = FileSystem->createAndOpenFile(absolutePath);
......@@ -447,6 +453,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
texture = findTexture(file->getFileName());
if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
file->drop();
return texture;
}
......@@ -456,6 +463,7 @@ ITexture* CNullDriver::getTexture(const io::path& filename)
if (texture)
{
texture->updateSource(ETS_FROM_FILE);
addTexture(texture);
texture->drop(); // drop it because we created it, one grab too much
}
......@@ -481,12 +489,16 @@ ITexture* CNullDriver::getTexture(io::IReadFile* file)
texture = findTexture(file->getFileName());
if (texture)
{
texture->updateSource(ETS_FROM_CACHE);
return texture;
}
texture = loadTextureFromFile(file);
if (texture)
{
texture->updateSource(ETS_FROM_FILE);
addTexture(texture);
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