Use the time elapsed instead of # compiled as limit

0.6.1
scrawl 8 years ago
parent 8a6d909b22
commit 47ca8aeee5

@ -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<OpenThreads::Mutex> 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<osg::GLExtensions>();
@ -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)

@ -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<osg::ref_ptr<CompositeMap> > CompileSet;

Loading…
Cancel
Save