Moved IncrementalCompileOperation out of include-src/osgUtil/GLObjectVisitor into their own files.

Added support to IncrementCompileOperation for controlling how much time is alloted to compilation and flush
This commit is contained in:
Robert Osfield
2009-03-12 15:21:04 +00:00
parent c3fc21fa82
commit 7b5f3ec92a
8 changed files with 641 additions and 477 deletions

View File

@@ -131,124 +131,6 @@ class OSGUTIL_EXPORT GLObjectsOperation : public osg::GraphicsOperation
GLObjectsVisitor::Mode _mode;
};
class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
{
public:
IncrementalCompileOperation();
typedef std::vector<osg::GraphicsContext*> Contexts;
void assignContexts(Contexts& contexts);
void removeContexts(Contexts& contexts);
void addGraphicsContext(osg::GraphicsContext* gc);
void removeGraphicsContext(osg::GraphicsContext* gc);
/** Merge subgraphs that have been compiled.*/
void mergeCompiledSubgraphs();
virtual void operator () (osg::GraphicsContext* context);
struct CompileData : public osg::Referenced
{
typedef std::list< osg::ref_ptr<osg::Drawable> > Drawables;
typedef std::list< osg::ref_ptr<osg::Texture> > Textures;
typedef std::list< osg::ref_ptr<osg::Program> > Programs;
bool empty() const { return _drawables.empty() && _textures.empty() && _programs.empty(); }
Drawables _drawables;
Textures _textures;
Programs _programs;
};
class CompileSet;
typedef std::set<osg::GraphicsContext*> ContextSet;
typedef std::map<osg::GraphicsContext*, CompileData > CompileMap;
struct CompileCompletedCallback : public osg::Referenced
{
virtual bool compileCompleted(CompileSet* compileSet) = 0;
};
class CompileSet : public osg::Referenced
{
public:
CompileSet() {}
CompileSet(osg::Node*subgraphToCompile):
_subgraphToCompile(subgraphToCompile) {}
CompileSet(osg::Group* attachmentPoint, osg::Node*subgraphToCompile):
_attachmentPoint(attachmentPoint),
_subgraphToCompile(subgraphToCompile) {}
void buildCompileMap(ContextSet& context, GLObjectsVisitor::Mode mode=GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES);
bool compileCompleted() const
{
for(CompileMap::const_iterator itr = _compileMap.begin();
itr != _compileMap.end();
++itr)
{
if (!(itr->second.empty())) return false;
}
return true;
}
osg::ref_ptr<osg::Group> _attachmentPoint;
osg::ref_ptr<osg::Node> _subgraphToCompile;
osg::ref_ptr<CompileCompletedCallback> _compileCompletedCallback;
CompileMap _compileMap;
// protected:
virtual ~CompileSet() {}
};
typedef std::list< osg::ref_ptr<CompileSet> > CompileSets;
/** Add a subgraph to be compiled.*/
void add(osg::Node* subgraphToCompile);
/** Add a subgraph to be compiled and add automatically to attachPoint on call to mergeCompiledSubgraphs.*/
void add(osg::Group* attachmentPoint, osg::Node* subgraphToCompile);
/** Add a CompileSet to be compiled.*/
void add(CompileSet* compileSet, bool callBuildCompileMap=true);
OpenThreads::Mutex* getToCompiledMutex() { return &_toCompileMutex; }
CompileSets& getToCompile() { return _compiled; }
OpenThreads::Mutex* getCompiledMutex() { return &_compiledMutex; }
CompileSets& getCompiled() { return _compiled; }
protected:
virtual ~IncrementalCompileOperation();
// forward declare to keep within class namespace
class CollectStateToCompile;
OpenThreads::Mutex _toCompileMutex;
CompileSets _toCompile;
OpenThreads::Mutex _compiledMutex;
CompileSets _compiled;
ContextSet _contexts;
};
}
#endif