|
26 | 26 | #include <Hlms/Unlit/OgreHlmsUnlitDatablock.h>
|
27 | 27 | #include <OgreHlmsManager.h>
|
28 | 28 | #include <OgreMaterialManager.h>
|
| 29 | +#include <OgreTextureManager.h> |
29 | 30 | #ifdef _MSC_VER
|
30 | 31 | #pragma warning(pop)
|
31 | 32 | #endif
|
|
44 | 45 | /// \brief Private data for the Ogre2Material class
|
45 | 46 | class ignition::rendering::Ogre2MaterialPrivate
|
46 | 47 | {
|
| 48 | + /// \brief Ogre stores the name using hashes. This variable will |
| 49 | + /// store the material hash name |
| 50 | + public: std::string hashName; |
47 | 51 | };
|
48 | 52 |
|
49 | 53 | using namespace ignition;
|
@@ -87,6 +91,39 @@ void Ogre2Material::Destroy()
|
87 | 91 | matManager.remove(this->ogreMaterial);
|
88 | 92 | this->ogreMaterial.reset();
|
89 | 93 | }
|
| 94 | + |
| 95 | + auto &textureManager = Ogre::TextureManager::getSingleton(); |
| 96 | + auto iend = textureManager.getResourceIterator().end(); |
| 97 | + for (auto i = textureManager.getResourceIterator().begin(); i != iend;) |
| 98 | + { |
| 99 | + // A use count of 4 means that only RGM, RM and MeshManager have references |
| 100 | + // RGM has one (this one) and RM has 2 (by name and by handle) |
| 101 | + // and MeshManager keep another one int the template |
| 102 | + Ogre::Resource* res = i->second.get(); |
| 103 | + if (i->second.useCount() == 5) |
| 104 | + { |
| 105 | + if (this->dataPtr->hashName == res->getName() && |
| 106 | + res->getName().find( |
| 107 | + scene->Name() + "::RenderTexture") == std::string::npos) |
| 108 | + { |
| 109 | + Ogre2ScenePtr s = std::dynamic_pointer_cast<Ogre2Scene>(this->Scene()); |
| 110 | + s->ClearMaterialsCache(this->textureName); |
| 111 | + this->Scene()->UnregisterMaterial(this->name); |
| 112 | + if (i->second.useCount() == 4) |
| 113 | + { |
| 114 | + textureManager.remove(res->getHandle()); |
| 115 | + if (!this->textureName.empty()) |
| 116 | + { |
| 117 | + Ogre::HlmsTextureManager *hlmsTextureManager = |
| 118 | + this->ogreHlmsPbs->getHlmsManager()->getTextureManager(); |
| 119 | + hlmsTextureManager->destroyTexture(this->textureName); |
| 120 | + } |
| 121 | + } |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + ++i; |
| 126 | + } |
90 | 127 | }
|
91 | 128 |
|
92 | 129 | //////////////////////////////////////////////////
|
@@ -538,6 +575,7 @@ void Ogre2Material::SetTextureMapImpl(const std::string &_texture,
|
538 | 575 | Ogre::HlmsTextureManager::TextureLocation texLocation =
|
539 | 576 | hlmsTextureManager->createOrRetrieveTexture(baseName,
|
540 | 577 | this->ogreDatablock->suggestMapTypeBasedOnTextureType(_type));
|
| 578 | + this->dataPtr->hashName = texLocation.texture->getName(); |
541 | 579 |
|
542 | 580 | Ogre::HlmsSamplerblock samplerBlockRef;
|
543 | 581 | samplerBlockRef.mU = Ogre::TAM_WRAP;
|
|
0 commit comments