diff --git a/components/terrain/compositemaprenderer.cpp b/components/terrain/compositemaprenderer.cpp index 2b7a33686..8e63575f1 100644 --- a/components/terrain/compositemaprenderer.cpp +++ b/components/terrain/compositemaprenderer.cpp @@ -10,7 +10,7 @@ namespace Terrain { CompositeMapRenderer::CompositeMapRenderer() - : mNumCompilePerFrame(1) + : mTimeAvailable(0.0005) { setSupportsDisplayList(false); setCullingActive(false); @@ -24,8 +24,6 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const { mCompiled.clear(); - unsigned int numCompiled = 0; - OpenThreads::ScopedLock lock(mMutex); if (mImmediateCompileSet.empty() && mCompileSet.empty()) @@ -36,28 +34,27 @@ void CompositeMapRenderer::drawImplementation(osg::RenderInfo &renderInfo) const CompositeMap* node = *mImmediateCompileSet.begin(); mCompiled.insert(node); - compile(*node, renderInfo); + compile(*node, renderInfo, NULL); mImmediateCompileSet.erase(mImmediateCompileSet.begin()); - - ++numCompiled; } - while (!mCompileSet.empty() && numCompiled <= mNumCompilePerFrame) + double timeLeft = mTimeAvailable; + + while (!mCompileSet.empty() && timeLeft > 0) { CompositeMap* node = *mCompileSet.begin(); - compile(*node, renderInfo); - - ++numCompiled; + compile(*node, renderInfo, &timeLeft); mCompiled.insert(node); mCompileSet.erase(mCompileSet.begin()); } } -void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo &renderInfo) const +void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo &renderInfo, double* timeLeft) const { + osg::Timer timer; osg::State& state = *renderInfo.getState(); osg::GLExtensions* ext = state.get(); @@ -102,11 +99,14 @@ void CompositeMapRenderer::compile(CompositeMap &compositeMap, osg::RenderInfo & GLuint fboId = state.getGraphicsContext() ? state.getGraphicsContext()->getDefaultFboId() : 0; ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fboId); + + if (timeLeft) + *timeLeft -= timer.time_s(); } -void CompositeMapRenderer::setNumCompilePerFrame(int num) +void CompositeMapRenderer::setTimeAvailableForCompile(double time) { - mNumCompilePerFrame = num; + mTimeAvailable = time; } void CompositeMapRenderer::addCompositeMap(CompositeMap* compositeMap, bool immediate) diff --git a/components/terrain/compositemaprenderer.hpp b/components/terrain/compositemaprenderer.hpp index c3579d8bb..5bc45da45 100644 --- a/components/terrain/compositemaprenderer.hpp +++ b/components/terrain/compositemaprenderer.hpp @@ -35,10 +35,10 @@ namespace Terrain virtual void drawImplementation(osg::RenderInfo& renderInfo) const; - void compile(CompositeMap& compositeMap, osg::RenderInfo& renderInfo) const; + void compile(CompositeMap& compositeMap, osg::RenderInfo& renderInfo, double* timeLeft) const; - /// Set the maximum number of (non-immediate) composite maps to compile per frame - void setNumCompilePerFrame(int num); + /// Set the available time in seconds for compiling (non-immediate) composite maps each frame + void setTimeAvailableForCompile(double time); /// Add a composite map to be rendered void addCompositeMap(CompositeMap* map, bool immediate=false); @@ -47,7 +47,7 @@ namespace Terrain void setImmediate(CompositeMap* map); private: - unsigned int mNumCompilePerFrame; + double mTimeAvailable; typedef std::set > CompileSet;