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:
Robert Osfield
2003-04-08 15:18:45 +00:00
parent afef5ad2fa
commit e928bca4c9
41 changed files with 105 additions and 47 deletions

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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;

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )

View File

@@ -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();

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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)
{

View File

@@ -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);

View File

@@ -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();

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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.

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -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() )
{

View File

@@ -46,6 +46,7 @@ namespace osgParticle
ParticleProcessor();
ParticleProcessor(const ParticleProcessor &copy, const osg::CopyOp &copyop = 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(); } }

View File

@@ -29,6 +29,7 @@ namespace osgParticle
inline VariableRateCounter();
inline VariableRateCounter(const VariableRateCounter &copy, const osg::CopyOp &copyop = 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; }

View File

@@ -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.*/

View File

@@ -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();

View File

@@ -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()

View File

@@ -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()