mirror of https://github.com/OpenMW/openmw.git
Add CompositeMapRenderer
Temporarily render all terrain using composite maps for testing purposespull/1225/head
parent
e323b2fa7b
commit
b1d4bb5708
@ -0,0 +1,78 @@
|
||||
#include "compositemaprenderer.hpp"
|
||||
|
||||
#include <OpenThreads/ScopedLock>
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
|
||||
CompositeMapRenderer::CompositeMapRenderer()
|
||||
: mNumCompilePerFrame(1)
|
||||
, mLastFrame(0)
|
||||
{
|
||||
setCullingActive(false);
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::traverse(osg::NodeVisitor &nv)
|
||||
{
|
||||
if (nv.getVisitorType() != osg::NodeVisitor::CULL_VISITOR)
|
||||
return;
|
||||
|
||||
if (mLastFrame == nv.getTraversalNumber())
|
||||
return;
|
||||
mLastFrame = nv.getTraversalNumber();
|
||||
|
||||
mCompiled.clear();
|
||||
|
||||
unsigned int numCompiled = 0;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
|
||||
|
||||
while (!mImmediateCompileSet.empty())
|
||||
{
|
||||
osg::Node* node = *mImmediateCompileSet.begin();
|
||||
mCompiled.insert(node);
|
||||
|
||||
node->accept(nv);
|
||||
mImmediateCompileSet.erase(mImmediateCompileSet.begin());
|
||||
|
||||
++numCompiled;
|
||||
}
|
||||
|
||||
while (!mCompileSet.empty() && numCompiled <= mNumCompilePerFrame)
|
||||
{
|
||||
osg::Node* node = *mCompileSet.begin();
|
||||
mCompiled.insert(node);
|
||||
|
||||
node->accept(nv);
|
||||
mCompileSet.erase(mCompileSet.begin());
|
||||
|
||||
++numCompiled;
|
||||
}
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::setNumCompilePerFrame(int num)
|
||||
{
|
||||
mNumCompilePerFrame = num;
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::addCompositeMap(osg::Node *node, bool immediate)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
|
||||
if (immediate)
|
||||
mImmediateCompileSet.insert(node);
|
||||
else
|
||||
mCompileSet.insert(node);
|
||||
}
|
||||
|
||||
void CompositeMapRenderer::setImmediate(osg::Node *node)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mMutex);
|
||||
mImmediateCompileSet.insert(node);
|
||||
mCompileSet.erase(node);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
#ifndef OPENMW_COMPONENTS_TERRAIN_COMPOSITEMAPRENDERER_H
|
||||
#define OPENMW_COMPONENTS_TERRAIN_COMPOSITEMAPRENDERER_H
|
||||
|
||||
#include <osg/Node>
|
||||
|
||||
#include <OpenThreads/Mutex>
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The CompositeMapRenderer is responsible for updating composite map textures in a blocking or non-blocking way.
|
||||
*/
|
||||
class CompositeMapRenderer : public osg::Node
|
||||
{
|
||||
public:
|
||||
CompositeMapRenderer();
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
/// Set the maximum number of (non-immediate) composite maps to compile per frame
|
||||
void setNumCompilePerFrame(int num);
|
||||
|
||||
/// Add a composite map to be rendered
|
||||
void addCompositeMap(osg::Node* node, bool immediate=false);
|
||||
|
||||
/// Mark this composite map to be required for the current frame
|
||||
void setImmediate(osg::Node* node);
|
||||
|
||||
private:
|
||||
unsigned int mNumCompilePerFrame;
|
||||
unsigned int mLastFrame;
|
||||
|
||||
typedef std::set<osg::ref_ptr<osg::Node> > CompileSet;
|
||||
|
||||
CompileSet mCompileSet;
|
||||
CompileSet mImmediateCompileSet;
|
||||
|
||||
CompileSet mCompiled;
|
||||
|
||||
OpenThreads::Mutex mMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue