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

Bug #416: Copy framebuffer to a texture instead of not clearing

Potentially faster than the previous workaround, and should work for triple buffering too.
This commit is contained in:
scrawl 2014-03-06 04:01:25 +01:00
parent d0f98103e4
commit e08f6c9ce3

View file

@ -7,6 +7,7 @@
#include <OgreSceneNode.h> #include <OgreSceneNode.h>
#include <OgreTextureManager.h> #include <OgreTextureManager.h>
#include <OgreViewport.h> #include <OgreViewport.h>
#include <OgreHardwarePixelBuffer.h>
#include <openengine/ogre/fader.hpp> #include <openengine/ogre/fader.hpp>
@ -86,11 +87,26 @@ namespace MWGui
if (!mFirstLoad) if (!mFirstLoad)
{ {
// When the loading screen is updated, we will disable render target clearing and only draw the loading bar itself. mBackgroundImage->setImageTexture("");
// But if using page flipping, this can cause jitteriness as it will alternate between the last two rendered frames. int width = mWindow->getWidth();
// Even though we attempt to disable vsync above, this may not work if it's forced on the driver level. int height = mWindow->getHeight();
// Therefore render the same frame twice before activating the loading bar. const std::string textureName = "@loading_background";
mWindow->update(); Ogre::TexturePtr texture;
texture = Ogre::TextureManager::getSingleton().getByName(textureName);
if (texture.isNull())
{
texture = Ogre::TextureManager::getSingleton().createManual(textureName,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Ogre::TEX_TYPE_2D,
width, height, 0, mWindow->suggestPixelFormat(), Ogre::TU_DYNAMIC_WRITE_ONLY);
}
texture->unload();
texture->setWidth(width);
texture->setHeight(height);
texture->createInternalResources();
mWindow->copyContentsToMemory(texture->getBuffer()->lock(Ogre::Image::Box(0,0,width,height), Ogre::HardwareBuffer::HBL_DISCARD));
texture->getBuffer()->unlock();
mBackgroundImage->setImageTexture(texture->getName());
} }
setVisible(true); setVisible(true);
@ -99,10 +115,6 @@ namespace MWGui
{ {
changeWallpaper(); changeWallpaper();
} }
else
{
mBackgroundImage->setImageTexture("");
}
MWBase::Environment::get().getWindowManager()->pushGuiMode(mFirstLoad ? GM_LoadingWallpaper : GM_Loading); MWBase::Environment::get().getWindowManager()->pushGuiMode(mFirstLoad ? GM_LoadingWallpaper : GM_Loading);
} }
@ -216,8 +228,6 @@ namespace MWGui
MWBase::Environment::get().getInputManager()->update(0, true); MWBase::Environment::get().getInputManager()->update(0, true);
mWindow->getViewport(0)->setClearEveryFrame(false);
// First, swap buffers from last draw, then, queue an update of the // First, swap buffers from last draw, then, queue an update of the
// window contents, but don't swap buffers (which would have // window contents, but don't swap buffers (which would have
// caused a sync / flush and would be expensive). // caused a sync / flush and would be expensive).
@ -227,9 +237,6 @@ namespace MWGui
mWindow->update(false); mWindow->update(false);
mWindow->getViewport(0)->setClearEveryFrame(true);
mRectangle->setVisible(false); mRectangle->setVisible(false);
// resume 3d rendering // resume 3d rendering