]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/SGPagedLOD.cxx
Merge branch 'next' of git.gitorious.org:fg/simgear into next
[simgear.git] / simgear / scene / model / SGPagedLOD.cxx
1 // Copyright (C) 2008 Till Busch buti@bux.at
2 //
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.
7 //
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.
12 //
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.
16
17 #ifdef HAVE_CONFIG_H
18 #  include <simgear_config.h>
19 #endif
20
21 #include <osgDB/ReadFile>
22 #include <osgDB/Input>
23 #include <osgDB/ParameterOutput>
24 #include <osgDB/DatabasePager>
25
26 #include <simgear/debug/logstream.hxx>
27 #include <simgear/structure/OSGVersion.hxx>
28
29 #include "modellib.hxx"
30 #include "SGReaderWriterXMLOptions.hxx"
31 #include "SGPagedLOD.hxx"
32
33 #include <simgear/math/SGMath.hxx>
34
35 using namespace osg;
36 using namespace simgear;
37
38 bool SGPagedLOD::_cache = true;
39
40 SGPagedLOD::SGPagedLOD()
41         : PagedLOD()
42 {
43 }
44
45 SGPagedLOD::~SGPagedLOD()
46 {
47     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::~SGPagedLOD(" << getFileName(0) << ")");
48 }
49
50 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
51         : osg::PagedLOD(plod, copyop)
52 #if !SG_PAGEDLOD_HAS_OPTIONS
53         ,  _readerWriterOptions(plod._readerWriterOptions)
54 #endif
55 {
56 }
57
58 void
59 SGPagedLOD::setReaderWriterOptions(osgDB::ReaderWriter::Options *options)
60 {
61     if (_cache)
62         options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
63     else
64         options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
65 #if SG_PAGEDLOD_HAS_OPTIONS
66     setDatabaseOptions(options);
67 #else
68     _readerWriterOptions = options;
69 #endif
70 }
71
72 bool SGPagedLOD::addChild(osg::Node *child)
73 {
74     if (!PagedLOD::addChild(child))
75         return false;
76
77     setRadius(getBound().radius());
78     setCenter(getBound().center());
79     return true;
80 }
81
82 // Work around interface change in osgDB::DatabasePager::requestNodeFile
83 struct NodePathProxy
84 {
85     NodePathProxy(NodePath& nodePath)
86         : _nodePath(nodePath)
87     {
88     }
89     operator Group* () { return static_cast<Group*>(_nodePath.back()); }
90     operator NodePath& () { return _nodePath; }
91     NodePath& _nodePath;
92 };
93
94 void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
95                            NodePath& path)
96 {
97     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
98     //getFileName(getNumChildren()) << ")");
99     unsigned childNum = getNumChildren();
100     setTimeStamp(childNum, 0);
101     double priority=1.0;
102     dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
103                          priority, framestamp,
104                          getDatabaseRequest(childNum),
105                          getReaderWriterOptions());
106 }
107
108 bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)
109 {
110     return true;
111 }
112
113 namespace
114 {
115 osgDB::RegisterDotOsgWrapperProxy sgPagedLODProxy
116 (
117     new SGPagedLOD,
118     "simgear::SGPagedLOD",
119     "Object Node LOD PagedLOD SGPagedLOD Group",
120     0,
121     &SGPagedLOD_writeLocalData
122     );
123 }