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