Use IncrementalCompileOperation to incrementally upload OpenGL objects during the loading screen

For now, not much difference, but should result in a sizable speed up once MyGUI no longer needs the DYNAMIC flag (i.e. the loading screen truly renders in the background).
This commit is contained in:
scrawl 2015-05-03 18:16:54 +02:00
parent 37e3118d21
commit 9de575ad42
6 changed files with 41 additions and 5 deletions

View file

@ -391,8 +391,6 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
mEnvironment.setJournal (new MWDialogue::Journal); mEnvironment.setJournal (new MWDialogue::Journal);
mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage)); mEnvironment.setDialogueManager (new MWDialogue::DialogueManager (mExtensions, mVerboseScripts, mTranslationDataStorage));
//mOgre->getRoot()->addFrameListener (this);
// scripts // scripts
if (mCompileAll) if (mCompileAll)
{ {
@ -466,13 +464,12 @@ void OMW::Engine::go()
mViewer->setCameraManipulator(new osgGA::TrackballManipulator); mViewer->setCameraManipulator(new osgGA::TrackballManipulator);
mViewer->addEventHandler(new osgViewer::StatsHandler); mViewer->addEventHandler(new osgViewer::StatsHandler);
mViewer->realize();
osg::Timer frameTimer; osg::Timer frameTimer;
while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) while (!mViewer->done() && !MWBase::Environment::get().getStateManager()->hasQuitRequest())
{ {
double dt = frameTimer.time_s(); double dt = frameTimer.time_s();
frameTimer.setStartTick(); frameTimer.setStartTick();
//dt = std::min(dt, 0.2f); //dt = std::min(dt, 0.2);
frame(dt); frame(dt);
mViewer->frame(/*simulationTime*/); mViewer->frame(/*simulationTime*/);

View file

@ -30,8 +30,9 @@ namespace MWGui
: WindowBase("openmw_loading_screen.layout") : WindowBase("openmw_loading_screen.layout")
, mVFS(vfs) , mVFS(vfs)
, mViewer(viewer) , mViewer(viewer)
, mLastRenderTime(0.0)
, mLastWallpaperChangeTime(0.0) , mLastWallpaperChangeTime(0.0)
, mLastRenderTime(0.0)
, mLoadingOnTime(0.0)
, mProgress(0) , mProgress(0)
, mVSyncWasEnabled(false) , mVSyncWasEnabled(false)
{ {
@ -97,6 +98,7 @@ namespace MWGui
void LoadingScreen::loadingOn() void LoadingScreen::loadingOn()
{ {
mLoadingOnTime = mTimer.time_m();
// Early-out if already on // Early-out if already on
if (mMainWidget->getVisible()) if (mMainWidget->getVisible())
return; return;
@ -143,6 +145,7 @@ namespace MWGui
void LoadingScreen::loadingOff() void LoadingScreen::loadingOff()
{ {
//std::cout << "loading took " << mTimer.time_m() - mLoadingOnTime << std::endl;
setVisible(false); setVisible(false);
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Loading); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Loading);
@ -215,6 +218,8 @@ namespace MWGui
changeWallpaper(); changeWallpaper();
} }
mViewer->getIncrementalCompileOperation()->setMaximumNumOfObjectsToCompilePerFrame(80);
// 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();
@ -223,6 +228,8 @@ namespace MWGui
MWBase::Environment::get().getInputManager()->update(0, true, true); MWBase::Environment::get().getInputManager()->update(0, true, true);
//std::cout << "num to compile " << mViewer->getIncrementalCompileOperation()->getToCompile().size() << std::endl;
mViewer->frame(); mViewer->frame();
// resume 3d rendering // resume 3d rendering

View file

@ -53,6 +53,7 @@ namespace MWGui
double mLastWallpaperChangeTime; double mLastWallpaperChangeTime;
double mLastRenderTime; double mLastRenderTime;
osg::Timer mTimer; osg::Timer mTimer;
double mLoadingOnTime;
size_t mProgress; size_t mProgress;

View file

@ -7,6 +7,8 @@
#include <osg/Geode> #include <osg/Geode>
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
#include <osgUtil/IncrementalCompileOperation>
#include <osgParticle/ParticleSystem> #include <osgParticle/ParticleSystem>
#include <osgParticle/ParticleProcessor> #include <osgParticle/ParticleProcessor>
@ -78,6 +80,11 @@ Objects::~Objects()
mCellSceneNodes.clear(); mCellSceneNodes.clear();
} }
void Objects::setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation *ico)
{
mIncrementalCompileOperation = ico;
}
void Objects::insertBegin(const MWWorld::Ptr& ptr) void Objects::insertBegin(const MWWorld::Ptr& ptr)
{ {
osg::ref_ptr<osg::Group> cellnode; osg::ref_ptr<osg::Group> cellnode;
@ -108,6 +115,9 @@ void Objects::insertModel(const MWWorld::Ptr &ptr, const std::string &mesh, bool
std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, allowLight)); std::auto_ptr<ObjectAnimation> anim (new ObjectAnimation(ptr, mesh, mResourceSystem, allowLight));
if (mIncrementalCompileOperation && anim->getObjectRoot())
mIncrementalCompileOperation->add(anim->getObjectRoot());
if (!allowLight) if (!allowLight)
{ {
RemoveParticlesVisitor visitor; RemoveParticlesVisitor visitor;
@ -130,6 +140,9 @@ void Objects::insertCreature(const MWWorld::Ptr &ptr, const std::string &mesh, b
else else
anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem)); anim.reset(new CreatureAnimation(ptr, mesh, mResourceSystem));
if (mIncrementalCompileOperation && anim->getObjectRoot())
mIncrementalCompileOperation->add(anim->getObjectRoot());
mObjects.insert(std::make_pair(ptr, anim.release())); mObjects.insert(std::make_pair(ptr, anim.release()));
} }
@ -139,6 +152,9 @@ void Objects::insertNPC(const MWWorld::Ptr &ptr)
std::auto_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem, 0)); std::auto_ptr<NpcAnimation> anim (new NpcAnimation(ptr, osg::ref_ptr<osg::Group>(ptr.getRefData().getBaseNode()), mResourceSystem, 0));
if (mIncrementalCompileOperation && anim->getObjectRoot())
mIncrementalCompileOperation->add(anim->getObjectRoot());
mObjects.insert(std::make_pair(ptr, anim.release())); mObjects.insert(std::make_pair(ptr, anim.release()));
} }

