forked from mirror/openmw-tes3mp
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
2 changed files with 46 additions and 41 deletions
|
@ -38,6 +38,7 @@ namespace MWGui
|
|||
, mLoadingOnTime(0.0)
|
||||
, mImportantLabel(false)
|
||||
, mProgress(0)
|
||||
, mShowWallpaper(true)
|
||||
{
|
||||
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
|
||||
|
||||
|
@ -104,14 +105,16 @@ namespace MWGui
|
|||
class CopyFramebufferToTextureCallback : public osg::Camera::DrawCallback
|
||||
{
|
||||
public:
|
||||
CopyFramebufferToTextureCallback(osg::Texture2D* texture, int w, int h)
|
||||
: mTexture(texture), mWidth(w), mHeight(h)
|
||||
CopyFramebufferToTextureCallback(osg::Texture2D* texture)
|
||||
: mTexture(texture)
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
if (renderInfo.getCurrentCamera())
|
||||
|
@ -120,7 +123,6 @@ namespace MWGui
|
|||
|
||||
private:
|
||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||
int mWidth, mHeight;
|
||||
};
|
||||
|
||||
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()
|
||||
mViewer->getSceneData()->setComputeBoundingSphereCallback(new DontComputeBoundCallback);
|
||||
|
||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
||||
mShowWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
||||
== 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);
|
||||
|
||||
if (showWallpaper)
|
||||
if (mShowWallpaper)
|
||||
{
|
||||
changeWallpaper();
|
||||
}
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(showWallpaper ? GM_LoadingWallpaper : GM_Loading);
|
||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(mShowWallpaper ? GM_LoadingWallpaper : GM_Loading);
|
||||
}
|
||||
|
||||
void LoadingScreen::loadingOff()
|
||||
|
@ -273,26 +247,53 @@ namespace MWGui
|
|||
diff -= mProgress / static_cast<float>(mProgressBar->getScrollRange()) * 100.f;
|
||||
}
|
||||
|
||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
||||
== MWBase::StateManager::State_NoGame);
|
||||
if (!showWallpaper && diff < initialDelay*1000)
|
||||
if (!mShowWallpaper && diff < initialDelay*1000)
|
||||
return false;
|
||||
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()
|
||||
{
|
||||
if (!needToDrawLoadingScreen())
|
||||
return;
|
||||
|
||||
bool showWallpaper = (MWBase::Environment::get().getStateManager()->getState()
|
||||
== MWBase::StateManager::State_NoGame);
|
||||
if (showWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1)
|
||||
if (mShowWallpaper && mTimer.time_m() > mLastWallpaperChangeTime + 5000*1)
|
||||
{
|
||||
mLastWallpaperChangeTime = mTimer.time_m();
|
||||
changeWallpaper();
|
||||
}
|
||||
|
||||
if (!mShowWallpaper && mLastRenderTime < mLoadingOnTime)
|
||||
{
|
||||
setupCopyFramebufferToTextureCallback();
|
||||
}
|
||||
|
||||
// Turn off rendering except the GUI
|
||||
int oldUpdateMask = mViewer->getUpdateVisitor()->getTraversalMask();
|
||||
int oldCullMask = mViewer->getCamera()->getCullMask();
|
||||
|
|
|
@ -47,6 +47,8 @@ namespace MWGui
|
|||
void findSplashScreens();
|
||||
bool needToDrawLoadingScreen();
|
||||
|
||||
void setupCopyFramebufferToTextureCallback();
|
||||
|
||||
const VFS::Manager* mVFS;
|
||||
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
||||
|
||||
|
@ -61,6 +63,8 @@ namespace MWGui
|
|||
|
||||
size_t mProgress;
|
||||
|
||||
bool mShowWallpaper;
|
||||
|
||||
MyGUI::Widget* mLoadingBox;
|
||||
|
||||
MyGUI::TextBox* mLoadingText;
|
||||
|
|
Loading…
Reference in a new issue