1 // SceneryPager.hxx -- Interface to OSG database pager
3 // Copyright (C) 2007 Tim Moore timoore@redhat.com
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of the
8 // License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #ifndef FLIGHTGEAR_SCENERYPAGERHXX
25 #include <osg/FrameStamp>
27 #include <osgDB/DatabasePager>
29 #include <simgear/structure/OSGVersion.hxx>
31 // Pager request change in OpenSceneGraph 2.5.1
32 #if SG_OSG_VERSION >= 25001
38 class SceneryPager : public osgDB::DatabasePager
42 SceneryPager(const SceneryPager& rhs);
43 // Unhide DatabasePager::requestNodeFile
44 using osgDB::DatabasePager::requestNodeFile;
45 // reimplement to add readerWriterOptions from SGPagedLOD
46 virtual void requestNodeFile(const std::string& fileName, osg::Group* group,
48 const osg::FrameStamp* framestamp
50 , osg::ref_ptr<osg::Referenced>&
54 void queueRequest(const std::string& fileName, osg::Group* node,
55 float priority, osg::FrameStamp* frameStamp,
57 osg::ref_ptr<osg::Referenced>& databaseRequest,
59 osgDB::ReaderWriter::Options* options);
60 // This is passed a ref_ptr so that it can "take ownership" of the
61 // node to delete and decrement its refcount while holding the
62 // lock on the delete list.
63 void queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr);
64 virtual void signalEndFrame();
66 // Queue up file requests until the end of the frame
69 PagerRequest() : _priority(0.0f), _databaseRequest(0) {}
70 PagerRequest(const PagerRequest& rhs) :
71 _fileName(rhs._fileName), _group(rhs._group),
72 _priority(rhs._priority), _frameStamp(rhs._frameStamp),
73 _options(rhs._options), _databaseRequest(rhs._databaseRequest) {}
75 PagerRequest(const std::string& fileName, osg::Group* group,
76 float priority, osg::FrameStamp* frameStamp,
78 osg::ref_ptr<Referenced>& databaseRequest,
80 osgDB::ReaderWriter::Options* options):
81 _fileName(fileName), _group(group), _priority(priority),
82 _frameStamp(frameStamp), _options(options),
84 _databaseRequest(&databaseRequest)
90 void doRequest(SceneryPager* pager)
92 if (_group->getNumChildren() == 0)
93 pager->requestNodeFile(_fileName, _group.get(), _priority,
101 std::string _fileName;
102 osg::ref_ptr<osg::Group> _group;
104 osg::ref_ptr<osg::FrameStamp> _frameStamp;
105 osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
106 osg::ref_ptr<osg::Referenced>* _databaseRequest;
108 typedef std::vector<PagerRequest> PagerRequestList;
109 PagerRequestList _pagerRequests;
110 typedef std::vector<osg::ref_ptr<osg::Object> > DeleteRequestList;
111 DeleteRequestList _deleteRequests;
112 virtual ~SceneryPager();
115 #define FLIGHTGEAR_SCENERYPAGERHXX 1