1 // Copyright (C) 2008 Till Busch buti@bux.at
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # include <simgear_config.h>
21 #include <osgDB/ReadFile>
22 #include <osgDB/Input>
23 #include <osgDB/ParameterOutput>
24 #include <osgDB/DatabasePager>
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/structure/OSGVersion.hxx>
29 #include "modellib.hxx"
30 #include "SGReaderWriterXMLOptions.hxx"
31 #include "SGPagedLOD.hxx"
33 #include <simgear/math/SGMath.hxx>
36 using namespace simgear;
38 bool SGPagedLOD::_cache = true;
40 SGPagedLOD::SGPagedLOD()
45 SGPagedLOD::~SGPagedLOD()
47 //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::~SGPagedLOD(" << getFileName(0) << ")");
50 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
51 : osg::PagedLOD(plod, copyop)
52 #if !SG_PAGEDLOD_HAS_OPTIONS
53 , _readerWriterOptions(plod._readerWriterOptions)
59 SGPagedLOD::setReaderWriterOptions(osgDB::ReaderWriter::Options *options)
62 options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
64 options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
65 #if SG_PAGEDLOD_HAS_OPTIONS
66 setDatabaseOptions(options);
68 _readerWriterOptions = options;
72 bool SGPagedLOD::addChild(osg::Node *child)
74 if (!PagedLOD::addChild(child))
77 setRadius(getBound().radius());
78 setCenter(getBound().center());
82 // Work around interface change in osgDB::DatabasePager::requestNodeFile
85 NodePathProxy(NodePath& nodePath)
89 operator Group* () { return static_cast<Group*>(_nodePath.back()); }
90 operator NodePath& () { return _nodePath; }
94 void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
97 //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
98 //getFileName(getNumChildren()) << ")");
99 unsigned childNum = getNumChildren();
100 setTimeStamp(childNum, 0);
102 dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
103 priority, framestamp,
104 getDatabaseRequest(childNum),
105 getReaderWriterOptions());
108 bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)
115 osgDB::RegisterDotOsgWrapperProxy sgPagedLODProxy
118 "simgear::SGPagedLOD",
119 "Object Node LOD PagedLOD SGPagedLOD Group",
121 &SGPagedLOD_writeLocalData