1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 20:39:41 +00:00

Merge branch 'loadingScreen_initialdrawcallback' into 'master'

Loading screen initialdrawcallback 4th time's the charm

See merge request OpenMW/openmw!479
This commit is contained in:
psi29a 2020-12-18 18:15:14 +00:00
commit a1065c8376
2 changed files with 30 additions and 5 deletions

View file

@ -46,6 +46,7 @@ namespace MWGui
, mProgress(0)
, mShowWallpaper(true)
, mOldCallback(nullptr)
, mHasCallback(false)
{
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
@ -139,13 +140,19 @@ namespace MWGui
{
public:
CopyFramebufferToTextureCallback(osg::Texture2D* texture)
: mTexture(texture)
, mOneshot(true)
: mOneshot(true)
, mTexture(texture)
{
}
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 h = renderInfo.getCurrentCamera()->getViewport()->height();
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h);
@ -164,6 +171,18 @@ namespace MWGui
mSignal.wait(lock);
}
void waitUntilInvoked()
{
std::unique_lock<std::mutex> lock(mMutex);
while (mOneshot)
mSignal.wait(lock);
}
void reset()
{
mOneshot = true;
}
private:
mutable bool mOneshot;
mutable std::mutex mMutex;
@ -349,6 +368,8 @@ namespace MWGui
mOldCallback = mViewer->getCamera()->getInitialDrawCallback();
mViewer->getCamera()->setInitialDrawCallback(mCopyFramebufferToTextureCallback);
#endif
mCopyFramebufferToTextureCallback->reset();
mHasCallback = true;
mBackgroundImage->setBackgroundImage("");
mBackgroundImage->setVisible(false);
@ -391,16 +412,19 @@ namespace MWGui
mViewer->renderingTraversals();
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)
mViewer->getCamera()->removeInitialDrawCallback(mCopyFramebufferToTextureCallback);
#else
// TODO: Remove once we officially end support for OSG versions pre 3.5.10
mViewer->getCamera()->setInitialDrawCallback(mOldCallback);
#endif
mCopyFramebufferToTextureCallback = nullptr;
mHasCallback = false;
}
mLastRenderTime = mTimer.time_m();

View file

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