2006-11-27 22:52:07 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
#include <osg/GLExtensions>
|
|
|
|
#include <osgUtil/GLObjectsVisitor>
|
|
|
|
#include <osgGA/TrackballManipulator>
|
2006-11-27 22:52:07 +08:00
|
|
|
#include <osgViewer/CompositeViewer>
|
2007-08-02 19:02:47 +08:00
|
|
|
#include <osgViewer/Renderer>
|
2007-06-06 18:57:02 +08:00
|
|
|
#include <osgDB/Registry>
|
2006-11-27 22:52:07 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
#include <osg/io_utils>
|
|
|
|
|
2006-11-27 22:52:07 +08:00
|
|
|
using namespace osgViewer;
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
CompositeViewer::CompositeViewer()
|
2006-11-27 22:52:07 +08:00
|
|
|
{
|
2007-06-06 18:57:02 +08:00
|
|
|
constructorInit();
|
|
|
|
}
|
|
|
|
|
2007-08-11 18:28:14 +08:00
|
|
|
CompositeViewer::CompositeViewer(const CompositeViewer& cv,const osg::CopyOp& copyop):
|
2007-09-30 00:46:08 +08:00
|
|
|
ViewerBase()
|
2007-08-11 18:28:14 +08:00
|
|
|
{
|
|
|
|
constructorInit();
|
|
|
|
}
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
CompositeViewer::CompositeViewer(osg::ArgumentParser& arguments)
|
|
|
|
{
|
|
|
|
constructorInit();
|
|
|
|
|
2007-09-21 21:30:33 +08:00
|
|
|
std::string filename;
|
|
|
|
bool readConfig = false;
|
|
|
|
while (arguments.read("-c",filename))
|
|
|
|
{
|
|
|
|
readConfig = readConfiguration(filename) || readConfig;
|
|
|
|
}
|
|
|
|
|
2007-06-06 18:57:02 +08:00
|
|
|
while (arguments.read("--SingleThreaded")) setThreadingModel(SingleThreaded);
|
2007-10-03 05:23:58 +08:00
|
|
|
while (arguments.read("--CullDrawThreadPerContext")) setThreadingModel(CullDrawThreadPerContext);
|
|
|
|
while (arguments.read("--DrawThreadPerContext")) setThreadingModel(DrawThreadPerContext);
|
|
|
|
while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) setThreadingModel(CullThreadPerCameraDrawThreadPerContext);
|
2007-06-06 18:57:02 +08:00
|
|
|
|
|
|
|
osg::DisplaySettings::instance()->readCommandLine(arguments);
|
|
|
|
osgDB::readCommandLine(arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositeViewer::constructorInit()
|
|
|
|
{
|
|
|
|
_endBarrierPosition = AfterSwapBuffers;
|
|
|
|
_startTick = 0;
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
// make sure View is safe to reference multi-threaded.
|
|
|
|
setThreadSafeRefUnref(true);
|
|
|
|
|
|
|
|
_frameStamp = new osg::FrameStamp;
|
|
|
|
_frameStamp->setFrameNumber(0);
|
|
|
|
_frameStamp->setReferenceTime(0);
|
2007-01-25 20:02:51 +08:00
|
|
|
_frameStamp->setSimulationTime(0);
|
2007-09-30 00:46:08 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
_eventVisitor = new osgGA::EventVisitor;
|
2007-08-10 18:52:35 +08:00
|
|
|
_eventVisitor->setFrameStamp(_frameStamp.get());
|
2007-09-30 00:46:08 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
_updateVisitor = new osgUtil::UpdateVisitor;
|
|
|
|
_updateVisitor->setFrameStamp(_frameStamp.get());
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
setStats(new osg::Stats("CompsiteViewer"));
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CompositeViewer::~CompositeViewer()
|
|
|
|
{
|
2007-01-17 00:01:01 +08:00
|
|
|
osg::notify(osg::INFO)<<"CompositeViewer::~CompositeViewer()"<<std::endl;
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
stopThreading();
|
|
|
|
|
|
|
|
Scenes scenes;
|
|
|
|
getScenes(scenes);
|
|
|
|
|
|
|
|
for(Scenes::iterator sitr = scenes.begin();
|
|
|
|
sitr != scenes.end();
|
|
|
|
++sitr)
|
|
|
|
{
|
|
|
|
Scene* scene = *sitr;
|
|
|
|
if (scene->getDatabasePager())
|
|
|
|
{
|
|
|
|
scene->getDatabasePager()->cancel();
|
|
|
|
scene->setDatabasePager(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts);
|
|
|
|
|
|
|
|
// clear out all the previously assigned operations
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
(*citr)->close();
|
|
|
|
}
|
|
|
|
|
2007-01-17 00:01:01 +08:00
|
|
|
osg::notify(osg::INFO)<<"finished CompositeViewer::~CompsiteViewer()"<<std::endl;
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
|
2007-09-21 21:30:33 +08:00
|
|
|
bool CompositeViewer::readConfiguration(const std::string& filename)
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"CompositeViewer::readConfiguration("<<filename<<")"<<std::endl;
|
2007-09-22 03:04:02 +08:00
|
|
|
return false;
|
2007-09-21 21:30:33 +08:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
void CompositeViewer::addView(osgViewer::View* view)
|
|
|
|
{
|
2007-05-12 03:25:44 +08:00
|
|
|
bool threadsWereRuinning = _threadsRunning;
|
|
|
|
if (threadsWereRuinning) stopThreading();
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
_views.push_back(view);
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
view->_viewerBase = this;
|
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
view->setFrameStamp(_frameStamp.get());
|
|
|
|
|
2007-05-12 03:25:44 +08:00
|
|
|
if (threadsWereRuinning) startThreading();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositeViewer::removeView(osgViewer::View* view)
|
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator itr = _views.begin();
|
2007-05-12 03:25:44 +08:00
|
|
|
itr != _views.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (*itr == view)
|
|
|
|
{
|
|
|
|
bool threadsWereRuinning = _threadsRunning;
|
|
|
|
if (threadsWereRuinning) stopThreading();
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
view->_viewerBase = 0;
|
|
|
|
|
2007-05-12 03:25:44 +08:00
|
|
|
_views.erase(itr);
|
|
|
|
|
|
|
|
if (threadsWereRuinning) startThreading();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CompositeViewer::isRealized() const
|
|
|
|
{
|
|
|
|
Contexts contexts;
|
|
|
|
const_cast<CompositeViewer*>(this)->getContexts(contexts);
|
|
|
|
|
|
|
|
unsigned int numRealizedWindows = 0;
|
|
|
|
|
|
|
|
// clear out all the previously assigned operations
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
if ((*citr)->isRealized()) ++numRealizedWindows;
|
|
|
|
}
|
|
|
|
|
|
|
|
return numRealizedWindows > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CompositeViewer::run()
|
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator itr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
itr != _views.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgViewer::View* view = itr->get();
|
2007-05-26 23:47:53 +08:00
|
|
|
if ((view->getCameraManipulator()==0) && view->getCamera()->getAllowEventFocus())
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
|
|
|
view->setCameraManipulator(new osgGA::TrackballManipulator());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-03 05:23:58 +08:00
|
|
|
return ViewerBase::run();
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CompositeViewer::setStartTick(osg::Timer_t tick)
|
|
|
|
{
|
|
|
|
_startTick = tick;
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-08-10 18:52:35 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
(*vitr)->setStartTick(tick);
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts,false);
|
|
|
|
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*citr);
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
gw->getEventQueue()->setStartTick(_startTick);
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 22:52:07 +08:00
|
|
|
}
|
2006-11-29 19:00:02 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
void CompositeViewer::setReferenceTime(double time)
|
|
|
|
{
|
|
|
|
osg::Timer_t tick = osg::Timer::instance()->tick();
|
|
|
|
double currentTime = osg::Timer::instance()->delta_s(_startTick, tick);
|
|
|
|
double delta_ticks = (time-currentTime)*(osg::Timer::instance()->getSecondsPerTick());
|
|
|
|
if (delta_ticks>=0) tick += osg::Timer_t(delta_ticks);
|
|
|
|
else tick -= osg::Timer_t(-delta_ticks);
|
|
|
|
|
|
|
|
// assign the new start tick
|
|
|
|
setStartTick(tick);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-03 05:23:58 +08:00
|
|
|
void CompositeViewer::viewerInit()
|
2007-01-02 18:11:53 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
osg::notify(osg::INFO)<<"CompositeViewer::init()"<<std::endl;
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator itr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
itr != _views.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2007-01-17 00:01:01 +08:00
|
|
|
(*itr)->init();
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
2007-01-02 18:11:53 +08:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::getContexts(Contexts& contexts, bool onlyValid)
|
2007-01-09 06:54:02 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
typedef std::set<osg::GraphicsContext*> ContextSet;
|
|
|
|
ContextSet contextSet;
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
osgViewer::View* view = vitr->get();
|
|
|
|
if (view->getCamera() &&
|
|
|
|
view->getCamera()->getGraphicsContext() &&
|
|
|
|
(view->getCamera()->getGraphicsContext()->valid() || !onlyValid))
|
|
|
|
{
|
|
|
|
contextSet.insert(view->getCamera()->getGraphicsContext());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<view->getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
View::Slave& slave = view->getSlave(i);
|
|
|
|
if (slave._camera.valid() &&
|
|
|
|
slave._camera->getGraphicsContext() &&
|
|
|
|
(slave._camera->getGraphicsContext()->valid() || !onlyValid))
|
|
|
|
{
|
|
|
|
contextSet.insert(slave._camera->getGraphicsContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contexts.clear();
|
|
|
|
contexts.reserve(contextSet.size());
|
|
|
|
|
|
|
|
for(ContextSet::iterator itr = contextSet.begin();
|
|
|
|
itr != contextSet.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
contexts.push_back(const_cast<osg::GraphicsContext*>(*itr));
|
|
|
|
}
|
2007-01-09 06:54:02 +08:00
|
|
|
}
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
void CompositeViewer::getCameras(Cameras& cameras, bool onlyActive)
|
|
|
|
{
|
|
|
|
cameras.clear();
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-09-30 00:46:08 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
View* view = vitr->get();
|
|
|
|
|
|
|
|
if (view->getCamera() &&
|
|
|
|
(!onlyActive || (view->getCamera()->getGraphicsContext() && view->getCamera()->getGraphicsContext()->valid())) ) cameras.push_back(view->getCamera());
|
|
|
|
|
|
|
|
for(View::Slaves::iterator itr = view->_slaves.begin();
|
|
|
|
itr != view->_slaves.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->_camera.valid() &&
|
|
|
|
(!onlyActive || (itr->_camera->getGraphicsContext() && itr->_camera->getGraphicsContext()->valid())) ) cameras.push_back(itr->_camera.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::getWindows(Windows& windows, bool onlyValid)
|
|
|
|
{
|
|
|
|
windows.clear();
|
|
|
|
|
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts, onlyValid);
|
|
|
|
|
|
|
|
for(Contexts::iterator itr = contexts.begin();
|
|
|
|
itr != contexts.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*itr);
|
|
|
|
if (gw) windows.push_back(gw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CompositeViewer::getScenes(Scenes& scenes, bool onlyValid)
|
|
|
|
{
|
|
|
|
typedef std::set<osgViewer::Scene*> SceneSet;
|
|
|
|
SceneSet sceneSet;
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
osgViewer::View* view = vitr->get();
|
|
|
|
if (view->getScene() && (!onlyValid || view->getScene()->getSceneData()))
|
|
|
|
{
|
|
|
|
sceneSet.insert(view->getScene());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(SceneSet::iterator sitr = sceneSet.begin();
|
|
|
|
sitr != sceneSet.end();
|
|
|
|
++sitr)
|
|
|
|
{
|
|
|
|
scenes.push_back(const_cast<osgViewer::Scene*>(*sitr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
void CompositeViewer::getViews(Views& views, bool onlyValid)
|
|
|
|
{
|
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
views.push_back(vitr->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-30 00:46:08 +08:00
|
|
|
void CompositeViewer::getAllThreads(Threads& threads, bool onlyActive)
|
|
|
|
{
|
|
|
|
OperationThreads operationThreads;
|
|
|
|
getOperationThreads(operationThreads);
|
|
|
|
|
|
|
|
for(OperationThreads::iterator itr = operationThreads.begin();
|
|
|
|
itr != operationThreads.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
threads.push_back(*itr);
|
|
|
|
}
|
|
|
|
|
|
|
|
Scenes scenes;
|
|
|
|
getScenes(scenes);
|
|
|
|
|
|
|
|
for(Scenes::iterator sitr = scenes.begin();
|
|
|
|
sitr != scenes.end();
|
|
|
|
++sitr)
|
|
|
|
{
|
|
|
|
Scene* scene = *sitr;
|
|
|
|
if (scene->getDatabasePager() &&
|
|
|
|
(!onlyActive || scene->getDatabasePager()->isRunning()))
|
|
|
|
{
|
|
|
|
threads.push_back(scene->getDatabasePager());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CompositeViewer::getOperationThreads(OperationThreads& threads, bool onlyActive)
|
|
|
|
{
|
|
|
|
threads.clear();
|
|
|
|
|
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts);
|
|
|
|
for(Contexts::iterator gcitr = contexts.begin();
|
|
|
|
gcitr != contexts.end();
|
|
|
|
++gcitr)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* gc = *gcitr;
|
|
|
|
if (gc->getGraphicsThread() &&
|
|
|
|
(!onlyActive || gc->getGraphicsThread()->isRunning()) )
|
|
|
|
{
|
|
|
|
threads.push_back(gc->getGraphicsThread());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cameras cameras;
|
|
|
|
getCameras(cameras);
|
|
|
|
for(Cameras::iterator citr = cameras.begin();
|
|
|
|
citr != cameras.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
osg::Camera* camera = *citr;
|
|
|
|
if (camera->getCameraThread() &&
|
|
|
|
(!onlyActive || camera->getCameraThread()->isRunning()) )
|
|
|
|
{
|
|
|
|
threads.push_back(camera->getCameraThread());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::realize()
|
|
|
|
{
|
|
|
|
//osg::notify(osg::INFO)<<"CompositeViewer::realize()"<<std::endl;
|
|
|
|
|
|
|
|
setCameraWithFocus(0);
|
|
|
|
|
|
|
|
if (_views.empty())
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"CompositeViewer::realize() - not views to realize."<<std::endl;
|
|
|
|
_done = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts);
|
|
|
|
|
|
|
|
if (contexts.empty())
|
|
|
|
{
|
|
|
|
osg::notify(osg::INFO)<<"CompositeViewer::realize() - No valid contexts found, setting up view across all screens."<<std::endl;
|
|
|
|
|
|
|
|
// no windows are already set up so set up a default view
|
|
|
|
_views[0]->setUpViewAcrossAllScreens();
|
|
|
|
|
|
|
|
getContexts(contexts);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contexts.empty())
|
|
|
|
{
|
|
|
|
osg::notify(osg::NOTICE)<<"CompositeViewer::realize() - failed to set up any windows"<<std::endl;
|
|
|
|
_done = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
2007-01-29 01:11:21 +08:00
|
|
|
osg::GraphicsContext* gc = *citr;
|
|
|
|
gc->realize();
|
|
|
|
|
2007-05-22 02:46:57 +08:00
|
|
|
if (_realizeOperation.valid() && gc->valid())
|
2007-01-29 01:11:21 +08:00
|
|
|
{
|
|
|
|
gc->makeCurrent();
|
|
|
|
|
|
|
|
(*_realizeOperation)(gc);
|
|
|
|
|
|
|
|
gc->releaseContext();
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool grabFocus = true;
|
|
|
|
if (grabFocus)
|
|
|
|
{
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*citr);
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
gw->grabFocusIfPointerInWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
startThreading();
|
|
|
|
|
|
|
|
// initialize the global timer to be relative to the current time.
|
|
|
|
osg::Timer::instance()->setStartTick();
|
|
|
|
|
|
|
|
// pass on the start tick to all the associated eventqueues
|
|
|
|
setStartTick(osg::Timer::instance()->getStartTick());
|
2007-08-11 22:49:14 +08:00
|
|
|
|
|
|
|
if (osg::DisplaySettings::instance()->getCompileContextsHint())
|
|
|
|
{
|
|
|
|
int numProcessors = OpenThreads::GetNumberOfProcessors();
|
|
|
|
int processNum = 0;
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<= osg::GraphicsContext::getMaxContextID(); ++i)
|
|
|
|
{
|
|
|
|
osg::GraphicsContext* gc = osg::GraphicsContext::getOrCreateCompileContext(i);
|
|
|
|
|
|
|
|
if (gc)
|
|
|
|
{
|
|
|
|
gc->createGraphicsThread();
|
|
|
|
gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors);
|
|
|
|
gc->getGraphicsThread()->startThread();
|
|
|
|
|
|
|
|
++processNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
|
2007-01-25 20:02:51 +08:00
|
|
|
void CompositeViewer::advance(double simulationTime)
|
2006-11-29 19:00:02 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
if (_done) return;
|
2007-09-29 19:41:57 +08:00
|
|
|
|
|
|
|
double prevousReferenceTime = _frameStamp->getReferenceTime();
|
|
|
|
int previousFrameNumber = _frameStamp->getFrameNumber();
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
_frameStamp->setFrameNumber(_frameStamp->getFrameNumber()+1);
|
2007-01-25 20:02:51 +08:00
|
|
|
|
|
|
|
_frameStamp->setReferenceTime( osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()) );
|
|
|
|
|
|
|
|
if (simulationTime==USE_REFERENCE_TIME)
|
|
|
|
{
|
|
|
|
_frameStamp->setSimulationTime(_frameStamp->getReferenceTime());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_frameStamp->setSimulationTime(simulationTime);
|
|
|
|
}
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
if (getStats() && getStats()->collectStats("frame_rate"))
|
2007-09-29 19:41:57 +08:00
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
// update previous frame stats
|
|
|
|
double deltaFrameTime = _frameStamp->getReferenceTime() - prevousReferenceTime;
|
|
|
|
getStats()->setAttribute(previousFrameNumber, "Frame duration", deltaFrameTime);
|
|
|
|
getStats()->setAttribute(previousFrameNumber, "Frame rate", 1.0/deltaFrameTime);
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
// update current frames stats
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Reference time", _frameStamp->getReferenceTime());
|
2007-09-29 19:41:57 +08:00
|
|
|
}
|
2007-09-30 19:37:00 +08:00
|
|
|
|
2006-11-29 19:00:02 +08:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::setCameraWithFocus(osg::Camera* camera)
|
2006-11-29 19:00:02 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
_cameraWithFocus = camera;
|
|
|
|
|
|
|
|
if (camera)
|
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
View* view = vitr->get();
|
|
|
|
if (view->containsCamera(camera))
|
|
|
|
{
|
|
|
|
_viewWithFocus = view;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_viewWithFocus = 0;
|
2006-11-29 19:00:02 +08:00
|
|
|
}
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::eventTraversal()
|
2006-11-29 19:00:02 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
if (_done) return;
|
|
|
|
|
|
|
|
if (_views.empty()) return;
|
2007-09-29 19:41:57 +08:00
|
|
|
|
|
|
|
double beginEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"CompositeViewer::frameEventTraversal()."<<std::endl;
|
|
|
|
|
|
|
|
// need to copy events from the GraphicsWindow's into local EventQueue;
|
2007-01-16 22:15:49 +08:00
|
|
|
|
|
|
|
typedef std::map<osgViewer::View*, osgGA::EventQueue::Events> ViewEventsMap;
|
|
|
|
ViewEventsMap viewEventsMap;
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
Contexts contexts;
|
|
|
|
getContexts(contexts);
|
|
|
|
|
|
|
|
Scenes scenes;
|
|
|
|
getScenes(scenes);
|
|
|
|
|
|
|
|
osgViewer::View* masterView = getViewWithFocus() ? getViewWithFocus() : _views[0].get();
|
|
|
|
|
|
|
|
osg::Camera* masterCamera = masterView->getCamera();
|
|
|
|
osgGA::GUIEventAdapter* eventState = masterView->getEventQueue()->getCurrentEventState();
|
|
|
|
osg::Matrix masterCameraVPW = masterCamera->getViewMatrix() * masterCamera->getProjectionMatrix();
|
|
|
|
if (masterCamera->getViewport())
|
|
|
|
{
|
|
|
|
osg::Viewport* viewport = masterCamera->getViewport();
|
|
|
|
masterCameraVPW *= viewport->computeWindowMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
for(Contexts::iterator citr = contexts.begin();
|
|
|
|
citr != contexts.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(*citr);
|
|
|
|
if (gw)
|
|
|
|
{
|
|
|
|
gw->checkEvents();
|
|
|
|
|
|
|
|
osgGA::EventQueue::Events gw_events;
|
|
|
|
gw->getEventQueue()->takeEvents(gw_events);
|
|
|
|
|
|
|
|
osgGA::EventQueue::Events::iterator itr;
|
|
|
|
for(itr = gw_events.begin();
|
|
|
|
itr != gw_events.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgGA::GUIEventAdapter* event = itr->get();
|
|
|
|
|
|
|
|
bool pointerEvent = false;
|
|
|
|
|
|
|
|
float x = event->getX();
|
|
|
|
float y = event->getY();
|
|
|
|
|
|
|
|
bool invert_y = event->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
|
|
|
if (invert_y && gw->getTraits()) y = gw->getTraits()->height - y;
|
|
|
|
|
|
|
|
switch(event->getEventType())
|
|
|
|
{
|
2007-05-22 21:48:21 +08:00
|
|
|
case(osgGA::GUIEventAdapter::RESIZE):
|
|
|
|
setCameraWithFocus(0);
|
|
|
|
break;
|
2007-01-16 16:56:33 +08:00
|
|
|
case(osgGA::GUIEventAdapter::PUSH):
|
|
|
|
case(osgGA::GUIEventAdapter::RELEASE):
|
|
|
|
case(osgGA::GUIEventAdapter::DRAG):
|
|
|
|
case(osgGA::GUIEventAdapter::MOVE):
|
|
|
|
{
|
|
|
|
pointerEvent = true;
|
|
|
|
|
|
|
|
if (event->getEventType()!=osgGA::GUIEventAdapter::DRAG || !getCameraWithFocus())
|
|
|
|
{
|
|
|
|
osg::GraphicsContext::Cameras& cameras = gw->getCameras();
|
|
|
|
for(osg::GraphicsContext::Cameras::iterator citr = cameras.begin();
|
|
|
|
citr != cameras.end();
|
|
|
|
++citr)
|
|
|
|
{
|
|
|
|
osg::Camera* camera = *citr;
|
2007-02-23 19:51:52 +08:00
|
|
|
if (camera->getView() &&
|
|
|
|
camera->getAllowEventFocus() &&
|
|
|
|
camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-02-23 19:51:52 +08:00
|
|
|
osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
|
|
|
if (viewport &&
|
|
|
|
x >= viewport->x() && y >= viewport->y() &&
|
|
|
|
x <= (viewport->x()+viewport->width()) && y <= (viewport->y()+viewport->height()) )
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-02-23 19:51:52 +08:00
|
|
|
setCameraWithFocus(camera);
|
|
|
|
|
2008-03-05 01:57:06 +08:00
|
|
|
// If this camera is not a slave camera
|
|
|
|
if (camera->getView()->getCamera() == camera)
|
2007-05-22 21:48:21 +08:00
|
|
|
{
|
2008-03-05 01:57:06 +08:00
|
|
|
const osg::GraphicsContext::Traits* traits = gw ? gw->getTraits() : 0;
|
|
|
|
if (traits)
|
|
|
|
{
|
|
|
|
eventState->setInputRange( 0, 0, traits->width, traits->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventState->setInputRange(-1.0, -1.0, 1.0, 1.0);
|
|
|
|
}
|
2007-05-22 21:48:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eventState->setInputRange(-1.0, -1.0, 1.0, 1.0);
|
|
|
|
}
|
|
|
|
|
2007-02-23 19:51:52 +08:00
|
|
|
if (getViewWithFocus()!=masterView)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-02-23 19:51:52 +08:00
|
|
|
// need to reset the masterView
|
|
|
|
masterView = getViewWithFocus();
|
|
|
|
masterCamera = masterView->getCamera();
|
|
|
|
eventState = masterView->getEventQueue()->getCurrentEventState();
|
|
|
|
masterCameraVPW = masterCamera->getViewMatrix() * masterCamera->getProjectionMatrix();
|
2007-05-22 21:48:21 +08:00
|
|
|
|
2007-02-23 19:51:52 +08:00
|
|
|
if (masterCamera->getViewport())
|
|
|
|
{
|
|
|
|
osg::Viewport* viewport = masterCamera->getViewport();
|
|
|
|
masterCameraVPW *= viewport->computeWindowMatrix();
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pointerEvent)
|
|
|
|
{
|
|
|
|
if (getCameraWithFocus())
|
|
|
|
{
|
|
|
|
osg::Viewport* viewport = getCameraWithFocus()->getViewport();
|
|
|
|
osg::Matrix localCameraVPW = getCameraWithFocus()->getViewMatrix() * getCameraWithFocus()->getProjectionMatrix();
|
|
|
|
if (viewport) localCameraVPW *= viewport->computeWindowMatrix();
|
|
|
|
|
|
|
|
osg::Matrix matrix( osg::Matrix::inverse(localCameraVPW) * masterCameraVPW );
|
|
|
|
|
|
|
|
osg::Vec3d new_coord = osg::Vec3d(x,y,0.0) * matrix;
|
|
|
|
|
|
|
|
x = new_coord.x();
|
|
|
|
y = new_coord.y();
|
|
|
|
|
|
|
|
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
|
|
|
event->setX(x);
|
|
|
|
event->setY(y);
|
|
|
|
event->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
|
|
|
|
|
|
|
}
|
|
|
|
// pass along the new pointer events details to the eventState of the viewer
|
|
|
|
eventState->setX(x);
|
|
|
|
eventState->setY(y);
|
|
|
|
eventState->setButtonMask(event->getButtonMask());
|
|
|
|
eventState->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
|
|
|
event->setX(eventState->getX());
|
|
|
|
event->setY(eventState->getY());
|
|
|
|
event->setButtonMask(eventState->getButtonMask());
|
|
|
|
event->setMouseYOrientation(eventState->getMouseYOrientation());
|
|
|
|
}
|
|
|
|
//osg::notify(osg::NOTICE)<<" mouse x = "<<event->getX()<<" y="<<event->getY()<<std::endl;
|
|
|
|
// osg::notify(osg::NOTICE)<<" mouse Xmin = "<<event->getXmin()<<" Ymin="<<event->getYmin()<<" xMax="<<event->getXmax()<<" Ymax="<<event->getYmax()<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(itr = gw_events.begin();
|
|
|
|
itr != gw_events.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgGA::GUIEventAdapter* event = itr->get();
|
|
|
|
switch(event->getEventType())
|
|
|
|
{
|
|
|
|
case(osgGA::GUIEventAdapter::CLOSE_WINDOW):
|
|
|
|
{
|
2007-05-22 02:46:57 +08:00
|
|
|
bool wasThreading = areThreadsRunning();
|
|
|
|
if (wasThreading) stopThreading();
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
gw->close();
|
2007-05-22 02:46:57 +08:00
|
|
|
|
|
|
|
if (wasThreading) startThreading();
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-16 22:15:49 +08:00
|
|
|
viewEventsMap[masterView].insert( viewEventsMap[masterView].end(), gw_events.begin(), gw_events.end() );
|
2007-01-16 16:56:33 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// osg::notify(osg::NOTICE)<<"mouseEventState Xmin = "<<eventState->getXmin()<<" Ymin="<<eventState->getYmin()<<" xMax="<<eventState->getXmax()<<" Ymax="<<eventState->getYmax()<<std::endl;
|
|
|
|
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-01-16 22:15:49 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
View* view = vitr->get();
|
|
|
|
view->getEventQueue()->frame( getFrameStamp()->getReferenceTime() );
|
|
|
|
view->getEventQueue()->takeEvents(viewEventsMap[view]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
2007-01-16 16:56:33 +08:00
|
|
|
_eventQueue->getCurrentEventState()->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
|
|
|
_eventQueue->getCurrentEventState()->setX(eventState->getX());
|
|
|
|
_eventQueue->getCurrentEventState()->setY(eventState->getY());
|
|
|
|
_eventQueue->getCurrentEventState()->setButtonMask(eventState->getButtonMask());
|
|
|
|
_eventQueue->getCurrentEventState()->setMouseYOrientation(eventState->getMouseYOrientation());
|
|
|
|
|
|
|
|
_eventQueue->frame( getFrameStamp()->getReferenceTime() );
|
|
|
|
_eventQueue->takeEvents(events);
|
|
|
|
#endif
|
|
|
|
|
2007-01-16 22:15:49 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
// osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl;
|
|
|
|
|
|
|
|
if ((_keyEventSetsDone!=0) || _quitEventSetsDone)
|
|
|
|
{
|
2007-01-16 22:15:49 +08:00
|
|
|
for(ViewEventsMap::iterator veitr = viewEventsMap.begin();
|
|
|
|
veitr != viewEventsMap.end();
|
|
|
|
++veitr)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-01-16 22:15:49 +08:00
|
|
|
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
|
|
|
itr != veitr->second.end();
|
|
|
|
++itr)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-01-16 22:15:49 +08:00
|
|
|
osgGA::GUIEventAdapter* event = itr->get();
|
|
|
|
switch(event->getEventType())
|
|
|
|
{
|
|
|
|
case(osgGA::GUIEventAdapter::KEYUP):
|
|
|
|
if (_keyEventSetsDone && event->getKey()==_keyEventSetsDone) _done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case(osgGA::GUIEventAdapter::QUIT_APPLICATION):
|
|
|
|
if (_quitEventSetsDone) _done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_done) return;
|
|
|
|
|
2007-01-16 22:15:49 +08:00
|
|
|
for(ViewEventsMap::iterator veitr = viewEventsMap.begin();
|
|
|
|
veitr != viewEventsMap.end();
|
|
|
|
++veitr)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-01-16 22:15:49 +08:00
|
|
|
View* view = veitr->first;
|
2007-01-17 03:18:32 +08:00
|
|
|
_eventVisitor->setActionAdapter(view);
|
|
|
|
|
2007-01-16 22:15:49 +08:00
|
|
|
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
|
|
|
itr != veitr->second.end();
|
2007-01-16 16:56:33 +08:00
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgGA::GUIEventAdapter* event = itr->get();
|
|
|
|
|
2007-01-16 22:15:49 +08:00
|
|
|
for(View::EventHandlers::iterator hitr = view->getEventHandlers().begin();
|
2007-01-24 20:28:18 +08:00
|
|
|
hitr != view->getEventHandlers().end();
|
2007-01-16 22:15:49 +08:00
|
|
|
++hitr)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-09-14 18:44:46 +08:00
|
|
|
(*hitr)->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view, 0, 0);
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
2007-02-26 21:01:17 +08:00
|
|
|
|
|
|
|
if (view->getCameraManipulator())
|
|
|
|
{
|
2007-09-14 18:44:46 +08:00
|
|
|
view->getCameraManipulator()->handleWithCheckAgainstIgnoreHandledEventsMask( *event, *view);
|
2007-02-26 21:01:17 +08:00
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-17 03:18:32 +08:00
|
|
|
if (_eventVisitor.valid())
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
|
|
|
_eventVisitor->setFrameStamp(getFrameStamp());
|
|
|
|
_eventVisitor->setTraversalNumber(getFrameStamp()->getFrameNumber());
|
|
|
|
|
2007-01-17 03:18:32 +08:00
|
|
|
for(ViewEventsMap::iterator veitr = viewEventsMap.begin();
|
|
|
|
veitr != viewEventsMap.end();
|
|
|
|
++veitr)
|
2007-01-16 16:56:33 +08:00
|
|
|
{
|
2007-01-17 03:18:32 +08:00
|
|
|
View* view = veitr->first;
|
2007-02-23 19:51:52 +08:00
|
|
|
if (view->getSceneData())
|
|
|
|
{
|
|
|
|
for(osgGA::EventQueue::Events::iterator itr = veitr->second.begin();
|
|
|
|
itr != veitr->second.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osgGA::GUIEventAdapter* event = itr->get();
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2007-02-23 19:51:52 +08:00
|
|
|
_eventVisitor->reset();
|
|
|
|
_eventVisitor->addEvent( event );
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2007-02-23 19:51:52 +08:00
|
|
|
view->getSceneData()->accept(*_eventVisitor);
|
2007-05-28 01:29:29 +08:00
|
|
|
|
|
|
|
// call any camera update callbacks, but only traverse that callback, don't traverse its subgraph
|
|
|
|
// leave that to the scene update traversal.
|
|
|
|
osg::NodeVisitor::TraversalMode tm = _eventVisitor->getTraversalMode();
|
|
|
|
_eventVisitor->setTraversalMode(osg::NodeVisitor::TRAVERSE_NONE);
|
|
|
|
|
|
|
|
if (view->getCamera() && view->getCamera()->getEventCallback()) view->getCamera()->accept(*_eventVisitor);
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<view->getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
osg::Camera* camera = view->getSlave(i)._camera.get();
|
|
|
|
if (camera && camera->getEventCallback()) camera->accept(*_eventVisitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
_eventVisitor->setTraversalMode(tm);
|
|
|
|
|
2007-02-23 19:51:52 +08:00
|
|
|
}
|
2007-01-17 03:18:32 +08:00
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
2007-05-28 01:29:29 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
|
|
|
|
if (getStats() && getStats()->collectStats("event"))
|
2007-09-29 19:41:57 +08:00
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
double endEventTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
// update current frames stats
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal begin time", beginEventTraversal);
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal end time", endEventTraversal);
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Event traversal time taken", endEventTraversal-beginEventTraversal);
|
2007-09-29 19:41:57 +08:00
|
|
|
}
|
2006-11-29 19:00:02 +08:00
|
|
|
}
|
|
|
|
|
2007-08-11 18:28:14 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
void CompositeViewer::updateTraversal()
|
2006-11-29 19:00:02 +08:00
|
|
|
{
|
2007-01-16 16:56:33 +08:00
|
|
|
if (_done) return;
|
2007-09-29 19:41:57 +08:00
|
|
|
|
|
|
|
double beginUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2008-01-09 22:22:44 +08:00
|
|
|
_updateVisitor->reset();
|
|
|
|
_updateVisitor->setFrameStamp(getFrameStamp());
|
|
|
|
_updateVisitor->setTraversalNumber(getFrameStamp()->getFrameNumber());
|
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
Scenes scenes;
|
|
|
|
getScenes(scenes);
|
|
|
|
for(Scenes::iterator sitr = scenes.begin();
|
|
|
|
sitr != scenes.end();
|
|
|
|
++sitr)
|
|
|
|
{
|
2007-08-10 18:52:35 +08:00
|
|
|
Scene* scene = *sitr;
|
|
|
|
if (scene->getSceneData())
|
|
|
|
{
|
|
|
|
scene->getSceneData()->accept(*_updateVisitor);
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
if (scene->getDatabasePager())
|
|
|
|
{
|
2007-12-11 01:30:18 +08:00
|
|
|
// synchronize changes required by the DatabasePager thread to the scene graph
|
2007-08-10 18:52:35 +08:00
|
|
|
scene->getDatabasePager()->updateSceneGraph(_frameStamp->getReferenceTime());
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
}
|
2007-08-11 18:28:14 +08:00
|
|
|
|
|
|
|
if (_updateOperations.valid())
|
|
|
|
{
|
|
|
|
_updateOperations->runOperations(this);
|
|
|
|
}
|
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::iterator vitr = _views.begin();
|
2007-01-16 16:56:33 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
View* view = vitr->get();
|
2007-05-28 01:29:29 +08:00
|
|
|
|
|
|
|
Scene* scene = view->getScene();
|
2007-08-10 18:52:35 +08:00
|
|
|
|
2007-05-28 01:29:29 +08:00
|
|
|
{
|
|
|
|
// call any camera update callbacks, but only traverse that callback, don't traverse its subgraph
|
|
|
|
// leave that to the scene update traversal.
|
2007-08-10 18:52:35 +08:00
|
|
|
osg::NodeVisitor::TraversalMode tm = _updateVisitor->getTraversalMode();
|
|
|
|
_updateVisitor->setTraversalMode(osg::NodeVisitor::TRAVERSE_NONE);
|
2007-05-28 01:29:29 +08:00
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
if (view->getCamera() && view->getCamera()->getUpdateCallback()) view->getCamera()->accept(*_updateVisitor);
|
2007-05-28 01:29:29 +08:00
|
|
|
|
|
|
|
for(unsigned int i=0; i<view->getNumSlaves(); ++i)
|
|
|
|
{
|
|
|
|
osg::Camera* camera = view->getSlave(i)._camera.get();
|
2007-08-10 18:52:35 +08:00
|
|
|
if (camera && camera->getUpdateCallback()) camera->accept(*_updateVisitor);
|
2007-05-28 01:29:29 +08:00
|
|
|
}
|
|
|
|
|
2007-08-10 18:52:35 +08:00
|
|
|
_updateVisitor->setTraversalMode(tm);
|
2007-05-28 01:29:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-18 03:58:57 +08:00
|
|
|
if (view->getCameraManipulator())
|
|
|
|
{
|
|
|
|
view->setFusionDistance( view->getCameraManipulator()->getFusionDistanceMode(),
|
|
|
|
view->getCameraManipulator()->getFusionDistanceValue() );
|
|
|
|
|
|
|
|
view->getCamera()->setViewMatrix( view->getCameraManipulator()->getInverseMatrix());
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
view->updateSlaves();
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-01-16 16:56:33 +08:00
|
|
|
}
|
2007-09-29 19:41:57 +08:00
|
|
|
|
2007-09-30 19:37:00 +08:00
|
|
|
if (getStats() && getStats()->collectStats("update"))
|
|
|
|
{
|
|
|
|
double endUpdateTraversal = osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
|
|
|
|
|
|
|
// update current frames stats
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal begin time", beginUpdateTraversal);
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal end time", endUpdateTraversal);
|
|
|
|
getStats()->setAttribute(_frameStamp->getFrameNumber(), "Update traversal time taken", endUpdateTraversal-beginUpdateTraversal);
|
|
|
|
}
|
2007-01-16 16:56:33 +08:00
|
|
|
|
2006-11-29 19:00:02 +08:00
|
|
|
}
|
|
|
|
|
2007-10-03 05:23:58 +08:00
|
|
|
double CompositeViewer::elapsedTime()
|
2006-11-29 19:00:02 +08:00
|
|
|
{
|
2007-10-03 05:23:58 +08:00
|
|
|
return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick());
|
2006-11-29 19:00:02 +08:00
|
|
|
}
|
2007-09-30 00:46:08 +08:00
|
|
|
|
|
|
|
void CompositeViewer::getUsage(osg::ApplicationUsage& usage) const
|
|
|
|
{
|
2007-09-30 19:37:00 +08:00
|
|
|
for(RefViews::const_iterator vitr = _views.begin();
|
2007-09-30 00:46:08 +08:00
|
|
|
vitr != _views.end();
|
|
|
|
++vitr)
|
|
|
|
{
|
|
|
|
const View* view = vitr->get();
|
|
|
|
if (view->getCameraManipulator())
|
|
|
|
{
|
|
|
|
view->getCameraManipulator()->getUsage(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(View::EventHandlers::const_iterator hitr = view->_eventHandlers.begin();
|
|
|
|
hitr != view->_eventHandlers.end();
|
|
|
|
++hitr)
|
|
|
|
{
|
|
|
|
(*hitr)->getUsage(usage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|