summaryrefslogtreecommitdiffstats
path: root/AssetLoader/src/GLTFLoader.cpp
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-11-05 00:30:51 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-11-05 00:30:51 +0000
commit150b73541c5f60dc291749deacb6ddec57cc25a2 (patch)
treed7356f3259d8e9b34013bd15029dfdc7d8db7ccb /AssetLoader/src/GLTFLoader.cpp
parentImGuiDiligentRenderer: added MSL shaders (diff)
downloadDiligentTools-150b73541c5f60dc291749deacb6ddec57cc25a2.tar.gz
DiligentTools-150b73541c5f60dc291749deacb6ddec57cc25a2.zip
GLTFLoader: made texture cache thread-safe
Diffstat (limited to 'AssetLoader/src/GLTFLoader.cpp')
-rw-r--r--AssetLoader/src/GLTFLoader.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/AssetLoader/src/GLTFLoader.cpp b/AssetLoader/src/GLTFLoader.cpp
index e573963..7f64a27 100644
--- a/AssetLoader/src/GLTFLoader.cpp
+++ b/AssetLoader/src/GLTFLoader.cpp
@@ -651,8 +651,10 @@ void Model::LoadTextures(IRenderDevice* pDevice,
RefCntAutoPtr<ITexture> pTexture;
if (pTextureCache != nullptr)
{
- auto it = pTextureCache->find(BaseDir + gltf_image.uri);
- if (it != pTextureCache->end())
+ std::lock_guard<std::mutex> Lock{pTextureCache->TexturesMtx};
+
+ auto it = pTextureCache->Textures.find(BaseDir + gltf_image.uri);
+ if (it != pTextureCache->Textures.end())
{
pTexture = it->second.Lock();
if (!pTexture)
@@ -667,7 +669,7 @@ void Model::LoadTextures(IRenderDevice* pDevice,
}
else
{
- pTextureCache->erase(it);
+ pTextureCache->Textures.erase(it);
}
}
}
@@ -719,7 +721,8 @@ void Model::LoadTextures(IRenderDevice* pDevice,
if (pTextureCache != nullptr)
{
- pTextureCache->emplace(BaseDir + gltf_image.uri, pTexture);
+ std::lock_guard<std::mutex> Lock{pTextureCache->TexturesMtx};
+ pTextureCache->Textures.emplace(BaseDir + gltf_image.uri, pTexture);
}
}
@@ -1140,8 +1143,12 @@ bool LoadImageData(tinygltf::Image* gltf_image,
auto* pLoaderData = reinterpret_cast<ImageLoaderData*>(user_data);
if (pLoaderData != nullptr && pLoaderData->pTextureCache != nullptr)
{
- auto it = pLoaderData->pTextureCache->find(pLoaderData->BaseDir + gltf_image->uri);
- if (it != pLoaderData->pTextureCache->end())
+ auto& TexCache = *pLoaderData->pTextureCache;
+
+ std::lock_guard<std::mutex> Lock{TexCache.TexturesMtx};
+
+ auto it = TexCache.Textures.find(pLoaderData->BaseDir + gltf_image->uri);
+ if (it != TexCache.Textures.end())
{
if (auto pTexture = it->second.Lock())
{
@@ -1162,7 +1169,7 @@ bool LoadImageData(tinygltf::Image* gltf_image,
else
{
// Texture is stale - remove it from the cache
- pLoaderData->pTextureCache->erase(it);
+ TexCache.Textures.erase(it);
}
}
}