4#include <unordered_map>
14using std::unordered_map;
23TextureManager::TextureManager(
Renderer* renderer): mutex(
"texturemanager-mutex") {
37 auto textureManagedIt =
textures.find(
id);
38 if (textureManagedIt !=
textures.end()) {
40 auto textureManaged = textureManagedIt->second;
41 textureManaged->incrementReferenceCounter();
45 return textureManaged;
52 textureManaged->incrementReferenceCounter();
58 return textureManaged;
65 auto rendererId = textureManaged->getRendererId();
68 if (created ==
true) {
76 textureManaged->setUploaded(
true);
87 auto rendererId = textureManaged->getRendererId();
90 if (created ==
true) {
98 textureManaged->setUploaded(
true);
108 auto textureManagedIt =
textures.find(textureId);
109 if (textureManagedIt !=
textures.end()) {
110 auto textureManaged = textureManagedIt->second;
111 if (textureManaged->decrementReferenceCounter()) {
113 auto textureRendererId = textureManaged->getRendererId();
120 delete textureManaged;
129 Console::println(
string(
"Warning: texture not loaded by texture manager"));
const string & getId() const
void removeTexture(const string &textureId)
Removes a texture from manager / open gl stack.
unordered_map< string, TextureManager_TextureManaged * > textures
int32_t addCubeMapTexture(const string &id, Texture *textureLeft, Texture *textureRight, Texture *textureTop, Texture *textureBottom, Texture *textureFront, Texture *textureBack, int contextIdx=0)
Adds a cube map texture to manager.
friend class TextureManager_TextureManaged
~TextureManager()
Destructor.
TextureManager_TextureManaged * addTexture(const string &id, bool &created)
Adds a texture to manager.
virtual void bindCubeMapTexture(int contextIdx, int32_t textureId)=0
Binds a cube map texture with given id or unbinds when using ID_NONE.
virtual int32_t createTexture()=0
Creates a texture.
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
virtual void disposeTexture(int32_t textureId)=0
Dispose a texture.
virtual void uploadTexture(int contextIdx, Texture *texture)=0
Uploads texture data to current bound texture.
virtual void uploadCubeMapTexture(int contextIdx, Texture *textureLeft, Texture *textureRight, Texture *textureTop, Texture *textureBottom, Texture *textureFront, Texture *textureBack)=0
Uploads cube map texture data to current bound texture.
void unlock()
Unlocks this mutex.
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.