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

Revision 8633, 2.6 kB (checked in by robert, 6 years ago)

First cut of osgDB::ImagePager? for updating osg::ImageSequence?

  • 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
[8633]80
[7209]81Scene* Scene::getScene(osg::Node* node)
[5757]82{
[7209]83    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_sceneCacheMutex);
84    for(SceneCache::iterator itr = s_sceneCache.begin();
85        itr != s_sceneCache.end();
86        ++itr)
87    {
88        Scene* scene = itr->get();
89        if (scene && scene->getSceneData()==node) return scene;
[5757]90    }
[7209]91    return 0;
[5757]92}
93
[7453]94Scene* Scene::getOrCreateScene(osg::Node* node)
95{
96    if (!node) return 0;
97
98    osgViewer::Scene* scene = getScene(node);
99    if (!scene)
100    {
101        scene = new Scene;
102        scene->setSceneData(node);
103    }
104
105    return scene;
106}
Note: See TracBrowser for help on using the browser.