- assimpview: reuse textures to minimize memory usage. This may break editing stuff, but I'll fix this asap.
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1168 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/5/head
parent
4ebba5bdd4
commit
23c16a3ef9
|
@ -330,6 +330,14 @@ int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
|
||||||
|
|
||||||
*p_ppiOut = NULL;
|
*p_ppiOut = NULL;
|
||||||
|
|
||||||
|
const std::string s = szPath->data;
|
||||||
|
TextureCache::iterator ff;
|
||||||
|
if ((ff = sCachedTextures.find(s)) != sCachedTextures.end()) {
|
||||||
|
*p_ppiOut = (*ff).second;
|
||||||
|
(*p_ppiOut)->AddRef();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// first get a valid path to the texture
|
// first get a valid path to the texture
|
||||||
if( 5 == FindValidPath(szPath))
|
if( 5 == FindValidPath(szPath))
|
||||||
{
|
{
|
||||||
|
@ -398,6 +406,8 @@ int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
|
||||||
(*p_ppiOut)->UnlockRect(0);
|
(*p_ppiOut)->UnlockRect(0);
|
||||||
(*p_ppiOut)->GenerateMipSubLevels();
|
(*p_ppiOut)->GenerateMipSubLevels();
|
||||||
}
|
}
|
||||||
|
sCachedTextures[s] = *p_ppiOut;
|
||||||
|
(*p_ppiOut)->AddRef();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -435,6 +445,9 @@ int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath)
|
||||||
|
|
||||||
this->SetDefaultTexture(p_ppiOut);
|
this->SetDefaultTexture(p_ppiOut);
|
||||||
}
|
}
|
||||||
|
sCachedTextures[s] = *p_ppiOut;
|
||||||
|
(*p_ppiOut)->AddRef();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------
|
||||||
|
|
|
@ -60,6 +60,7 @@ private:
|
||||||
if (sDefaultTexture) {
|
if (sDefaultTexture) {
|
||||||
sDefaultTexture->Release();
|
sDefaultTexture->Release();
|
||||||
}
|
}
|
||||||
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -145,6 +146,10 @@ public:
|
||||||
inline void Reset()
|
inline void Reset()
|
||||||
{
|
{
|
||||||
this->m_iShaderCount = 0;
|
this->m_iShaderCount = 0;
|
||||||
|
for (TextureCache::iterator it = sCachedTextures.begin(); it != sCachedTextures.end(); ++it) {
|
||||||
|
(*it).second->Release();
|
||||||
|
}
|
||||||
|
sCachedTextures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -190,6 +195,8 @@ private:
|
||||||
unsigned int m_iShaderCount;
|
unsigned int m_iShaderCount;
|
||||||
IDirect3DTexture9* sDefaultTexture;
|
IDirect3DTexture9* sDefaultTexture;
|
||||||
|
|
||||||
|
typedef std::map<std::string,IDirect3DTexture9*> TextureCache;
|
||||||
|
TextureCache sCachedTextures;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //!! include guard
|
#endif //!! include guard
|
||||||
|
|
Loading…
Reference in New Issue