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
22 #define FLIGHTGEAR_SCENERYPAGERHXX 1
26 #include <osg/FrameStamp>
28 #include <osgDB/DatabasePager>
30 #include <simgear/structure/OSGVersion.hxx>
34 class SceneryPager : public osgDB::DatabasePager
38 SceneryPager(const SceneryPager& rhs);
39 // Unhide DatabasePager::requestNodeFile
40 using osgDB::DatabasePager::requestNodeFile;
41 // reimplement to add readerWriterOptions from SGPagedLOD
42 virtual void requestNodeFile(const std::string& fileName, osg::Group* group,
44 const osg::FrameStamp* framestamp,
45 osg::ref_ptr<osg::Referenced>& databaseRequest,
46 #if SG_OSG_MIN_VERSION_REQUIRED(2,9,5)
47 const osg::Referenced* options
49 osgDB::ReaderWriter::Options* options
52 void queueRequest(const std::string& fileName, osg::Group* node,
53 float priority, osg::FrameStamp* frameStamp,
54 osg::ref_ptr<osg::Referenced>& databaseRequest,
55 osgDB::ReaderWriter::Options* options);
56 // This is passed a ref_ptr so that it can "take ownership" of the
57 // node to delete and decrement its refcount while holding the
58 // lock on the delete list.
59 void queueDeleteRequest(osg::ref_ptr<osg::Object>& objptr);
60 virtual void signalEndFrame();
62 // Queue up file requests until the end of the frame
65 PagerRequest() : _priority(0.0f), _databaseRequest(0) {}
66 PagerRequest(const PagerRequest& rhs) :
67 _fileName(rhs._fileName), _group(rhs._group),
68 _priority(rhs._priority), _frameStamp(rhs._frameStamp),
69 _options(rhs._options), _databaseRequest(rhs._databaseRequest) {}
71 PagerRequest(const std::string& fileName, osg::Group* group,
72 float priority, osg::FrameStamp* frameStamp,
73 osg::ref_ptr<Referenced>& databaseRequest,
74 osgDB::ReaderWriter::Options* options):
75 _fileName(fileName), _group(group), _priority(priority),
76 _frameStamp(frameStamp), _options(options),
77 _databaseRequest(&databaseRequest)
80 void doRequest(SceneryPager* pager)
82 if (_group->getNumChildren() == 0)
83 pager->requestNodeFile(_fileName, _group.get(), _priority,
89 std::string _fileName;
90 osg::ref_ptr<osg::Group> _group;
92 osg::ref_ptr<osg::FrameStamp> _frameStamp;
93 osg::ref_ptr<osgDB::ReaderWriter::Options> _options;
94 osg::ref_ptr<osg::Referenced>* _databaseRequest;
96 typedef std::vector<PagerRequest> PagerRequestList;
97 PagerRequestList _pagerRequests;
98 typedef std::vector<osg::ref_ptr<osg::Object> > DeleteRequestList;
99 DeleteRequestList _deleteRequests;
100 virtual ~SceneryPager();