mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Store RenderManager textures by value
This commit is contained in:
parent
6738722aa5
commit
036937ee02
2 changed files with 9 additions and 24 deletions
|
@ -380,8 +380,6 @@ RenderManager::~RenderManager()
|
||||||
mSceneRoot = nullptr;
|
mSceneRoot = nullptr;
|
||||||
mViewer = nullptr;
|
mViewer = nullptr;
|
||||||
|
|
||||||
destroyAllResources();
|
|
||||||
|
|
||||||
MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully shutdown");
|
MYGUI_PLATFORM_LOG(Info, getClassTypeName()<<" successfully shutdown");
|
||||||
mIsInitialise = false;
|
mIsInitialise = false;
|
||||||
}
|
}
|
||||||
|
@ -532,16 +530,13 @@ bool RenderManager::isFormatSupported(MyGUI::PixelFormat /*format*/, MyGUI::Text
|
||||||
|
|
||||||
MyGUI::ITexture* RenderManager::createTexture(const std::string &name)
|
MyGUI::ITexture* RenderManager::createTexture(const std::string &name)
|
||||||
{
|
{
|
||||||
MapTexture::iterator item = mTextures.find(name);
|
auto item = mTextures.find(name);
|
||||||
if (item != mTextures.end())
|
if (item != mTextures.end())
|
||||||
{
|
|
||||||
delete item->second;
|
|
||||||
mTextures.erase(item);
|
mTextures.erase(item);
|
||||||
}
|
|
||||||
|
|
||||||
OSGTexture* texture = new OSGTexture(name, mImageManager);
|
item = mTextures.emplace_hint(item, name, OSGTexture(name, mImageManager));
|
||||||
mTextures.insert(std::make_pair(name, texture));
|
|
||||||
return texture;
|
return &item->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderManager::destroyTexture(MyGUI::ITexture *texture)
|
void RenderManager::destroyTexture(MyGUI::ITexture *texture)
|
||||||
|
@ -549,11 +544,10 @@ void RenderManager::destroyTexture(MyGUI::ITexture *texture)
|
||||||
if(texture == nullptr)
|
if(texture == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MapTexture::iterator item = mTextures.find(texture->getName());
|
const auto item = mTextures.find(texture->getName());
|
||||||
MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '"<<texture->getName()<<"' not found");
|
MYGUI_PLATFORM_ASSERT(item != mTextures.end(), "Texture '"<<texture->getName()<<"' not found");
|
||||||
|
|
||||||
mTextures.erase(item);
|
mTextures.erase(item);
|
||||||
delete texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
|
MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
|
||||||
|
@ -561,21 +555,14 @@ MyGUI::ITexture* RenderManager::getTexture(const std::string &name)
|
||||||
if (name.empty())
|
if (name.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
MapTexture::const_iterator item = mTextures.find(name);
|
const auto item = mTextures.find(name);
|
||||||
if(item == mTextures.end())
|
if(item == mTextures.end())
|
||||||
{
|
{
|
||||||
MyGUI::ITexture* tex = createTexture(name);
|
MyGUI::ITexture* tex = createTexture(name);
|
||||||
tex->loadFromFile(name);
|
tex->loadFromFile(name);
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
return item->second;
|
return &item->second;
|
||||||
}
|
|
||||||
|
|
||||||
void RenderManager::destroyAllResources()
|
|
||||||
{
|
|
||||||
for (MapTexture::iterator it = mTextures.begin(); it != mTextures.end(); ++it)
|
|
||||||
delete it->second;
|
|
||||||
mTextures.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderManager::checkTexture(MyGUI::ITexture* _texture)
|
bool RenderManager::checkTexture(MyGUI::ITexture* _texture)
|
||||||
|
|
|
@ -32,6 +32,7 @@ namespace osgMyGUI
|
||||||
{
|
{
|
||||||
|
|
||||||
class Drawable;
|
class Drawable;
|
||||||
|
class OSGTexture;
|
||||||
|
|
||||||
class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
|
class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
|
||||||
{
|
{
|
||||||
|
@ -45,8 +46,7 @@ class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
|
||||||
MyGUI::VertexColourType mVertexFormat;
|
MyGUI::VertexColourType mVertexFormat;
|
||||||
MyGUI::RenderTargetInfo mInfo;
|
MyGUI::RenderTargetInfo mInfo;
|
||||||
|
|
||||||
typedef std::map<std::string, MyGUI::ITexture*> MapTexture;
|
std::map<std::string, OSGTexture> mTextures;
|
||||||
MapTexture mTextures;
|
|
||||||
|
|
||||||
bool mIsInitialise;
|
bool mIsInitialise;
|
||||||
|
|
||||||
|
@ -56,8 +56,6 @@ class RenderManager : public MyGUI::RenderManager, public MyGUI::IRenderTarget
|
||||||
|
|
||||||
osg::StateSet* mInjectState;
|
osg::StateSet* mInjectState;
|
||||||
|
|
||||||
void destroyAllResources();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::ImageManager* imageManager, float scalingFactor);
|
RenderManager(osgViewer::Viewer *viewer, osg::Group *sceneroot, Resource::ImageManager* imageManager, float scalingFactor);
|
||||||
virtual ~RenderManager();
|
virtual ~RenderManager();
|
||||||
|
|
Loading…
Reference in a new issue