Material.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "Context.h"
  24. #include "FileSystem.h"
  25. #include "Graphics.h"
  26. #include "Log.h"
  27. #include "Material.h"
  28. #include "MaterialShaderParameterAnimationInstance.h"
  29. #include "Matrix3x4.h"
  30. #include "Profiler.h"
  31. #include "ResourceCache.h"
  32. #include "Technique.h"
  33. #include "Texture2D.h"
  34. #include "TextureCube.h"
  35. #include "XMLFile.h"
  36. #include "DebugNew.h"
  37. namespace Urho3D
  38. {
  39. static const char* textureUnitNames[] =
  40. {
  41. "diffuse",
  42. "normal",
  43. "specular",
  44. "emissive",
  45. "environment",
  46. "lightramp",
  47. "lightshape",
  48. "shadowmap",
  49. "faceselect",
  50. "indirection",
  51. "depth",
  52. "light",
  53. "volume",
  54. 0
  55. };
  56. static const char* cullModeNames[] =
  57. {
  58. "none",
  59. "ccw",
  60. "cw",
  61. 0
  62. };
  63. TextureUnit ParseTextureUnitName(String name)
  64. {
  65. name = name.ToLower().Trimmed();
  66. TextureUnit unit = (TextureUnit)GetStringListIndex(name.CString(), textureUnitNames, MAX_TEXTURE_UNITS);
  67. if (unit == MAX_TEXTURE_UNITS)
  68. {
  69. // Check also for shorthand names
  70. if (name == "diff")
  71. unit = TU_DIFFUSE;
  72. else if (name == "albedo")
  73. unit = TU_DIFFUSE;
  74. else if (name == "norm")
  75. unit = TU_NORMAL;
  76. else if (name == "spec")
  77. unit = TU_SPECULAR;
  78. else if (name == "env")
  79. unit = TU_ENVIRONMENT;
  80. // Finally check for specifying the texture unit directly as a number
  81. else if (name.Length() < 3)
  82. unit = (TextureUnit)Clamp(ToInt(name), 0, MAX_TEXTURE_UNITS);
  83. }
  84. if (unit == MAX_TEXTURE_UNITS)
  85. LOGERROR("Unknown texture unit name " + name);
  86. return unit;
  87. }
  88. static TechniqueEntry noEntry;
  89. bool CompareTechniqueEntries(const TechniqueEntry& lhs, const TechniqueEntry& rhs)
  90. {
  91. if (lhs.lodDistance_ != rhs.lodDistance_)
  92. return lhs.lodDistance_ > rhs.lodDistance_;
  93. else
  94. return lhs.qualityLevel_ > rhs.qualityLevel_;
  95. }
  96. TechniqueEntry::TechniqueEntry() :
  97. qualityLevel_(0),
  98. lodDistance_(0.0f)
  99. {
  100. }
  101. TechniqueEntry::TechniqueEntry(Technique* tech, unsigned qualityLevel, float lodDistance) :
  102. technique_(tech),
  103. qualityLevel_(qualityLevel),
  104. lodDistance_(lodDistance)
  105. {
  106. }
  107. TechniqueEntry::~TechniqueEntry()
  108. {
  109. }
  110. Material::Material(Context* context) :
  111. Resource(context),
  112. auxViewFrameNumber_(0),
  113. occlusion_(true),
  114. specular_(false),
  115. frameNumber_(0)
  116. {
  117. ResetToDefaults();
  118. }
  119. Material::~Material()
  120. {
  121. }
  122. void Material::RegisterObject(Context* context)
  123. {
  124. context->RegisterFactory<Material>();
  125. }
  126. bool Material::Load(Deserializer& source)
  127. {
  128. PROFILE(LoadMaterial);
  129. // In headless mode, do not actually load the material, just return success
  130. Graphics* graphics = GetSubsystem<Graphics>();
  131. if (!graphics)
  132. return true;
  133. SharedPtr<XMLFile> xml(new XMLFile(context_));
  134. if (!xml->Load(source))
  135. {
  136. ResetToDefaults();
  137. return false;
  138. }
  139. XMLElement rootElem = xml->GetRoot();
  140. return Load(rootElem);
  141. }
  142. bool Material::Save(Serializer& dest) const
  143. {
  144. SharedPtr<XMLFile> xml(new XMLFile(context_));
  145. XMLElement materialElem = xml->CreateRoot("material");
  146. Save(materialElem);
  147. return xml->Save(dest);
  148. }
  149. bool Material::Load(const XMLElement& source)
  150. {
  151. ResetToDefaults();
  152. if (source.IsNull())
  153. {
  154. LOGERROR("Can not load material from null XML element");
  155. return false;
  156. }
  157. ResourceCache* cache = GetSubsystem<ResourceCache>();
  158. XMLElement techniqueElem = source.GetChild("technique");
  159. techniques_.Clear();
  160. while (techniqueElem)
  161. {
  162. Technique* tech = cache->GetResource<Technique>(techniqueElem.GetAttribute("name"));
  163. if (tech)
  164. {
  165. TechniqueEntry newTechnique;
  166. newTechnique.technique_ = tech;
  167. if (techniqueElem.HasAttribute("quality"))
  168. newTechnique.qualityLevel_ = techniqueElem.GetInt("quality");
  169. if (techniqueElem.HasAttribute("loddistance"))
  170. newTechnique.lodDistance_ = techniqueElem.GetFloat("loddistance");
  171. techniques_.Push(newTechnique);
  172. }
  173. techniqueElem = techniqueElem.GetNext("technique");
  174. }
  175. SortTechniques();
  176. XMLElement textureElem = source.GetChild("texture");
  177. while (textureElem)
  178. {
  179. TextureUnit unit = TU_DIFFUSE;
  180. if (textureElem.HasAttribute("unit"))
  181. unit = ParseTextureUnitName(textureElem.GetAttribute("unit"));
  182. if (unit < MAX_MATERIAL_TEXTURE_UNITS)
  183. {
  184. String name = textureElem.GetAttribute("name");
  185. // Detect cube maps by file extension: they are defined by an XML file
  186. if (GetExtension(name) == ".xml")
  187. SetTexture(unit, cache->GetResource<TextureCube>(name));
  188. else
  189. SetTexture(unit, cache->GetResource<Texture2D>(name));
  190. }
  191. textureElem = textureElem.GetNext("texture");
  192. }
  193. XMLElement parameterElem = source.GetChild("parameter");
  194. while (parameterElem)
  195. {
  196. String name = parameterElem.GetAttribute("name");
  197. SetShaderParameter(name, ParseShaderParameterValue(parameterElem.GetAttribute("value")));
  198. parameterElem = parameterElem.GetNext("parameter");
  199. }
  200. XMLElement cullElem = source.GetChild("cull");
  201. if (cullElem)
  202. SetCullMode((CullMode)GetStringListIndex(cullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW));
  203. XMLElement shadowCullElem = source.GetChild("shadowcull");
  204. if (shadowCullElem)
  205. SetShadowCullMode((CullMode)GetStringListIndex(shadowCullElem.GetAttribute("value").CString(), cullModeNames, CULL_CCW));
  206. XMLElement depthBiasElem = source.GetChild("depthbias");
  207. if (depthBiasElem)
  208. SetDepthBias(BiasParameters(depthBiasElem.GetFloat("constant"), depthBiasElem.GetFloat("slopescaled")));
  209. // Calculate memory use
  210. RefreshMemoryUse();
  211. CheckOcclusion();
  212. return true;
  213. }
  214. bool Material::Save(XMLElement& dest) const
  215. {
  216. if (dest.IsNull())
  217. {
  218. LOGERROR("Can not save material to null XML element");
  219. return false;
  220. }
  221. // Write techniques
  222. for (unsigned i = 0; i < techniques_.Size(); ++i)
  223. {
  224. const TechniqueEntry& entry = techniques_[i];
  225. if (!entry.technique_)
  226. continue;
  227. XMLElement techniqueElem = dest.CreateChild("technique");
  228. techniqueElem.SetString("name", entry.technique_->GetName());
  229. techniqueElem.SetInt("quality", entry.qualityLevel_);
  230. techniqueElem.SetFloat("loddistance", entry.lodDistance_);
  231. }
  232. // Write texture units
  233. for (unsigned j = 0; j < MAX_MATERIAL_TEXTURE_UNITS; ++j)
  234. {
  235. Texture* texture = GetTexture((TextureUnit)j);
  236. if (texture)
  237. {
  238. XMLElement textureElem = dest.CreateChild("texture");
  239. textureElem.SetString("unit", textureUnitNames[j]);
  240. textureElem.SetString("name", texture->GetName());
  241. }
  242. }
  243. // Write shader parameters
  244. for (HashMap<StringHash, MaterialShaderParameter>::ConstIterator j = shaderParameters_.Begin(); j != shaderParameters_.End(); ++j)
  245. {
  246. XMLElement parameterElem = dest.CreateChild("parameter");
  247. parameterElem.SetString("name", j->second_.name_);
  248. parameterElem.SetVectorVariant("value", j->second_.value_);
  249. }
  250. // Write culling modes
  251. XMLElement cullElem = dest.CreateChild("cull");
  252. cullElem.SetString("value", cullModeNames[cullMode_]);
  253. XMLElement shadowCullElem = dest.CreateChild("shadowcull");
  254. shadowCullElem.SetString("value", cullModeNames[shadowCullMode_]);
  255. // Write depth bias
  256. XMLElement depthBiasElem = dest.CreateChild("depthbias");
  257. depthBiasElem.SetFloat("constant", depthBias_.constantBias_);
  258. depthBiasElem.SetFloat("slopescaled", depthBias_.slopeScaledBias_);
  259. return true;
  260. }
  261. void Material::SetNumTechniques(unsigned num)
  262. {
  263. if (!num)
  264. return;
  265. techniques_.Resize(num);
  266. RefreshMemoryUse();
  267. }
  268. void Material::SetTechnique(unsigned index, Technique* tech, unsigned qualityLevel, float lodDistance)
  269. {
  270. if (index >= techniques_.Size())
  271. return;
  272. techniques_[index] = TechniqueEntry(tech, qualityLevel, lodDistance);
  273. CheckOcclusion();
  274. }
  275. void Material::SetShaderParameter(const String& name, const Variant& value)
  276. {
  277. MaterialShaderParameter newParam;
  278. newParam.name_ = name;
  279. newParam.value_ = value;
  280. StringHash nameHash(name);
  281. shaderParameters_[nameHash] = newParam;
  282. if (nameHash == PSP_MATSPECCOLOR)
  283. {
  284. VariantType type = value.GetType();
  285. if (type == VAR_VECTOR3)
  286. {
  287. const Vector3& vec = value.GetVector3();
  288. specular_ = vec.x_ > 0.0f || vec.y_ > 0.0f || vec.z_ > 0.0f;
  289. }
  290. else if (type == VAR_VECTOR4)
  291. {
  292. const Vector4& vec = value.GetVector4();
  293. specular_ = vec.x_ > 0.0f || vec.y_ > 0.0f || vec.z_ > 0.0f;
  294. }
  295. }
  296. RefreshMemoryUse();
  297. }
  298. void Material::SetShaderParameterAnimation(const String& name, ValueAnimation* animation, WrapMode wrapMode, float speed)
  299. {
  300. if (shaderParameters_.Find(name) == shaderParameters_.End())
  301. return;
  302. materialShaderParameterAnimationInstances_[name] = new MaterialShaderParameterAnimationInstance(this, name, animation, wrapMode, speed);
  303. }
  304. void Material::SetShaderParameterAnimationWrapMode(const String& name, WrapMode wrapMode)
  305. {
  306. MaterialShaderParameterAnimationInstance* instance = GetMaterialShaderParameterAnimationInstance(name);
  307. if (instance)
  308. instance->SetWrapMode(wrapMode);
  309. }
  310. void Material::SetShaderParameterAnimationSpeed(const String& name, float speed)
  311. {
  312. MaterialShaderParameterAnimationInstance* instance = GetMaterialShaderParameterAnimationInstance(name);
  313. if (instance)
  314. instance->SetSpeed(speed);
  315. }
  316. void Material::SetTexture(TextureUnit unit, Texture* texture)
  317. {
  318. if (unit < MAX_MATERIAL_TEXTURE_UNITS)
  319. textures_[unit] = texture;
  320. }
  321. void Material::SetUVTransform(const Vector2& offset, float rotation, const Vector2& repeat)
  322. {
  323. Matrix3x4 transform(Matrix3x4::IDENTITY);
  324. transform.m00_ = repeat.x_;
  325. transform.m11_ = repeat.y_;
  326. transform.m03_ = -0.5f * transform.m00_ + 0.5f;
  327. transform.m13_ = -0.5f * transform.m11_ + 0.5f;
  328. Matrix3x4 rotationMatrix(Matrix3x4::IDENTITY);
  329. rotationMatrix.m00_ = Cos(rotation);
  330. rotationMatrix.m01_ = Sin(rotation);
  331. rotationMatrix.m10_ = -rotationMatrix.m01_;
  332. rotationMatrix.m11_ = rotationMatrix.m00_;
  333. rotationMatrix.m03_ = 0.5f - 0.5f * (rotationMatrix.m00_ + rotationMatrix.m01_);
  334. rotationMatrix.m13_ = 0.5f - 0.5f * (rotationMatrix.m10_ + rotationMatrix.m11_);
  335. transform = rotationMatrix * transform;
  336. Matrix3x4 offsetMatrix = Matrix3x4::IDENTITY;
  337. offsetMatrix.m03_ = offset.x_;
  338. offsetMatrix.m13_ = offset.y_;
  339. transform = offsetMatrix * transform;
  340. SetShaderParameter("UOffset", Vector4(transform.m00_, transform.m01_, transform.m02_, transform.m03_));
  341. SetShaderParameter("VOffset", Vector4(transform.m10_, transform.m11_, transform.m12_, transform.m13_));
  342. }
  343. void Material::SetUVTransform(const Vector2& offset, float rotation, float repeat)
  344. {
  345. SetUVTransform(offset, rotation, Vector2(repeat, repeat));
  346. }
  347. void Material::SetCullMode(CullMode mode)
  348. {
  349. cullMode_ = mode;
  350. }
  351. void Material::SetShadowCullMode(CullMode mode)
  352. {
  353. shadowCullMode_ = mode;
  354. }
  355. void Material::SetDepthBias(const BiasParameters& parameters)
  356. {
  357. depthBias_ = parameters;
  358. depthBias_.Validate();
  359. }
  360. void Material::RemoveShaderParameter(const String& name)
  361. {
  362. StringHash nameHash(name);
  363. shaderParameters_.Erase(nameHash);
  364. if (nameHash == PSP_MATSPECCOLOR)
  365. specular_ = false;
  366. RefreshMemoryUse();
  367. }
  368. void Material::ReleaseShaders()
  369. {
  370. for (unsigned i = 0; i < techniques_.Size(); ++i)
  371. {
  372. Technique* tech = techniques_[i].technique_;
  373. if (tech)
  374. tech->ReleaseShaders();
  375. }
  376. }
  377. SharedPtr<Material> Material::Clone(const String& cloneName) const
  378. {
  379. SharedPtr<Material> ret(new Material(context_));
  380. ret->SetName(cloneName);
  381. ret->techniques_ = techniques_;
  382. ret->shaderParameters_ = shaderParameters_;
  383. for (unsigned i = 0; i < MAX_MATERIAL_TEXTURE_UNITS; ++i)
  384. ret->textures_[i] = textures_[i];
  385. ret->occlusion_ = occlusion_;
  386. ret->specular_ = specular_;
  387. ret->cullMode_ = cullMode_;
  388. ret->shadowCullMode_ = shadowCullMode_;
  389. ret->RefreshMemoryUse();
  390. return ret;
  391. }
  392. void Material::SortTechniques()
  393. {
  394. Sort(techniques_.Begin(), techniques_.End(), CompareTechniqueEntries);
  395. }
  396. void Material::MarkForAuxView(unsigned frameNumber)
  397. {
  398. auxViewFrameNumber_ = frameNumber;
  399. }
  400. void Material::UpdateShaderParameterAnimations()
  401. {
  402. if (materialShaderParameterAnimationInstances_.Empty())
  403. return;
  404. Time* time = GetSubsystem<Time>();
  405. if (time->GetFrameNumber() == frameNumber_)
  406. return;
  407. frameNumber_ = time->GetFrameNumber();
  408. float timeStep = time->GetTimeStep();
  409. Vector<String> finishedNames;
  410. for (HashMap<StringHash, SharedPtr<MaterialShaderParameterAnimationInstance> >::ConstIterator i = materialShaderParameterAnimationInstances_.Begin(); i != materialShaderParameterAnimationInstances_.End(); ++i)
  411. {
  412. if (i->second_->Update(timeStep))
  413. finishedNames.Push(i->second_->GetName());
  414. }
  415. // Remove finished animation
  416. for (unsigned i = 0; i < finishedNames.Size(); ++i)
  417. SetShaderParameterAnimation(finishedNames[i], 0);
  418. }
  419. const TechniqueEntry& Material::GetTechniqueEntry(unsigned index) const
  420. {
  421. return index < techniques_.Size() ? techniques_[index] : noEntry;
  422. }
  423. Technique* Material::GetTechnique(unsigned index) const
  424. {
  425. return index < techniques_.Size() ? techniques_[index].technique_ : (Technique*)0;
  426. }
  427. Pass* Material::GetPass(unsigned index, StringHash passType) const
  428. {
  429. Technique* tech = index < techniques_.Size() ? techniques_[index].technique_ : (Technique*)0;
  430. return tech ? tech->GetPass(passType) : 0;
  431. }
  432. Texture* Material::GetTexture(TextureUnit unit) const
  433. {
  434. return unit < MAX_MATERIAL_TEXTURE_UNITS ? textures_[unit] : (Texture*)0;
  435. }
  436. const Variant& Material::GetShaderParameter(const String& name) const
  437. {
  438. HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = shaderParameters_.Find(name);
  439. return i != shaderParameters_.End() ? i->second_.value_ : Variant::EMPTY;
  440. }
  441. ValueAnimation* Material::GetShaderParameterAnimation(const String& name) const
  442. {
  443. MaterialShaderParameterAnimationInstance* instance = GetMaterialShaderParameterAnimationInstance(name);
  444. return instance == 0 ? 0 : instance->GetAnimation();
  445. }
  446. WrapMode Material::GetShaderParameterAnimationWrapMode(const String& name) const
  447. {
  448. MaterialShaderParameterAnimationInstance* instance = GetMaterialShaderParameterAnimationInstance(name);
  449. return instance == 0 ? WM_LOOP : instance->GetWrapMode();
  450. }
  451. float Material::GetShaderParameterAnimationSpeed(const String& name) const
  452. {
  453. MaterialShaderParameterAnimationInstance* instance = GetMaterialShaderParameterAnimationInstance(name);
  454. return instance == 0 ? 0 : instance->GetSpeed();
  455. }
  456. String Material::GetTextureUnitName(TextureUnit unit)
  457. {
  458. return textureUnitNames[unit];
  459. }
  460. Variant Material::ParseShaderParameterValue(const String& value)
  461. {
  462. String valueTrimmed = value.Trimmed();
  463. if (valueTrimmed.Length() && IsAlpha(valueTrimmed[0]))
  464. return Variant(ToBool(valueTrimmed));
  465. else
  466. return ToVectorVariant(valueTrimmed);
  467. }
  468. void Material::CheckOcclusion()
  469. {
  470. // Determine occlusion by checking the base pass of each technique
  471. occlusion_ = false;
  472. for (unsigned i = 0; i < techniques_.Size(); ++i)
  473. {
  474. Technique* tech = techniques_[i].technique_;
  475. if (tech)
  476. {
  477. Pass* pass = tech->GetPass(PASS_BASE);
  478. if (pass && pass->GetDepthWrite() && !pass->GetAlphaMask())
  479. occlusion_ = true;
  480. }
  481. }
  482. }
  483. void Material::ResetToDefaults()
  484. {
  485. SetNumTechniques(1);
  486. SetTechnique(0, GetSubsystem<ResourceCache>()->GetResource<Technique>("Techniques/NoTexture.xml"));
  487. for (unsigned i = 0; i < MAX_MATERIAL_TEXTURE_UNITS; ++i)
  488. textures_[i] = 0;
  489. shaderParameters_.Clear();
  490. SetShaderParameter("UOffset", Vector4(1.0f, 0.0f, 0.0f, 0.0f));
  491. SetShaderParameter("VOffset", Vector4(0.0f, 1.0f, 0.0f, 0.0f));
  492. SetShaderParameter("MatDiffColor", Vector4::ONE);
  493. SetShaderParameter("MatEmissiveColor", Vector3::ZERO);
  494. SetShaderParameter("MatEnvMapColor", Vector3::ONE);
  495. SetShaderParameter("MatSpecColor", Vector4(0.0f, 0.0f, 0.0f, 1.0f));
  496. cullMode_ = CULL_CCW;
  497. shadowCullMode_ = CULL_CCW;
  498. depthBias_ = BiasParameters(0.0f, 0.0f);
  499. RefreshMemoryUse();
  500. }
  501. void Material::RefreshMemoryUse()
  502. {
  503. unsigned memoryUse = sizeof(Material);
  504. memoryUse += techniques_.Size() * sizeof(TechniqueEntry);
  505. memoryUse += MAX_MATERIAL_TEXTURE_UNITS * sizeof(SharedPtr<Texture>);
  506. memoryUse += shaderParameters_.Size() * sizeof(MaterialShaderParameter);
  507. SetMemoryUse(memoryUse);
  508. }
  509. MaterialShaderParameterAnimationInstance* Material::GetMaterialShaderParameterAnimationInstance(const String& name) const
  510. {
  511. HashMap<StringHash, SharedPtr<MaterialShaderParameterAnimationInstance> >::ConstIterator i = materialShaderParameterAnimationInstances_.Find(name);
  512. if (i == materialShaderParameterAnimationInstances_.End())
  513. return 0;
  514. return i->second_;
  515. }
  516. }