From 4a26dcb2ad6e92658230379aedba736fe5d2e0da Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 8 Aug 2014 15:44:22 +0200 Subject: [PATCH] Avoid calling RenderTarget::update from within loadResource --- apps/openmw/mwgui/inventorywindow.cpp | 1 + apps/openmw/mwrender/characterpreview.cpp | 21 ++++++++++++++++++--- apps/openmw/mwrender/characterpreview.hpp | 5 +++++ libs/openengine/ogre/selectionbuffer.cpp | 7 +++++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 6772d6e04..e56719da0 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -504,6 +504,7 @@ namespace MWGui void InventoryWindow::doRenderUpdate () { + mPreview->onFrame(); if (mPreviewDirty) { mPreviewDirty = false; diff --git a/apps/openmw/mwrender/characterpreview.cpp b/apps/openmw/mwrender/characterpreview.cpp index cc1a03a12..fde5e9432 100644 --- a/apps/openmw/mwrender/characterpreview.cpp +++ b/apps/openmw/mwrender/characterpreview.cpp @@ -37,6 +37,7 @@ namespace MWRender , mViewport(NULL) , mCamera(NULL) , mNode(NULL) + , mRecover(false) { mCharacter.mCell = NULL; } @@ -46,6 +47,16 @@ namespace MWRender } + void CharacterPreview::onFrame() + { + if (mRecover) + { + setupRenderTarget(); + mRenderTarget->update(); + mRecover = false; + } + } + void CharacterPreview::setup () { mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC); @@ -127,9 +138,9 @@ namespace MWRender tex->createInternalResources(); - setupRenderTarget(); - - mRenderTarget->update(); + mRenderTarget = NULL; + mViewport = NULL; + mRecover = true; } void CharacterPreview::setupRenderTarget() @@ -223,6 +234,10 @@ namespace MWRender mViewport->setDimensions (0, 0, std::min(1.f, float(mSizeX) / float(512)), std::min(1.f, float(mSizeY) / float(1024))); mTexture->load(); + + if (!mRenderTarget) + setupRenderTarget(); + mRenderTarget->update(); mSelectionBuffer->update(); diff --git a/apps/openmw/mwrender/characterpreview.hpp b/apps/openmw/mwrender/characterpreview.hpp index 8990018dd..d8f4609b8 100644 --- a/apps/openmw/mwrender/characterpreview.hpp +++ b/apps/openmw/mwrender/characterpreview.hpp @@ -34,8 +34,13 @@ namespace MWRender virtual void rebuild(); + void onFrame(); + void loadResource(Ogre::Resource *resource); + private: + bool mRecover; // Texture content was lost and needs to be re-rendered + private: CharacterPreview(const CharacterPreview&); CharacterPreview& operator=(const CharacterPreview&); diff --git a/libs/openengine/ogre/selectionbuffer.cpp b/libs/openengine/ogre/selectionbuffer.cpp index 620b7ea8a..af95750d5 100644 --- a/libs/openengine/ogre/selectionbuffer.cpp +++ b/libs/openengine/ogre/selectionbuffer.cpp @@ -51,9 +51,9 @@ namespace Render tex->createInternalResources(); - setupRenderTarget(); + mRenderTarget = NULL; - mRenderTarget->update(); + // Don't need to re-render texture, because we have a copy in system memory (mBuffer) } SelectionBuffer::~SelectionBuffer() @@ -65,6 +65,9 @@ namespace Render { Ogre::MaterialManager::getSingleton ().addListener (this); + if (mRenderTarget == NULL) + setupRenderTarget(); + mRenderTarget->update(); Ogre::MaterialManager::getSingleton ().removeListener (this);