1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 22:20:33 +00:00

Merge branch 'loadingScreen_initialdrawcallback' into 'master'

Clean up use of initial draw callback in loadingscreen

See merge request OpenMW/openmw!472
This commit is contained in:
AnyOldName3 2020-12-16 22:10:03 +00:00
commit 70bd9d395d
2 changed files with 14 additions and 8 deletions

View File

@ -137,15 +137,11 @@ namespace MWGui
public: public:
CopyFramebufferToTextureCallback(osg::Texture2D* texture) CopyFramebufferToTextureCallback(osg::Texture2D* texture)
: mTexture(texture) : mTexture(texture)
, oneshot(true)
{ {
} }
void operator () (osg::RenderInfo& renderInfo) const override void operator () (osg::RenderInfo& renderInfo) const override
{ {
if (!oneshot)
return;
oneshot = false;
int w = renderInfo.getCurrentCamera()->getViewport()->width(); int w = renderInfo.getCurrentCamera()->getViewport()->width();
int h = renderInfo.getCurrentCamera()->getViewport()->height(); int h = renderInfo.getCurrentCamera()->getViewport()->height();
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h); mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h);
@ -153,7 +149,6 @@ namespace MWGui
private: private:
osg::ref_ptr<osg::Texture2D> mTexture; osg::ref_ptr<osg::Texture2D> mTexture;
mutable bool oneshot;
}; };
class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback
@ -322,9 +317,12 @@ namespace MWGui
mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture)); mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture));
} }
// Notice that the next time this is called, the current CopyFramebufferToTextureCallback will be deleted if (!mCopyFramebufferToTextureCallback)
// so there's no memory leak as at most one object of type CopyFramebufferToTextureCallback is allocated at a time. {
mViewer->getCamera()->setInitialDrawCallback(new CopyFramebufferToTextureCallback(mTexture)); mCopyFramebufferToTextureCallback = new CopyFramebufferToTextureCallback(mTexture);
}
mViewer->getCamera()->addInitialDrawCallback(mCopyFramebufferToTextureCallback);
mBackgroundImage->setBackgroundImage(""); mBackgroundImage->setBackgroundImage("");
mBackgroundImage->setVisible(false); mBackgroundImage->setVisible(false);
@ -367,6 +365,12 @@ namespace MWGui
mViewer->renderingTraversals(); mViewer->renderingTraversals();
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime()); mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
if (mCopyFramebufferToTextureCallback)
{
mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback);
mCopyFramebufferToTextureCallback = nullptr;
}
mLastRenderTime = mTimer.time_m(); mLastRenderTime = mTimer.time_m();
} }

View File

@ -28,6 +28,7 @@ namespace Resource
namespace MWGui namespace MWGui
{ {
class BackgroundImage; class BackgroundImage;
class CopyFramebufferToTextureCallback;
class LoadingScreen : public WindowBase, public Loading::Listener class LoadingScreen : public WindowBase, public Loading::Listener
{ {
@ -84,6 +85,7 @@ namespace MWGui
std::vector<std::string> mSplashScreens; std::vector<std::string> mSplashScreens;
osg::ref_ptr<osg::Texture2D> mTexture; osg::ref_ptr<osg::Texture2D> mTexture;
osg::ref_ptr<CopyFramebufferToTextureCallback> mCopyFramebufferToTextureCallback;
std::unique_ptr<MyGUI::ITexture> mGuiTexture; std::unique_ptr<MyGUI::ITexture> mGuiTexture;
void changeWallpaper(); void changeWallpaper();