mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Merge pull request #2264 from akortunov/optimize_terrain
Delete composite map layers in the background thread
This commit is contained in:
commit
b819690e82
@ -314,6 +314,7 @@ namespace MWRender
|
||||
|
||||
mTerrain->setDefaultViewer(mViewer->getCamera());
|
||||
mTerrain->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells"));
|
||||
mTerrain->setWorkQueue(mWorkQueue.get());
|
||||
|
||||
mCamera.reset(new Camera(mViewer->getCamera()));
|
||||
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include <osg/Texture2D>
|
||||
#include <osg/RenderInfo>
|
||||
|
||||
#include <components/sceneutil/unrefqueue.hpp>
|
||||
#include <components/sceneutil/workqueue.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Terrain
|
||||
@ -20,9 +23,20 @@ CompositeMapRenderer::CompositeMapRenderer()
|
||||
|
||||
mFBO = new osg::FrameBufferObject;
|
||||
|
||||
mUnrefQueue = new SceneUtil::UnrefQueue;
|
||||
|
||||
getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
||||
}
|
||||
|
||||
CompositeMapRenderer::~CompositeMapRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::setWorkQueue(SceneUtil::WorkQueue* workQueue)
|
||||
{
|
||||
mWorkQueue = workQueue;
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
|
||||
{
|
||||
double dt = mTimer.time_s();
|
||||
@ -35,6 +49,9 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const
|
||||
|
||||
mCompiled.clear();
|
||||
|
||||
if (mWorkQueue)
|
||||
mUnrefQueue->flush(mWorkQueue.get());
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
|
||||
|
||||
if (mImmediateCompileSet.empty() && mCompileSet.empty())
|
||||
@ -122,6 +139,10 @@ void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo &
|
||||
|
||||
++compositeMap.mCompiled;
|
||||
|
||||
if (mWorkQueue)
|
||||
{
|
||||
mUnrefQueue->push(compositeMap.mDrawables[i]);
|
||||
}
|
||||
compositeMap.mDrawables[i] = nullptr;
|
||||
|
||||
if (timeLeft)
|
||||
|
@ -14,6 +14,12 @@ namespace osg
|
||||
class Texture2D;
|
||||
}
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
class UnrefQueue;
|
||||
class WorkQueue;
|
||||
}
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
|
||||
@ -34,11 +40,15 @@ namespace Terrain
|
||||
{
|
||||
public:
|
||||
CompositeMapRenderer();
|
||||
~CompositeMapRenderer();
|
||||
|
||||
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
|
||||
|
||||
void compile(CompositeMap& compositeMap, osg::RenderInfo& renderInfo, double* timeLeft) const;
|
||||
|
||||
/// Set a WorkQueue to delete compiled composite map layers in the background thread
|
||||
void setWorkQueue(SceneUtil::WorkQueue* workQueue);
|
||||
|
||||
/// Set the available time in seconds for compiling (non-immediate) composite maps each frame
|
||||
void setMinimumTimeAvailableForCompile(double time);
|
||||
|
||||
@ -58,6 +68,9 @@ namespace Terrain
|
||||
double mMinimumTimeAvailable;
|
||||
mutable osg::Timer mTimer;
|
||||
|
||||
osg::ref_ptr<SceneUtil::UnrefQueue> mUnrefQueue;
|
||||
osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
|
||||
|
||||
typedef std::set<osg::ref_ptr<CompositeMap> > CompileSet;
|
||||
|
||||
mutable CompileSet mCompileSet;
|
||||
|
@ -16,7 +16,7 @@ namespace Terrain
|
||||
class RootNode;
|
||||
class ViewDataMap;
|
||||
|
||||
/// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD. The entire world is displayed at all times.
|
||||
/// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD.
|
||||
class QuadTreeWorld : public TerrainGrid // note: derived from TerrainGrid is only to render default cells (see loadCell)
|
||||
{
|
||||
public:
|
||||
|
@ -66,6 +66,11 @@ World::~World()
|
||||
delete mStorage;
|
||||
}
|
||||
|
||||
void World::setWorkQueue(SceneUtil::WorkQueue* workQueue)
|
||||
{
|
||||
mCompositeMapRenderer->setWorkQueue(workQueue);
|
||||
}
|
||||
|
||||
void World::setBordersVisible(bool visible)
|
||||
{
|
||||
mBorderVisible = visible;
|
||||
|
@ -25,6 +25,11 @@ namespace Resource
|
||||
class ResourceSystem;
|
||||
}
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
class WorkQueue;
|
||||
}
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
class Storage;
|
||||
@ -60,6 +65,9 @@ namespace Terrain
|
||||
World(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem, Storage* storage, int nodeMask, int preCompileMask, int borderMask);
|
||||
virtual ~World();
|
||||
|
||||
/// Set a WorkQueue to delete objects in the background thread.
|
||||
void setWorkQueue(SceneUtil::WorkQueue* workQueue);
|
||||
|
||||
/// See CompositeMapRenderer::setTargetFrameRate
|
||||
void setTargetFrameRate(float rate);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user