root/OpenSceneGraph/trunk/src/osgViewer/Scene.cpp @ 10520

Revision 10520, 3.2 kB (checked in by robert, 5 years ago)

Moved the updating and expiry of the Registry object cache from DatabasePager? into osgViewer::Viewer/CompositeViewer.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[5757]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgViewer/Scene>
[5952]15#include <osgGA/EventVisitor>
[5757]16
17using namespace osgViewer;
18
[7209]19typedef std::vector< osg::observer_ptr<Scene> >  SceneCache;
20static OpenThreads::Mutex s_sceneCacheMutex;
21static SceneCache s_sceneCache;
22
[5757]23Scene::Scene():
[7209]24    osg::Referenced(true)
[5757]25{
[7205]26    setDatabasePager(osgDB::DatabasePager::create());
[8633]27    setImagePager(new osgDB::ImagePager);
[7209]28   
29    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
30    s_sceneCache.push_back(this);
[5757]31}
32
33Scene::~Scene()
34{
[7209]35    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
36    for(SceneCache::iterator itr = s_sceneCache.begin();
37        itr != s_sceneCache.end();
38        ++itr)
39    {
40        Scene* scene = itr->get();
41        if (scene==this)
42        {
43            s_sceneCache.erase(itr);
44            break;
45        }
46    }
[5757]47}
48
49void Scene::setSceneData(osg::Node* node)
50{
51    _sceneData = node;
52   
53    if (_databasePager.valid())
54    {   
55        // register any PagedLOD that need to be tracked in the scene graph
[7453]56        if (node) _databasePager->registerPagedLODs(node);
[5757]57    }
58}
59
60osg::Node* Scene::getSceneData()
61{
62    return _sceneData.get();
63}
64
65const osg::Node* Scene::getSceneData() const
66{
67    return _sceneData.get();
68}
69
70void Scene::setDatabasePager(osgDB::DatabasePager* dp)
71{
72    _databasePager = dp;
73}
74
[8633]75void Scene::setImagePager(osgDB::ImagePager* ip)
76{
77    _imagePager = ip;
78}
[6766]79
[10520]80void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor)
81{
82    if (!_sceneData) return;
[8633]83
[10520]84    if (getSceneData())
85    {
86        updateVisitor.setImageRequestHandler(getImagePager());
87        getSceneData()->accept(updateVisitor);
88    }
89
90    if (getDatabasePager())
91    {
92        // synchronize changes required by the DatabasePager thread to the scene graph
93        getDatabasePager()->updateSceneGraph((*updateVisitor.getFrameStamp()));
94    }
95
96    if (getImagePager())
97    {
98        // synchronize changes required by the DatabasePager thread to the scene graph
99        getImagePager()->updateSceneGraph(*(updateVisitor.getFrameStamp()));
100    }
101
102
103}
104
105
[7209]106Scene* Scene::getScene(osg::Node* node)
[5757]107{
[7209]108    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
109    for(SceneCache::iterator itr = s_sceneCache.begin();
110        itr != s_sceneCache.end();
111        ++itr)
112    {
113        Scene* scene = itr->get();
114        if (scene && scene->getSceneData()==node) return scene;
[5757]115    }
[7209]116    return 0;
[5757]117}
118
[7453]119Scene* Scene::getOrCreateScene(osg::Node* node)
120{
121    if (!node) return 0;
122
123    osgViewer::Scene* scene = getScene(node);
124    if (!scene)
125    {
126        scene = new Scene;
127        scene->setSceneData(node);
128    }
129
130    return scene;
131}
Note: See TracBrowser for help on using the browser.