3 #include "MessageQueue.h"
7 #include <unordered_map>
17 struct MaterialTexturePairing
19 std::string materialName;
25 void SetTextureForMaterial(
const std::string& materialName, GLuint textureID)
27 m_messageQueue.Enqueue(MaterialTexturePairing{ materialName, textureID });
30 GLuint GetTextureForMaterial(
const std::string& materialName)
34 auto it = m_materials.find(materialName);
36 if (it == m_materials.end())
39 it = m_materials.find(materialName);
42 if (it != m_materials.end())
50 void ReleaseTexture(GLuint
id)
52 auto it = m_reverseMaterialMapping.find(
id);
54 if (it == m_reverseMaterialMapping.end())
57 it = m_reverseMaterialMapping.find(
id);
60 if (it != m_reverseMaterialMapping.end())
62 for (
const auto& materialName : it->second)
64 m_materials.erase(materialName);
67 m_reverseMaterialMapping.erase(it);
75 MaterialTexturePairing pairing;
77 while (m_messageQueue.TryDequeue(pairing))
79 m_materials.insert({ pairing.materialName, pairing.textureID });
80 auto existingReverseEntry = m_reverseMaterialMapping.find(pairing.textureID);
82 if (existingReverseEntry != m_reverseMaterialMapping.end())
84 existingReverseEntry->second.push_back(pairing.materialName);
88 m_reverseMaterialMapping.insert({ pairing.textureID, { pairing.materialName } });
94 std::unordered_map<std::string, GLuint> m_materials;
95 std::unordered_map<GLuint, std::vector<std::string>> m_reverseMaterialMapping;