mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-21 09:39:56 +00:00
Fix unnecessary use of CopyFramebufferToTextureCallback when loading is too fast for a loading screen to be displayed
This commit is contained in:
parent
767eba941f
commit
83a9435167
@ -38,6 +38,7 @@ namespace MWGui
|
|||||||
, mLoadingOnTime(0.0)
|
, mLoadingOnTime(0.0)
|
||||||
, mImportantLabel(false)
|
, mImportantLabel(false)
|
||||||
, mProgress(0)
|
, mProgress(0)
|
||||||
|
, mShowWallpaper(true)
|
||||||
{
|
{
|
||||||
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
|
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
|
||||||
|
|
||||||
@ -104,14 +105,16 @@ namespace MWGui
|
|||||||
class CopyFramebufferToTextureCallback : public osg::Camera::DrawCallback
|
class CopyFramebufferToTextureCallback : public osg::Camera::DrawCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CopyFramebufferToTextureCallback(osg::Texture2D* texture, int w, int h)
|
CopyFramebufferToTextureCallback(osg::Texture2D* texture)
|
||||||
: mTexture(texture), mWidth(w), mHeight(h)
|
: mTexture(texture)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void operator () (osg::RenderInfo& renderInfo) const
|
virtual void operator () (osg::RenderInfo& renderInfo) const
|
||||||
{
|
{
|
||||||
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, mWidth, mHeight);
|
int w = renderInfo.getCurrentCamera()->getViewport()->width();
|
||||||
|
int h = renderInfo.getCurrentCamera()->getViewport()->height();
|
||||||
|
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, w, h);
|
||||||
|
|
||||||
// Callback removes itself when done
|
// Callback removes itself when done
|
||||||
if (renderInfo.getCurrentCamera())
|
if (renderInfo.getCurrentCamera())
|
||||||
@ -120,7 +123,6 @@ namespace MWGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||||
int mWidth, mHeight;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback
|
class DontComputeBoundCallback : public osg::Node::ComputeBoundingSphereCallback
|
||||||
@ -146,45 +148,17 @@ namespace MWGui
|
|||||||
// We are already using node masks to avoid the scene from being updated/rendered, but node masks don't work for computeBound()
|
// We are already using node masks to avoid the scene from being updated/rendered, but node masks don't work for computeBound()
|
||||||
mViewer->getSceneData()->setComputeBoundingSphereCallback(new DontComputeBoundCallback);
|
mViewer->getSceneData()->setComputeBoundingSphereCallback(new DontComputeBoundCallback);
|
||||||
|
|
||||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
mShowWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
||||||
== MWBase::StateManager::State_NoGame);
|
== MWBase::StateManager::State_NoGame);
|
||||||
|
|
||||||
if (!showWallpaper)
|
|
||||||
{
|
|
||||||
// Copy the current framebuffer onto a texture and display that texture as the background image
|
|
||||||
// Note, we could also set the camera to disable clearing and have the background image transparent,
|
|
||||||
// but then we get shaking effects on buffer swaps.
|
|
||||||
|
|
||||||
if (!mTexture)
|
|
||||||
{
|
|
||||||
mTexture = new osg::Texture2D;
|
|
||||||
mTexture->setInternalFormat(GL_RGB);
|
|
||||||
mTexture->setResizeNonPowerOfTwoHint(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = mViewer->getCamera()->getViewport()->width();
|
|
||||||
int height = mViewer->getCamera()->getViewport()->height();
|
|
||||||
mViewer->getCamera()->setInitialDrawCallback(new CopyFramebufferToTextureCallback(mTexture, width, height));
|
|
||||||
|
|
||||||
if (!mGuiTexture.get())
|
|
||||||
{
|
|
||||||
mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture));
|
|
||||||
}
|
|
||||||
|
|
||||||
mBackgroundImage->setBackgroundImage("");
|
|
||||||
|
|
||||||
mBackgroundImage->setRenderItemTexture(mGuiTexture.get());
|
|
||||||
mBackgroundImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
|
||||||
}
|
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
if (showWallpaper)
|
if (mShowWallpaper)
|
||||||
{
|
{
|
||||||
changeWallpaper();
|
changeWallpaper();
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(showWallpaper ? GM_LoadingWallpaper : GM_Loading);
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(mShowWallpaper ? GM_LoadingWallpaper : GM_Loading);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadingScreen::loadingOff()
|
void LoadingScreen::loadingOff()
|
||||||
@ -273,26 +247,53 @@ namespace MWGui
|
|||||||
diff -= mProgress / static_cast<float>(mProgressBar->getScrollRange()) * 100.f;
|
diff -= mProgress / static_cast<float>(mProgressBar->getScrollRange()) * 100.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
if (!mShowWallpaper && diff < initialDelay*1000)
|
||||||
== MWBase::StateManager::State_NoGame);
|
|
||||||
if (!showWallpaper && diff < initialDelay*1000)
|
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadingScreen::setupCopyFramebufferToTextureCallback()
|
||||||
|
{
|
||||||
|
// Copy the current framebuffer onto a texture and display that texture as the background image
|
||||||
|
// Note, we could also set the camera to disable clearing and have the background image transparent,
|
||||||
|
// but then we get shaking effects on buffer swaps.
|
||||||
|
|
||||||
|
if (!mTexture)
|
||||||
|
{
|
||||||
|
mTexture = new osg::Texture2D;
|
||||||
|
mTexture->setInternalFormat(GL_RGB);
|
||||||
|
mTexture->setResizeNonPowerOfTwoHint(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mGuiTexture.get())
|
||||||
|
{
|
||||||
|
mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture));
|
||||||
|
}
|
||||||
|
|
||||||
|
mViewer->getCamera()->setInitialDrawCallback(new CopyFramebufferToTextureCallback(mTexture));
|
||||||
|
|
||||||
|
mBackgroundImage->setBackgroundImage("");
|
||||||
|
|
||||||
|
mBackgroundImage->setRenderItemTexture(mGuiTexture.get());
|
||||||
|
mBackgroundImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
|
||||||
|
}
|
||||||
|
|
||||||
void LoadingScreen::draw()
|
void LoadingScreen::draw()
|
||||||
{
|
{
|
||||||
if (!needToDrawLoadingScreen())
|
if (!needToDrawLoadingScreen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
if (mShowWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1)
|
||||||
== MWBase::StateManager::State_NoGame);
|
|
||||||
if (showWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1)
|
|
||||||
{
|
{
|
||||||
mLastWallpaperChangeTime = mTimer.time_m();
|
mLastWallpaperChangeTime = mTimer.time_m();
|
||||||
changeWallpaper();
|
changeWallpaper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mShowWallpaper && mLastRenderTime < mLoadingOnTime)
|
||||||
|
{
|
||||||
|
setupCopyFramebufferToTextureCallback();
|
||||||
|
}
|
||||||
|
|
||||||
// Turn off rendering except the GUI
|
// Turn off rendering except the GUI
|
||||||
int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask();
|
int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask();
|
||||||
int oldCullMask = mViewer->getCamera()->getCullMask();
|
int oldCullMask = mViewer->getCamera()->getCullMask();
|
||||||
|
@ -47,6 +47,8 @@ namespace MWGui
|
|||||||
void findSplashScreens();
|
void findSplashScreens();
|
||||||
bool needToDrawLoadingScreen();
|
bool needToDrawLoadingScreen();
|
||||||
|
|
||||||
|
void setupCopyFramebufferToTextureCallback();
|
||||||
|
|
||||||
const VFS::Manager* mVFS;
|
const VFS::Manager* mVFS;
|
||||||
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
||||||
|
|
||||||
@ -61,6 +63,8 @@ namespace MWGui
|
|||||||
|
|
||||||
size_t mProgress;
|
size_t mProgress;
|
||||||
|
|
||||||
|
bool mShowWallpaper;
|
||||||
|
|
||||||
MyGUI::Widget* mLoadingBox;
|
MyGUI::Widget* mLoadingBox;
|
||||||
|
|
||||||
MyGUI::TextBox* mLoadingText;
|
MyGUI::TextBox* mLoadingText;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user