Skip to content

Commit c540d7c

Browse files
AhmedAmrNabilAhmedSobhy01
authored andcommitted
fix(model): fix cache key for model texture
1 parent 62ca883 commit c540d7c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/common/model/model.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,10 @@ namespace our {
351351
if (mat->GetTextureCount(type) == 0) return nullptr;
352352
if (mat->GetTexture(type, 0, &path) != AI_SUCCESS) return nullptr;
353353

354-
Texture2D* texture = nullptr;
354+
std::string cacheKey = this->name + "_" + path.C_Str();
355+
Texture2D* texture = AssetLoader<Texture2D>::get(cacheKey);
356+
if (texture) return texture;
357+
355358
if (path.length > 0 && path.data[0] == '*') {
356359
// this is an embedded texture, we can load it directly from memory
357360
const aiTexture* embeddedTexture = scene->GetEmbeddedTexture(path.C_Str());
@@ -387,7 +390,7 @@ namespace our {
387390
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
388391
texture->unbind();
389392

390-
AssetLoader<Texture2D>::add(path.C_Str(), texture);
393+
AssetLoader<Texture2D>::add(cacheKey, texture);
391394
return texture;
392395
}
393396

0 commit comments

Comments
 (0)