diff --git a/code/nel/include/nel/3d/texture_bump.h b/code/nel/include/nel/3d/texture_bump.h index 1fb6152de..1c1f2a245 100644 --- a/code/nel/include/nel/3d/texture_bump.h +++ b/code/nel/include/nel/3d/texture_bump.h @@ -84,14 +84,6 @@ protected: float *_NormalizationFactor; bool _DisableSharing; bool _ForceNormalize; - // Map that give the normalization factor for each map from its sharename. This avoid to generate several time the maps to get the normalization factor if a bumpmap is shared by severals CTextureBump instances; - struct CNormalizationInfo - { - uint NumRefs; - float NormalizationFactor; - }; - typedef std::map TNameToNI; // sharename to the normalization factor - static TNameToNI _NameToNF; // name to normalization factor private: /// we don't allow for mipmap for bump so we redefine this to prevent the user from doing this on the base class Itexture virtual void setFilterMode(TMagFilter magf, TMinFilter minf); diff --git a/code/nel/src/3d/texture_bump.cpp b/code/nel/src/3d/texture_bump.cpp index 3707476b2..7705a58fa 100644 --- a/code/nel/src/3d/texture_bump.cpp +++ b/code/nel/src/3d/texture_bump.cpp @@ -26,9 +26,31 @@ namespace NL3D { +namespace /* anonymous */ { -CTextureBump::TNameToNI CTextureBump::_NameToNF; +// Map that give the normalization factor for each map from its sharename. This avoid to generate several time the maps to get the normalization factor if a bumpmap is shared by severals CTextureBump instances; +struct CNormalizationInfo +{ + uint NumRefs; + float NormalizationFactor; +}; +typedef std::map TNameToNI; // sharename to the normalization factor +class CNameToNFStatic { +public: + TNameToNI Map; + bool Initialized; + CNameToNFStatic() : Initialized(true) + { + + } + ~CNameToNFStatic() + { + Initialized = false; + } +}; +CNameToNFStatic s_NameToNF; +} /* anonymous namespace */ #define GET_HGT(x, y) ((sint) ((src[(uint) (x) % width + ((uint) (y) % height) * width] & 0x00ff00) >> 8)) /// create a DsDt texture from a height map (red component of a rgba bitmap) @@ -242,14 +264,15 @@ void CTextureBump::doGenerate(bool async) } // create entry in the map for the normalization factor std::string shareName = getShareName(); - TNameToNI::iterator it = _NameToNF.find(shareName); - if (it == _NameToNF.end()) + nlassertverbose(s_NameToNF.Initialized); + TNameToNI::iterator it = s_NameToNF.Map.find(shareName); + if (it == s_NameToNF.Map.end()) { // create a new entry CNormalizationInfo ni; ni.NumRefs = 1; ni.NormalizationFactor = normalizationFactor; - std::pair pb = _NameToNF.insert(TNameToNI::value_type(shareName, ni)); + std::pair pb = s_NameToNF.Map.insert(TNameToNI::value_type(shareName, ni)); _NormalizationFactor = &(pb.first->second.NormalizationFactor); } else @@ -303,8 +326,9 @@ float CTextureBump::getNormalizationFactor() if (!_HeightMap) return 1.f; // not computed yet, see if another map has computed it std::string shareName = getShareName(); - TNameToNI::iterator it = _NameToNF.find(shareName); - if (it != _NameToNF.end()) + nlassertverbose(s_NameToNF.Initialized); + TNameToNI::iterator it = s_NameToNF.Map.find(shareName); + if (it != s_NameToNF.Map.end()) { _NormalizationFactor = &(it->second.NormalizationFactor); ++(it->second.NumRefs); @@ -320,16 +344,16 @@ float CTextureBump::getNormalizationFactor() ///============================================================================================== CTextureBump::~CTextureBump() { - if (_NormalizationFactor && !_NameToNF.empty()) + if (s_NameToNF.Initialized && _NormalizationFactor && !s_NameToNF.Map.empty()) { // find normalization factor from its name - TNameToNI::iterator it = _NameToNF.find(getShareName()); + TNameToNI::iterator it = s_NameToNF.Map.find(getShareName()); // if found - if (it != _NameToNF.end()) + if (it != s_NameToNF.Map.end()) { // we can delete it only if it's not used anymore - if (--(it->second.NumRefs) == 0) _NameToNF.erase(it); + if (--(it->second.NumRefs) == 0) s_NameToNF.Map.erase(it); } } }