1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-29 13:20:35 +00:00

Restore the "transparent" loading screen

This commit is contained in:
scrawl 2015-06-07 21:21:57 +02:00
parent f3cbe7b9da
commit 0330d3d61e
2 changed files with 59 additions and 21 deletions

View File

@ -2,6 +2,8 @@
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <osg/Texture2D>
#include <MyGUI_RenderManager.h> #include <MyGUI_RenderManager.h>
#include <MyGUI_ScrollBar.h> #include <MyGUI_ScrollBar.h>
#include <MyGUI_Gui.h> #include <MyGUI_Gui.h>
@ -9,6 +11,8 @@
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/vfs/manager.hpp> #include <components/vfs/manager.hpp>
@ -96,6 +100,28 @@ namespace MWGui
mBackgroundImage->setVisible(visible); mBackgroundImage->setVisible(visible);
} }
class CopyFramebufferToTextureCallback : public osg::Camera::DrawCallback
{
public:
CopyFramebufferToTextureCallback(osg::Texture2D* texture, int w, int h)
: mTexture(texture), mWidth(w), mHeight(h)
{
}
virtual void operator () (osg::RenderInfo& renderInfo) const
{
mTexture->copyTexImage2D(*renderInfo.getState(), 0, 0, mWidth, mHeight);
// Callback removes itself when done
if (renderInfo.getCurrentCamera())
renderInfo.getCurrentCamera()->setInitialDrawCallback(NULL);
}
private:
osg::ref_ptr<osg::Texture2D> mTexture;
int mWidth, mHeight;
};
void LoadingScreen::loadingOn() void LoadingScreen::loadingOn()
{ {
mLoadingOnTime = mTimer.time_m(); mLoadingOnTime = mTimer.time_m();
@ -114,29 +140,30 @@ namespace MWGui
if (!showWallpaper) if (!showWallpaper)
{ {
// TODO // 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,
mBackgroundImage->setImageTexture(""); // but then we get shaking effects on buffer swaps.
int width = mWindow->getWidth();
int height = mWindow->getHeight(); if (!mTexture)
const std::string textureName = "@loading_background";
Ogre::TexturePtr texture;
texture = Ogre::TextureManager::getSingleton().getByName(textureName);
if (texture.isNull())
{ {
texture = Ogre::TextureManager::getSingleton().createManual(textureName, mTexture = new osg::Texture2D;
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, mTexture->setInternalFormat(GL_RGB);
Ogre::TEX_TYPE_2D, mTexture->setResizeNonPowerOfTwoHint(false);
width, height, 0, mWindow->suggestPixelFormat(), Ogre::TU_DYNAMIC_WRITE_ONLY);
} }
texture->unload();
texture->setWidth(width); int width = mViewer->getCamera()->getViewport()->width();
texture->setHeight(height); int height = mViewer->getCamera()->getViewport()->height();
texture->createInternalResources(); mViewer->getCamera()->setInitialDrawCallback(new CopyFramebufferToTextureCallback(mTexture, width, height));
mWindow->copyContentsToMemory(texture->getBuffer()->lock(Ogre::Image::Box(0,0,width,height), Ogre::HardwareBuffer::HBL_DISCARD));
texture->getBuffer()->unlock(); if (!mGuiTexture.get())
mBackgroundImage->setBackgroundImage(texture->getName(), false, false); {
*/ mGuiTexture.reset(new osgMyGUI::OSGTexture(mTexture));
}
mBackgroundImage->setBackgroundImage("");
mBackgroundImage->setRenderItemTexture(mGuiTexture.get());
mBackgroundImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 1.f, 1.f, 0.f));
} }
setVisible(true); setVisible(true);

View File

@ -12,6 +12,12 @@ namespace osgViewer
{ {
class Viewer; class Viewer;
} }
namespace osg
{
class Texture2D;
}
namespace VFS namespace VFS
{ {
class Manager; class Manager;
@ -67,6 +73,11 @@ namespace MWGui
std::vector<std::string> mSplashScreens; std::vector<std::string> mSplashScreens;
// TODO: add releaseGLObjects() for mTexture
osg::ref_ptr<osg::Texture2D> mTexture;
std::auto_ptr<MyGUI::ITexture> mGuiTexture;
void changeWallpaper(); void changeWallpaper();
void draw(); void draw();