mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:23:51 +00:00
No longer delete and recreate CopyFramebufferToTextureCallback, remove oneshot functionality. Instead just remove the callback after the traversals. Use addInitialDrawCallback instead of setInitialDrawCallback to avoid messing with existing callbacks.
This commit is contained in:
parent
9f81dcbd1a
commit
640420eaaa
2 changed files with 11 additions and 8 deletions
|
@ -137,15 +137,11 @@ namespace MWGui
|
|||
public:
|
||||
CopyFramebufferToTextureCallback(osg::Texture2D* texture)
|
||||
: mTexture(texture)
|
||||
, oneshot(true)
|
||||
{
|
||||
}
|
||||
|
||||
void operator () (osg::RenderInfo& renderInfo) const override
|
||||
{
|
||||
if (!oneshot)
|
||||
return;
|
||||
oneshot = false;
|
||||
int w = renderInfo.getCurrentCamera()->getViewport()->width();
|
||||
int h = renderInfo.getCurrentCamera()->getViewport()->height();
|
||||
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h);
|
||||
|
@ -153,7 +149,6 @@ namespace MWGui
|
|||
|
||||
private:
|
||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||
mutable bool oneshot;
|
||||
};
|
||||
|
||||
class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback
|
||||
|
@ -322,9 +317,12 @@ namespace MWGui
|
|||
mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture));
|
||||
}
|
||||
|
||||
// Notice that the next time this is called, the current CopyFramebufferToTextureCallback will be deleted
|
||||
// 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));
|
||||
if (!mCopyFramebufferToTextureCallback)
|
||||
{
|
||||
mCopyFramebufferToTextureCallback = new CopyFramebufferToTextureCallback(mTexture);
|
||||
}
|
||||
|
||||
mViewer->getCamera()->addInitialDrawCallback(mCopyFramebufferToTextureCallback);
|
||||
|
||||
mBackgroundImage->setBackgroundImage("");
|
||||
mBackgroundImage->setVisible(false);
|
||||
|
@ -367,6 +365,9 @@ namespace MWGui
|
|||
mViewer->renderingTraversals();
|
||||
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
|
||||
|
||||
if(mCopyFramebufferToTextureCallback)
|
||||
mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback);
|
||||
|
||||
mLastRenderTime = mTimer.time_m();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace Resource
|
|||
namespace MWGui
|
||||
{
|
||||
class BackgroundImage;
|
||||
class CopyFramebufferToTextureCallback;
|
||||
|
||||
class LoadingScreen : public WindowBase, public Loading::Listener
|
||||
{
|
||||
|
@ -84,6 +85,7 @@ namespace MWGui
|
|||
std::vector<std::string> mSplashScreens;
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||
osg::ref_ptr<CopyFramebufferToTextureCallback> mCopyFramebufferToTextureCallback;
|
||||
std::unique_ptr<MyGUI::ITexture> mGuiTexture;
|
||||
|
||||
void changeWallpaper();
|
||||
|
|
Loading…
Reference in a new issue