View file

@ -12,6 +12,11 @@ namespace osg
class Group; class Group;
} }
namespace osgUtil
{
class IncrementalCompileOperation;
}
namespace Resource namespace Resource
{ {
class ResourceSystem; class ResourceSystem;
@ -41,10 +46,14 @@ class Objects{
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
osg::ref_ptr<osgUtil::IncrementalCompileOperation> mIncrementalCompileOperation;
public: public:
Objects(Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> rootNode); Objects(Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> rootNode);
~Objects(); ~Objects();
void setIncrementalCompileOperation(osgUtil::IncrementalCompileOperation* ico);
/// @param animated Attempt to load separate keyframes from a .kf file matching the model file? /// @param animated Attempt to load separate keyframes from a .kf file matching the model file?
/// @param allowLight If false, no lights will be created, and particles systems will be removed. /// @param allowLight If false, no lights will be created, and particles systems will be removed.
void insertModel(const MWWorld::Ptr& ptr, const std::string &model, bool animated=false, bool allowLight=true); void insertModel(const MWWorld::Ptr& ptr, const std::string &model, bool animated=false, bool allowLight=true);

View file

@ -9,6 +9,8 @@
#include <osg/Group> #include <osg/Group>
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
#include <osgUtil/IncrementalCompileOperation>
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include <components/resource/resourcesystem.hpp> #include <components/resource/resourcesystem.hpp>
@ -95,6 +97,10 @@ namespace MWRender
mObjects.reset(new Objects(mResourceSystem, lightRoot)); mObjects.reset(new Objects(mResourceSystem, lightRoot));
mViewer.setIncrementalCompileOperation(new osgUtil::IncrementalCompileOperation);
mObjects->setIncrementalCompileOperation(mViewer.getIncrementalCompileOperation());
mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem)); mEffectManager.reset(new EffectManager(mRootNode, mResourceSystem));
mViewer.setLightingMode(osgViewer::View::NO_LIGHT); mViewer.setLightingMode(osgViewer::View::NO_LIGHT);