Ported across Viewer's to use osgUtil::GLObjectOperation, added second option
in GLObjectOperation to handle cases when no subgraph is registered, in these case the code now compile all Camera subgraphs.
This commit is contained in:
@@ -117,6 +117,8 @@ class OSGUTIL_EXPORT GLObjectsOperation : public osg::GraphicsOperation
|
||||
{
|
||||
public:
|
||||
|
||||
GLObjectsOperation(GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
|
||||
|
||||
GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode = GLObjectsVisitor::COMPILE_DISPLAY_LISTS|GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|GLObjectsVisitor::CHECK_BLACK_LISTED_MODES);
|
||||
|
||||
virtual void operator () (osg::GraphicsContext* context);
|
||||
|
||||
@@ -139,6 +139,12 @@ void GLObjectsVisitor::apply(osg::StateSet& stateset)
|
||||
}
|
||||
}
|
||||
|
||||
GLObjectsOperation::GLObjectsOperation(GLObjectsVisitor::Mode mode):
|
||||
osg::GraphicsOperation("GLObjectOperation",false),
|
||||
_mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
GLObjectsOperation::GLObjectsOperation(osg::Node* subgraph, GLObjectsVisitor::Mode mode):
|
||||
osg::GraphicsOperation("GLObjectOperation",false),
|
||||
_subgraph(subgraph),
|
||||
@@ -150,9 +156,23 @@ void GLObjectsOperation::operator () (osg::GraphicsContext* context)
|
||||
{
|
||||
GLObjectsVisitor glObjectsVisitor(_mode);
|
||||
|
||||
context->getState()->initializeExtensionProcs();
|
||||
|
||||
glObjectsVisitor.setState(context->getState());
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"GLObjectsOperation::before <<<<<<<<<<<"<<std::endl;
|
||||
_subgraph->accept(glObjectsVisitor);
|
||||
if (_subgraph.valid())
|
||||
{
|
||||
_subgraph->accept(glObjectsVisitor);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(osg::GraphicsContext::Cameras::iterator itr = context->getCameras().begin();
|
||||
itr != context->getCameras().end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->accept(glObjectsVisitor);
|
||||
}
|
||||
}
|
||||
// osg::notify(osg::NOTICE)<<"GLObjectsOperation::after >>>>>>>>>>> "<<std::endl;
|
||||
}
|
||||
|
||||
@@ -254,39 +254,6 @@ void CompositeViewer::stopThreading()
|
||||
_numThreadsOnBarrier = 0;
|
||||
}
|
||||
|
||||
// Compile operation, that compile OpenGL objects.
|
||||
struct CompositeViewerCompileOperation : public osg::Operation
|
||||
{
|
||||
CompositeViewerCompileOperation():
|
||||
osg::Operation("Compile",false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator () (osg::Object* object)
|
||||
{
|
||||
osg::GraphicsContext* context = dynamic_cast<osg::GraphicsContext*>(object);
|
||||
if (!context) return;
|
||||
|
||||
// OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
|
||||
// osg::notify(osg::NOTICE)<<"Compile "<<context<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
|
||||
|
||||
context->getState()->initializeExtensionProcs();
|
||||
|
||||
osgUtil::GLObjectsVisitor compileVisitor;
|
||||
compileVisitor.setState(context->getState());
|
||||
|
||||
for(osg::GraphicsContext::Cameras::iterator itr = context->getCameras().begin();
|
||||
itr != context->getCameras().end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->accept(compileVisitor);
|
||||
}
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Done Compile "<<context<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Draw operation, that does a draw on the scene graph.
|
||||
struct CompositeViewerRunOperations : public osg::Operation
|
||||
{
|
||||
@@ -400,7 +367,7 @@ void CompositeViewer::startThreading()
|
||||
|
||||
if (affinity) gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
|
||||
|
||||
gc->getGraphicsThread()->add(new CompositeViewerCompileOperation());
|
||||
gc->getGraphicsThread()->add(new osgUtil::GLObjectsOperation());
|
||||
|
||||
// add the startRenderingBarrier
|
||||
gc->getGraphicsThread()->add(_startRenderingBarrier.get());
|
||||
|
||||
@@ -1029,37 +1029,6 @@ void Viewer::stopThreading()
|
||||
osg::notify(osg::INFO)<<"Viewer::stopThreading() - stopped threading."<<std::endl;
|
||||
}
|
||||
|
||||
// Compile operation, that compile OpenGL objects.
|
||||
struct ViewerCompileOperation : public osg::GraphicsOperation
|
||||
{
|
||||
ViewerCompileOperation(osg::Node* scene):
|
||||
osg::GraphicsOperation("Compile",false),
|
||||
_scene(scene)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void operator () (osg::GraphicsContext* context)
|
||||
{
|
||||
// OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mutex);
|
||||
// osg::notify(osg::NOTICE)<<"Compile "<<context<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
|
||||
|
||||
// context->makeCurrent();
|
||||
|
||||
context->getState()->initializeExtensionProcs();
|
||||
|
||||
osgUtil::GLObjectsVisitor compileVisitor;
|
||||
compileVisitor.setState(context->getState());
|
||||
|
||||
// do the compile traversal
|
||||
if (_scene.valid()) _scene->accept(compileVisitor);
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Done Compile "<<context<<" "<<OpenThreads::Thread::CurrentThread()<<std::endl;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Node> _scene;
|
||||
};
|
||||
|
||||
|
||||
// Draw operation, that does a draw on the scene graph.
|
||||
struct ViewerRunOperations : public osg::GraphicsOperation
|
||||
{
|
||||
@@ -1265,7 +1234,7 @@ void Viewer::startThreading()
|
||||
if (affinity) gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
|
||||
threadAffinityMap[gc->getGraphicsThread()] = processNum % numProcessors;
|
||||
|
||||
gc->getGraphicsThread()->add(new ViewerCompileOperation(getSceneData()));
|
||||
gc->getGraphicsThread()->add(new osgUtil::GLObjectsOperation());
|
||||
|
||||
// add the startRenderingBarrier
|
||||
if (_threadingModel==CullDrawThreadPerContext && _startRenderingBarrier.valid()) gc->getGraphicsThread()->add(_startRenderingBarrier.get());
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
BEGIN_OBJECT_REFLECTOR(osgUtil::GLObjectsOperation)
|
||||
I_DeclaringFile("osgUtil/GLObjectsVisitor");
|
||||
I_BaseType(osg::GraphicsOperation);
|
||||
I_ConstructorWithDefaults1(IN, osgUtil::GLObjectsVisitor::Mode, mode, osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS|osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|osgUtil::GLObjectsVisitor::CHECK_BLACK_LISTED_MODES,
|
||||
Properties::NON_EXPLICIT,
|
||||
____GLObjectsOperation__GLObjectsVisitor_Mode,
|
||||
"",
|
||||
"");
|
||||
I_ConstructorWithDefaults2(IN, osg::Node *, subgraph, , IN, osgUtil::GLObjectsVisitor::Mode, mode, osgUtil::GLObjectsVisitor::COMPILE_DISPLAY_LISTS|osgUtil::GLObjectsVisitor::COMPILE_STATE_ATTRIBUTES|osgUtil::GLObjectsVisitor::CHECK_BLACK_LISTED_MODES,
|
||||
____GLObjectsOperation__osg_Node_P1__GLObjectsVisitor_Mode,
|
||||
"",
|
||||
|
||||
Reference in New Issue
Block a user