1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-04 21:19:41 +00:00

Loading screen initialdrawcallback 4th time's the charm

This commit is contained in:
Mads Buvik Sandvei 2020-12-18 18:15:14 +00:00 committed by psi29a
parent 264539cd63
commit eec2ba3623
2 changed files with 30 additions and 5 deletions

View file

@ -46,6 +46,7 @@ namespace MWGui
, mProgress(0) , mProgress(0)
, mShowWallpaper(true) , mShowWallpaper(true)
, mOldCallback(nullptr) , mOldCallback(nullptr)
, mHasCallback(false)
{ {
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize()); mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
@ -139,13 +140,19 @@ namespace MWGui
{ {
public: public:
CopyFramebufferToTextureCallback(osg::Texture2D* texture) CopyFramebufferToTextureCallback(osg::Texture2D* texture)
: mTexture(texture) : mOneshot(true)
, mOneshot(true) , mTexture(texture)
{ {
} }
void operator () (osg::RenderInfo& renderInfo) const override void operator () (osg::RenderInfo& renderInfo) const override
{ {
{
std::unique_lock<std::mutex> lock(mMutex);
mOneshot = false;
}
mSignal.notify_all();
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);
@ -164,6 +171,18 @@ namespace MWGui
mSignal.wait(lock); mSignal.wait(lock);
} }
void waitUntilInvoked()
{
std::unique_lock<std::mutex> lock(mMutex);
while (mOneshot)
mSignal.wait(lock);
}
void reset()
{
mOneshot = true;
}
private: private:
mutable bool mOneshot; mutable bool mOneshot;
mutable std::mutex mMutex; mutable std::mutex mMutex;
@ -349,6 +368,8 @@ namespace MWGui
mOldCallback = mViewer->getCamera()->getInitialDrawCallback(); mOldCallback = mViewer->getCamera()->getInitialDrawCallback();
mViewer->getCamera()->setInitialDrawCallback(mCopyFramebufferToTextureCallback); mViewer->getCamera()->setInitialDrawCallback(mCopyFramebufferToTextureCallback);
#endif #endif
mCopyFramebufferToTextureCallback->reset();
mHasCallback = true;
mBackgroundImage->setBackgroundImage(""); mBackgroundImage->setBackgroundImage("");
mBackgroundImage->setVisible(false); mBackgroundImage->setVisible(false);
@ -391,16 +412,19 @@ namespace MWGui
mViewer->renderingTraversals(); mViewer->renderingTraversals();
mViewer->advance(mViewer->getFrameStamp()->getSimulationTime()); mViewer->advance(mViewer->getFrameStamp()->getSimulationTime());
if (mCopyFramebufferToTextureCallback) if (mHasCallback)
{ {
mCopyFramebufferToTextureCallback->wait(); mCopyFramebufferToTextureCallback->waitUntilInvoked();
// Note that we are removing the callback before the draw thread has returned from it.
// This is OK as we are retaining the ref_ptr.
#if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10) #if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 10)
mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback); mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback);
#else #else
// TODO: Remove once we officially end support for OSG versions pre 3.5.10 // TODO: Remove once we officially end support for OSG versions pre 3.5.10
mViewer->getCamera()->setInitialDrawCallback(mOldCallback); mViewer->getCamera()->setInitialDrawCallback(mOldCallback);
#endif #endif
mCopyFramebufferToTextureCallback = nullptr; mHasCallback = false;
} }
mLastRenderTime = mTimer.time_m(); mLastRenderTime = mTimer.time_m();

View file

@ -88,6 +88,7 @@ namespace MWGui
osg::ref_ptr<osg::Texture2D> mTexture; osg::ref_ptr<osg::Texture2D> mTexture;
osg::ref_ptr<CopyFramebufferToTextureCallback> mCopyFramebufferToTextureCallback; osg::ref_ptr<CopyFramebufferToTextureCallback> mCopyFramebufferToTextureCallback;
osg::ref_ptr<osg::Camera::DrawCallback> mOldCallback; osg::ref_ptr<osg::Camera::DrawCallback> mOldCallback;
bool mHasCallback;
std::unique_ptr<MyGUI::ITexture> mGuiTexture; std::unique_ptr<MyGUI::ITexture> mGuiTexture;
void changeWallpaper(); void changeWallpaper();