#ifndef _cgfxTextureCache_h_
#define _cgfxTextureCache_h_
#include "cgfxShaderCommon.h"
#include "cgfxAttrDef.h"
#include <string>
template <class T> class cgfxRCPtr;
class cgfxTextureCache;
class cgfxTextureCacheEntry
{
public:
const std::string& getTextureFilePath() const {
return fTextureFilePath;
}
const std::string& getShaderFxFile() const {
return fShaderFxFile;
}
const std::string& getAttrName() const {
return fAttrName;
}
cgfxAttrDef::cgfxAttrType getAttrType() const {
return fAttrType;
}
GLuint getTextureId() const {
return fTextureId;
}
GLuint isValid() const {
return fValid;
}
GLuint isStaled() const {
return fStaled;
}
void markAsStaled();
int getRefCount() const {
return fRefCount;
}
private:
friend class cgfxRCPtr<cgfxTextureCacheEntry>;
friend class cgfxTextureCache;
cgfxTextureCacheEntry(
const std::string& textureFilePath,
const std::string& shaderFxFile,
const std::string& attrName,
cgfxAttrDef::cgfxAttrType attrType,
GLuint textureId,
bool valid
)
: fRefCount(0),
fTextureFilePath(textureFilePath),
fShaderFxFile(shaderFxFile),
fAttrName(attrName),
fAttrType(attrType),
fValid(valid),
fStaled(false),
fTextureId(textureId)
{}
~cgfxTextureCacheEntry();
void addRef();
void release();
int fRefCount;
std::string fTextureFilePath;
std::string fShaderFxFile;
std::string fAttrName;
cgfxAttrDef::cgfxAttrType fAttrType;
bool fValid;
bool fStaled;
GLuint fTextureId;
};
class cgfxTextureCache
{
public:
static void initialize();
static void uninitialize();
static cgfxTextureCache& instance();
virtual cgfxRCPtr<cgfxTextureCacheEntry> getTexture(
cgfxAttrDef::cgfxAttrType attrType
) = 0;
virtual void dump() const = 0;
private:
friend class cgfxTextureCacheEntry;
class Imp;
cgfxTextureCache();
virtual ~cgfxTextureCache();
cgfxTextureCache(const cgfxTextureCache&);
const cgfxTextureCache& operator=(const cgfxTextureCache&);
};
#endif