2 ******************************************************************************
5 * @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2016.
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "utils/utility.h"
31 #include "utils/qtwindowingsystem.h"
33 #include "utils/pathutils.h"
35 #include <osg/DisplaySettings>
36 #include <osg/GraphicsContext>
37 #include <osg/Version>
39 #include <osgDB/Registry>
42 #include <osgEarth/Version>
43 #include <osgEarth/Cache>
44 #include <osgEarth/Capabilities>
45 #include <osgEarth/Registry>
46 #include <osgEarthDrivers/cache_filesystem/FileSystemCache>
51 #ifdef OSG_USE_QT_PRIVATE
52 #include <QtGui/private/qguiapplication_p.h>
53 #include <QtGui/qpa/qplatformintegration.h>
58 bool OsgEarth::registered
= false;
59 bool OsgEarth::initialized
= false;
61 class OSGEARTH_LIB_EXPORT QtNotifyHandler
: public osg::NotifyHandler
{
63 void notify(osg::NotifySeverity severity
, const char *message
);
66 void OsgEarth::registerQmlTypes()
68 // TOOO not thread safe...
74 // use "export OSG_NOTIFY_LEVEL=DEBUG" on command line to enable osg logging
75 // redirect osg logging to Qt
76 osg::setNotifyHandler(new QtNotifyHandler());
81 qDebug() << "OsgEarth::registerQmlTypes - registering Qml types...";
82 osgQtQuick::registerTypes();
85 void OsgEarth::initialize()
87 // TOOO not thread safe...
93 qDebug() << "OsgEarth::initialize - initializing osgearth...";
95 // increase cache (default is 300);
96 // setenv("OSG_MAX_PAGEDLOD", "500", 0);
98 // setenv("OSG_ASSIGN_PBO_TO_IMAGES", "on", 0);
100 // Number of threads in the DatbasePager set up, inclusive of the number of http dedicated threads.
101 osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint(8);
102 osg::DisplaySettings::instance()->setNumOfHttpDatabaseThreadsHint(4);
106 initWindowingSystem();
115 void OsgEarth::initializePathes()
117 // initialize data file path list
118 osgDB::FilePathList
&dataFilePathList
= osgDB::Registry::instance()->getDataFilePathList();
120 dataFilePathList
.push_front((Utils::GetDataPath() + "osgearth").toStdString());
121 dataFilePathList
.push_front((Utils::GetDataPath() + "osgearth/data").toStdString());
123 // initialize library file path list
124 osgDB::FilePathList
&libraryFilePathList
= osgDB::Registry::instance()->getLibraryFilePathList();
125 libraryFilePathList
.push_front((Utils::GetLibraryPath() + "osg").toStdString());
128 void OsgEarth::initializeCache()
132 QString cachePath
= Utils::GetStoragePath() + "osgearth/cache";
134 qputenv("OSGEARTH_CACHE_PATH", cachePath
.toLatin1());
136 const osgEarth::CachePolicy
cachePolicy(osgEarth::CachePolicy::USAGE_READ_WRITE
);
138 // The default cache policy used when no policy is set elsewhere
139 osgEarth::Registry::instance()->setDefaultCachePolicy(cachePolicy
);
141 // The override cache policy (overrides all others if set)
142 // osgEarth::Registry::instance()->setOverrideCachePolicy(cachePolicy);
144 #endif // ifdef USE_OSGEARTH
147 void OsgEarth::displayInfo()
149 qDebug() << "Using osg version :" << osgGetVersion();
151 qDebug() << "Using osgEarth version :" << osgEarthGetVersion();
154 // library file path list
155 osgDB::FilePathList
&libraryFilePathList
= osgDB::Registry::instance()->getLibraryFilePathList();
156 osgDB::FilePathList::iterator it
= libraryFilePathList
.begin();
157 while (it
!= libraryFilePathList
.end()) {
158 qDebug() << "osg library file path:" << QString::fromStdString(*it
);
162 // data file path list
163 osgDB::FilePathList
&dataFilePathList
= osgDB::Registry::instance()->getDataFilePathList();
164 it
= dataFilePathList
.begin();
165 while (it
!= dataFilePathList
.end()) {
166 qDebug() << "osg data file path:" << QString::fromStdString(*it
);
170 qDebug() << "osg database threads:" << osg::DisplaySettings::instance()->getNumOfDatabaseThreadsHint();
171 qDebug() << "osg http database threads:" << osg::DisplaySettings::instance()->getNumOfHttpDatabaseThreadsHint();
173 // qDebug() << "Platform supports GLSL:" << osgEarth::Registry::capabilities().supportsGLSL();
175 #ifdef OSG_USE_QT_PRIVATE
176 bool threadedOpenGL
= QGuiApplicationPrivate::platform_integration
->hasCapability(QPlatformIntegration::ThreadedOpenGL
);
177 qDebug() << "Platform supports threaded OpenGL:" << threadedOpenGL
;
181 osgQtQuick::capabilitiesInfo(osgEarth::Registry::capabilities());
185 void QtNotifyHandler::notify(osg::NotifySeverity severity
, const char *message
)
187 QString
msg(message
);
189 // right trim message...
190 int n
= msg
.size() - 1;
192 for (; n
>= 0; --n
) {
193 if (!msg
.at(n
).isSpace()) {
197 msg
= msg
.left(n
+ 1);
201 qDebug().noquote() << "[OSG]" << msg
;
204 qCritical().noquote() << "[OSG FATAL]" << msg
;
207 qWarning().noquote() << "[OSG WARN]" << msg
;
210 qDebug().noquote() << "[OSG NOTICE]" << msg
;
213 qDebug().noquote() << "[OSG]" << msg
;
215 case osg::DEBUG_INFO
:
216 qDebug().noquote() << "[OSG DEBUG INFO]" << msg
;
219 qDebug().noquote() << "[OSG DEBUG FP]" << msg
;
224 #if OSG_VERSION_GREATER_OR_EQUAL(3, 5, 3)
225 REGISTER_WINDOWINGSYSTEMINTERFACE(MyQt
, QtWindowingSystem
)
228 void OsgEarth::initWindowingSystem()
230 #if OSG_VERSION_LESS_THAN(3, 5, 3)
231 osg::GraphicsContext::setWindowingSystemInterface(QtWindowingSystem::getInterface());