Delete composite map layers in the background thread

pull/2264/head
bzzt 6 years ago committed by Andrei Kortunov
parent c6cb91ce61
commit aa5a071aef

@ -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;

@ -24,6 +24,11 @@ namespace Resource
class ResourceSystem;
}
namespace SceneUtil
{
class WorkQueue;
}
namespace Terrain
{
class Storage;
@ -59,6 +64,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…
Cancel
Save