working on texture manager

This commit is contained in:
Vladislav Khorev committed 2026-05-01 21:00:51 +03:00
1 parent e04fcbb9bd
commit be6a8cca9e
9 files changed
+92 -39

No files matched your search

+49
View File
@@ -416,5 +416,54 @@ namespace ZL
#endif
std::string TextureManager::MakeKey(const std::string& fileName, const std::string& zipFile)
{
return zipFile.empty() ? fileName : fileName + "|" + zipFile;
}
std::shared_ptr<Texture> TextureManager::LoadFromBmp24(const std::string& fileName, const std::string& zipFile)
{
std::string key = MakeKey(fileName, zipFile);
auto it = textureMap.find(key);
if (it != textureMap.end())
return it->second;
auto tex = std::make_shared<Texture>(CreateTextureDataFromBmp24(fileName, zipFile));
textureMap[key] = tex;
return tex;
}
std::shared_ptr<Texture> TextureManager::LoadFromBmp32(const std::string& fileName, const std::string& zipFile)
{
std::string key = MakeKey(fileName, zipFile);
auto it = textureMap.find(key);
if (it != textureMap.end())
return it->second;
auto tex = std::make_shared<Texture>(CreateTextureDataFromBmp32(fileName, zipFile));
textureMap[key] = tex;
return tex;
}
#ifdef PNG_ENABLED
std::shared_ptr<Texture> TextureManager::LoadFromPng(const std::string& fileName, const std::string& zipFile)
{
std::string key = MakeKey(fileName, zipFile);
auto it = textureMap.find(key);
if (it != textureMap.end())
return it->second;
auto tex = std::make_shared<Texture>(CreateTextureDataFromPng(fileName, zipFile));
textureMap[key] = tex;
return tex;
}
#endif
void TextureManager::Unload(const std::string& fileName, const std::string& zipFile)
{
textureMap.erase(MakeKey(fileName, zipFile));
}
void TextureManager::UnloadAll()
{
textureMap.clear();
}
}