osgEarth::Cache* Registry::getDefaultCache() const { if (!_defaultCache.valid()) { std::string driverName = getDefaultCacheDriverName(); Threading::ScopedMutexLock lock(_regMutex); if (!_defaultCache.valid()) { const char* noCache = ::getenv(OSGEARTH_ENV_NO_CACHE); if (noCache == 0L) { // see if there's a cache in the envvar; if so, create a cache. // Note: the value of the OSGEARTH_CACHE_PATH is not used here; rather // it's used in the driver(s) itself. const char* cachePath = ::getenv(OSGEARTH_ENV_CACHE_PATH); if (cachePath && !driverName.empty()) { CacheOptions cacheOptions; cacheOptions.setDriver(driverName); _defaultCache = CacheFactory::create(cacheOptions); } } } } return _defaultCache.get(); }
Registry::Registry() : osg::Referenced ( true ), _gdal_registered ( false ), _numGdalMutexGets ( 0 ), _uidGen ( 0 ), _caps ( 0L ), _defaultFont ( 0L ), _terrainEngineDriver( "mp" ), _cacheDriver ( "filesystem" ) { // set up GDAL and OGR. OGRRegisterAll(); GDALAllRegister(); // support Chinese character in the file name and attributes in ESRI's shapefile CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO"); CPLSetConfigOption("SHAPE_ENCODING",""); // global initialization for CURL (not thread safe) HTTPClient::globalInit(); // generates the basic shader code for the terrain engine and model layers. _shaderLib = new ShaderFactory(); // shader generator used internally by osgEarth. Can be replaced. _shaderGen = new ShaderGenerator(); // thread pool for general use _taskServiceManager = new TaskServiceManager(); // optimizes sharing of state attributes and state sets for // performance boost _stateSetCache = new StateSetCache(); // Default unref-after apply policy: _unRefImageDataAfterApply = true; // Default object index for tracking scene object by UID. _objectIndex = new ObjectIndex(); // activate KMZ support osgDB::Registry::instance()->addArchiveExtension ( "kmz" ); osgDB::Registry::instance()->addFileExtensionAlias( "kmz", "kml" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kml+xml", "kml" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/vnd.google-earth.kmz", "kmz" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/plain", "osgb" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/xml", "osgb" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "application/json", "osgb" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/json", "osgb" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "text/x-json", "osgb" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "image/jpg", "jpg" ); osgDB::Registry::instance()->addMimeTypeExtensionMapping( "image/dds", "dds" ); // pre-load OSG's ZIP plugin so that we can use it in URIs std::string zipLib = osgDB::Registry::instance()->createLibraryNameForExtension( "zip" ); if ( !zipLib.empty() ) osgDB::Registry::instance()->loadLibrary( zipLib ); // set up our default r/w options to NOT cache archives! _defaultOptions = new osgDB::Options(); _defaultOptions->setObjectCacheHint( osgDB::Options::CACHE_NONE ); // activate no-cache mode from the environment if ( ::getenv(OSGEARTH_ENV_NO_CACHE) ) { _overrideCachePolicy = CachePolicy::NO_CACHE; OE_INFO << LC << "NO-CACHE MODE set from environment" << std::endl; } else { // activate cache-only mode from the environment if ( ::getenv(OSGEARTH_ENV_CACHE_ONLY) ) { _overrideCachePolicy->usage() = CachePolicy::USAGE_CACHE_ONLY; OE_INFO << LC << "CACHE-ONLY MODE set from environment" << std::endl; } // see if the environment specifies a default caching driver. const char* cacheDriver = ::getenv(OSGEARTH_ENV_CACHE_DRIVER); if ( cacheDriver ) { setDefaultCacheDriverName( cacheDriver ); OE_INFO << LC << "Cache driver set from environment: " << getDefaultCacheDriverName() << std::endl; } // cache max age? const char* cacheMaxAge = ::getenv(OSGEARTH_ENV_CACHE_MAX_AGE); if ( cacheMaxAge ) { TimeSpan maxAge = osgEarth::as<long>( std::string(cacheMaxAge), INT_MAX ); _overrideCachePolicy->maxAge() = maxAge; } // see if there's a cache in the envvar; if so, create a cache. // Note: the value of the OSGEARTH_CACHE_PATH is not used here; rather // it's used in the driver(s) itself. const char* cachePath = ::getenv(OSGEARTH_ENV_CACHE_PATH); if ( cachePath ) { CacheOptions options; options.setDriver( getDefaultCacheDriverName() ); osg::ref_ptr<Cache> cache = CacheFactory::create(options); if ( cache->isOK() ) { setCache( cache.get() ); } else { OE_WARN << LC << "FAILED to initialize cache from environment" << std::endl; } } } const char* teStr = ::getenv(OSGEARTH_ENV_TERRAIN_ENGINE_DRIVER); if ( teStr ) { _terrainEngineDriver = std::string(teStr); } // load a default font const char* envFont = ::getenv("OSGEARTH_DEFAULT_FONT"); if ( envFont ) { _defaultFont = osgText::readFontFile( std::string(envFont) ); } if ( !_defaultFont.valid() ) { #ifdef WIN32 _defaultFont = osgText::readFontFile("arial.ttf"); #endif } if ( _defaultFont.valid() ) { // mitigates mipmapping issues that cause rendering artifacts // for some fonts/placement _defaultFont->setGlyphImageMargin( 2 ); } // register the system stock Units. Units::registerAll( this ); }