Changed the Viewer::realize() calls across to not using the threading paramter
leaving it up to the Viewer to specify the mode (which by default is MultiThreaded). Added a check for the presence of osgParticle systems so that threading is disabled in this case.
This commit is contained in:
@@ -242,7 +242,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -204,7 +204,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootNode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -187,7 +187,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -187,7 +187,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -53,7 +53,7 @@ class CameraPacket {
|
||||
void getModelView(osg::Matrix& matrix,float angle_offset=0.0f)
|
||||
{
|
||||
|
||||
matrix = _matrix * osg::Matrix::rotate(angle_offset,0.0f,1.0f,1.0f);
|
||||
matrix = _matrix * osg::Matrix::rotate(angle_offset,0.0f,1.0f,0.0f);
|
||||
}
|
||||
|
||||
void checkByteOrder( void )
|
||||
@@ -164,7 +164,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootnode.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
// objects for managing the broadcasting and recieving of camera packets.
|
||||
Broadcaster bc;
|
||||
|
||||
@@ -231,7 +231,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -171,7 +171,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -688,7 +688,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( root );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -147,7 +147,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -164,7 +164,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(group.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -319,7 +319,7 @@ int main( int argc, char **argv )
|
||||
// register trackball, flight and drive.
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -423,7 +423,7 @@ int main( int argc, char **argv )
|
||||
//osgDB::writeNodeFile(*keyboardModel->getScene(),"test.osg");
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
|
||||
while( !viewer.done() )
|
||||
|
||||
@@ -347,7 +347,7 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
// set all the sceneview's up so that their left and right add cull masks are set up.
|
||||
for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin();
|
||||
|
||||
@@ -159,7 +159,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -445,7 +445,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( node );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -98,7 +98,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -346,7 +346,7 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
if (manuallyCreateOccluders)
|
||||
{
|
||||
|
||||
@@ -385,7 +385,7 @@ int main(int argc, char **argv)
|
||||
viewer.setSceneData(root);
|
||||
|
||||
// create the windows and run the threads.
|
||||
// viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
// viewer.realize();
|
||||
// run single threaded since osgParticle still writes during cull.
|
||||
viewer.realize(Producer::CameraGroup::SingleThreaded);
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootNode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
g_pPixelBuffer = new PBuffer(512,512);
|
||||
g_pPixelBuffer->initialize();
|
||||
|
||||
@@ -430,7 +430,7 @@ int main( int argc, char **argv )
|
||||
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -393,7 +393,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootNode.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( rootnode );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -185,7 +185,7 @@ int main( int argc, char **argv )
|
||||
viewer.getEventHandlerList().push_front(new MyEventHandler(&seq));
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -215,7 +215,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( model );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -121,7 +121,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( node );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -471,7 +471,7 @@ int main( int argc, char **argv )
|
||||
if (ds) ds->setStereo(true);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
// now the windows have been realized we switch off the cursor to prevent it
|
||||
// distracting the people seeing the stereo images.
|
||||
|
||||
@@ -352,7 +352,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( createTeapot() );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -516,7 +516,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(rootNode.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -201,7 +201,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( loadedModel );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -723,7 +723,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData( rootNode );
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -263,7 +263,7 @@ int main( int argc, char **argv )
|
||||
viewer.setRealizeCallback(new ConstructStateCallback(rootNode));
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -402,7 +402,7 @@ int main(int argc, char *argv[])
|
||||
viewer.setSceneData(rootnode);
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -77,7 +77,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -109,8 +109,7 @@ int main( int argc, char **argv )
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
|
||||
// create the windows and run the threads.
|
||||
// viewer.realize(Producer::CameraGroup::ThreadPerCamera);
|
||||
viewer.realize(Producer::CameraGroup::SingleThreaded);
|
||||
viewer.realize();
|
||||
|
||||
while( !viewer.done() )
|
||||
{
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace osgParticle
|
||||
ParticleProcessor();
|
||||
ParticleProcessor(const ParticleProcessor ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual const char *libraryName() const { return "osgParticle"; }
|
||||
virtual const char *className() const { return "ParticleProcessor"; }
|
||||
virtual bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const ParticleProcessor*>(obj) != 0; }
|
||||
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace osgParticle
|
||||
inline VariableRateCounter();
|
||||
inline VariableRateCounter(const VariableRateCounter ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual const char *libraryName() const { return "osgParticle"; }
|
||||
virtual const char *className() const { return "VariableRateCounter"; }
|
||||
virtual bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const VariableRateCounter *>(obj) != 0; }
|
||||
|
||||
|
||||
@@ -137,9 +137,11 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
|
||||
|
||||
void advance();
|
||||
|
||||
/** Set the threading model and then call realize().*/
|
||||
virtual bool realize(ThreadingModel thread_model );
|
||||
|
||||
/** Realize the render surfaces (OpenGL graphics) and various threads, and call any realize callbacks.*/
|
||||
virtual void realize( ThreadingModel thread_model= SingleThreaded );
|
||||
virtual bool realize();
|
||||
|
||||
/** Set the model view matrix of the camera group,
|
||||
* by individually set all the camera groups's camera.*/
|
||||
|
||||
@@ -72,7 +72,10 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
|
||||
|
||||
bool done() const { return _done; }
|
||||
|
||||
virtual void realize( ThreadingModel thread_model= SingleThreaded );
|
||||
/** Set the threading model and then call realize().*/
|
||||
virtual bool realize(ThreadingModel thread_model);
|
||||
|
||||
virtual bool realize();
|
||||
|
||||
virtual void sync();
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ OsgCameraGroup::OsgCameraGroup(osg::ArgumentParser& arguments):
|
||||
|
||||
void OsgCameraGroup::_init()
|
||||
{
|
||||
_thread_model = ThreadPerCamera;
|
||||
|
||||
_scene_data = NULL;
|
||||
_global_stateset = NULL;
|
||||
_background_color.set( 0.2f, 0.2f, 0.4f, 1.0f );
|
||||
@@ -230,11 +232,40 @@ void OsgCameraGroup::advance()
|
||||
CameraGroup::advance();
|
||||
}
|
||||
|
||||
void OsgCameraGroup::realize( ThreadingModel thread_model)
|
||||
bool OsgCameraGroup::realize( ThreadingModel thread_model )
|
||||
{
|
||||
if( _initialized ) return;
|
||||
if( _realized ) return _realized;
|
||||
_thread_model = thread_model;
|
||||
return realize();
|
||||
}
|
||||
|
||||
|
||||
// small visitor to check for the existance of particle systems,
|
||||
// which currently arn't thread safe, so we would need to disable
|
||||
// multithreading of cull and draw.
|
||||
class SearchForParticleNodes : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
SearchForParticleNodes():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_foundParticles(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void apply(osg::Node& node)
|
||||
{
|
||||
if (strcmp(node.libraryName(),"osgParticle")==0) _foundParticles = true;
|
||||
if (!_foundParticles) traverse(node);
|
||||
}
|
||||
|
||||
|
||||
bool _foundParticles;
|
||||
};
|
||||
|
||||
bool OsgCameraGroup::realize()
|
||||
{
|
||||
if( _initialized ) return _realized;
|
||||
|
||||
if (!_ds) _ds = osg::DisplaySettings::instance();
|
||||
|
||||
_ds->setMaxNumberOfGraphicsContexts( _cfg->getNumberOfCameras() );
|
||||
@@ -319,9 +350,22 @@ void OsgCameraGroup::realize( ThreadingModel thread_model)
|
||||
}
|
||||
|
||||
setUpSceneViewsWithData();
|
||||
|
||||
if (getTopMostSceneData() && _thread_model!=Producer::CameraGroup::SingleThreaded)
|
||||
{
|
||||
SearchForParticleNodes sfpn;
|
||||
getTopMostSceneData()->accept(sfpn);
|
||||
if (sfpn._foundParticles)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning: disabling multi-threading of cull and draw"<<std::endl;
|
||||
osg::notify(osg::NOTICE)<<" to avoid threading problems in osgParticle."<<std::endl;
|
||||
_thread_model = Producer::CameraGroup::SingleThreaded;
|
||||
}
|
||||
}
|
||||
|
||||
CameraGroup::realize( thread_model );
|
||||
_initialized = true;
|
||||
_initialized = CameraGroup::realize();
|
||||
|
||||
return _initialized;
|
||||
}
|
||||
|
||||
osg::Node* OsgCameraGroup::getTopMostSceneData()
|
||||
|
||||
@@ -172,16 +172,23 @@ unsigned int Viewer::addCameraManipulator(osgGA::CameraManipulator* cm)
|
||||
return num;
|
||||
}
|
||||
|
||||
|
||||
void Viewer::realize( ThreadingModel thread_model)
|
||||
bool Viewer::realize( ThreadingModel thread_model )
|
||||
{
|
||||
if( _realized ) return _realized;
|
||||
_thread_model = thread_model;
|
||||
return realize();
|
||||
}
|
||||
|
||||
OsgCameraGroup::realize( thread_model );
|
||||
bool Viewer::realize()
|
||||
{
|
||||
if (_realized) return _realized;
|
||||
|
||||
OsgCameraGroup::realize();
|
||||
|
||||
// force a sync before we intialize the keyswitch manipulator to home
|
||||
// so that Producer has a chance to set up the windows before we do
|
||||
// any work on them.
|
||||
//OsgCameraGroup::sync();
|
||||
OsgCameraGroup::sync();
|
||||
|
||||
if (_keyswitchManipulator.valid() && _keyswitchManipulator->getCurrentCameraManipulator())
|
||||
{
|
||||
@@ -201,6 +208,7 @@ void Viewer::realize( ThreadingModel thread_model)
|
||||
(*p)->setCamera(_old_style_osg_camera.get());
|
||||
}
|
||||
|
||||
return _realized;
|
||||
}
|
||||
|
||||
void Viewer::sync()
|
||||
|
||||
Reference in New Issue
Block a user