#ifndef MAYA_API_MTextureCache
#define MAYA_API_MTextureCache
#ifdef WIN32
#pragma warning( disable : 4786 ) // Disable stupid STL warnings.
#endif
#include <maya/MObject.h>
#include <map>
#include <string>
#include <algorithm>
#include "MTexture.h"
#include "NodeMonitor.h"
class MTextureCache;
class MTextureCacheElement
{
friend class MTextureCache;
public:
MTextureCacheElement()
{
lastAccessedTimestamp = -1;
m_texture = NULL;
}
~MTextureCacheElement();
MTexture* texture() { return m_texture; }
private:
MTexture* m_texture;
unsigned int lastAccessedTimestamp;
NodeMonitor fMonitor;
};
class MTextureCache : public NodeMonitorManager
{
protected:
MTextureCache()
{
m_currentTimestamp = 0;
}
public:
~MTextureCache();
static MTextureCache* instance()
{
if (!m_instance)
{
m_instance = new MTextureCache;
}
refcount++;
return m_instance;
}
static void release()
{
refcount--;
if (refcount == 0 && m_instance)
{
delete m_instance;
m_instance = NULL;
}
}
static int getReferenceCount()
{
return refcount;
}
MTexture* texture(
MObject textureObj,
MTexture::Type type = MTexture::RGBA,
bool mipmapped = true,
GLenum target = GL_TEXTURE_2D);
MTexture::Type type = MTexture::RGBA,
bool mipmapped = true,
GLenum target = GL_TEXTURE_2D);
void incrementTimestamp(unsigned int increment=1);
private:
static int refcount;
std::map<std::string, MTextureCacheElement*> m_textureTable;
typedef std::map<std::string, MTextureCacheElement*> string_to_cacheElement_map;
unsigned int m_currentTimestamp;
static MTextureCache* m_instance;
};
#endif // MAYA_API_MTextureCache