| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_ITEXTURES_H ) |
| 23 |
#define INCLUDED_ITEXTURES_H |
| 24 |
|
| 25 |
#include "iimage.h" |
| 26 |
#include "generic/constant.h" |
| 27 |
|
| 28 |
struct qtexture_t; |
| 29 |
|
| 30 |
class LoadImageCallback |
| 31 |
{ |
| 32 |
typedef Image* ( *LoadFunc )( void* environment, const char* name ); |
| 33 |
public: |
| 34 |
void* m_environment; |
| 35 |
LoadFunc m_func; |
| 36 |
|
| 37 |
LoadImageCallback( void* environment, LoadFunc func ) : m_environment( environment ), m_func( func ){ |
| 38 |
} |
| 39 |
Image* loadImage( const char* name ) const { |
| 40 |
return m_func( m_environment, name ); |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
inline bool operator==( const LoadImageCallback& self, const LoadImageCallback& other ){ |
| 45 |
return self.m_environment == other.m_environment && self.m_func == other.m_func; |
| 46 |
} |
| 47 |
inline bool operator<( const LoadImageCallback& self, const LoadImageCallback& other ){ |
| 48 |
return self.m_environment < other.m_environment || |
| 49 |
( !( other.m_environment < self.m_environment ) && self.m_func < other.m_func ); |
| 50 |
} |
| 51 |
|
| 52 |
class TexturesCacheObserver |
| 53 |
{ |
| 54 |
public: |
| 55 |
virtual void unrealise() = 0; |
| 56 |
virtual void realise() = 0; |
| 57 |
}; |
| 58 |
|
| 59 |
class TexturesCache |
| 60 |
{ |
| 61 |
public: |
| 62 |
virtual ~TexturesCache() = default; |
| 63 |
INTEGER_CONSTANT( Version, 1 ); |
| 64 |
STRING_CONSTANT( Name, "textures" ); |
| 65 |
virtual LoadImageCallback defaultLoader() const = 0; |
| 66 |
virtual Image* loadImage( const char* name ) = 0; |
| 67 |
virtual qtexture_t* capture( const char* name ) = 0; |
| 68 |
virtual qtexture_t* capture( const LoadImageCallback& load, const char* name ) = 0; |
| 69 |
virtual void release( qtexture_t* texture ) = 0; |
| 70 |
virtual void attach( TexturesCacheObserver& observer ) = 0; |
| 71 |
virtual void detach( TexturesCacheObserver& observer ) = 0; |
| 72 |
}; |
| 73 |
|
| 74 |
#include "modulesystem.h" |
| 75 |
|
| 76 |
template<typename Type> |
| 77 |
class GlobalModule; |
| 78 |
typedef GlobalModule<TexturesCache> GlobalTexturesModule; |
| 79 |
|
| 80 |
template<typename Type> |
| 81 |
class GlobalModuleRef; |
| 82 |
typedef GlobalModuleRef<TexturesCache> GlobalTexturesModuleRef; |
| 83 |
|
| 84 |
inline TexturesCache& GlobalTexturesCache(){ |
| 85 |
return GlobalTexturesModule::getTable(); |
| 86 |
} |
| 87 |
|
| 88 |
#endif |