osgEarth的Rex引擎原理分析(八十三)rex引擎打开图层的过程

本文详细分析了osgEarth中图层的打开过程,包括设置属性、缓存管理、瓦片源创建等步骤,并探讨了Rex引擎如何处理图层,涉及瓦片缓存策略、二级缓存大小、瓦片源创建以及不同图层类型的处理。此外,还列出了后续将要分析的诸多问题,如图层添加到引擎、地理信息引擎节点创建等。
摘要由CSDN通过智能技术生成

目标:(八十二)中的问题162

图层在创建完成后,需要添加到osgEarth::Map中,添加过程中会执行图层的打开操作。每个图层只打开一次,打开过的图层就不再打开了。

osgEarth/TerrainLayer.cpp
const Status&
TerrainLayer::open()
{
    if ( !_openCalled )
    {
        // Call base class
        if (VisibleLayer::open().isError())
            return getStatus();

        // Create an L2 mem cache that sits atop the main cache, if necessary.
        // For now: use the same L2 cache size at the driver.
        int l2CacheSize = options().driver()->L2CacheSize().get();
    
        // See if it was overridden with an env var.
        char const* l2env = ::getenv( "OSGEARTH_L2_CACHE_SIZE" );
        if ( l2env )
        {
            l2CacheSize = as<int>( std::string(l2env), 0 );
            OE_INFO << LC << "L2 cache size set from environment = " << l2CacheSize << "\n";
        }

        // Env cache-only mode also disables the L2 cache.
        char const* noCacheEnv = ::getenv( "OSGEARTH_MEMORY_PROFILE" );
        if ( noCacheEnv )
        {
            l2CacheSize = 0;
        }

        // Initialize the l2 cache if it's size is > 0
        if ( l2CacheSize > 0 )
        {
            _memCache = new MemCache( l2CacheSize );
        }

        // create the unique cache ID for the cache bin.
        //std::string cacheId;

        if (options().cacheId().isSet() && !options().cacheId()->empty())
        {
            // user expliticy set a cacheId in the terrain layer options.
            // this appears to be a NOP; review for removal -gw
            _runtimeCacheId = options().cacheId().get();
        }
        else
        {
            // system will generate a cacheId from the layer configuration.
            Config hashConf = options().getConfig();

            // remove non-data properties.
            hashConf.remove("name");
            hashConf.remove("enabled");
            hashConf.remove("cacheid");
            hashConf.remove("cache_only");
            hashConf.remove("cache_enabled");
            hashConf.remove("cache_policy");
            hashConf.remove("visible");
            hashConf.remove("l2_cache_size");

            OE_DEBUG << "hashConfFinal = " << hashConf.toJSON(true) << std::endl;

            unsigned hash = osgEarth::hashString(hashConf.toJSON());
            _runtimeCacheId = Stringify() << std::hex << std::setw(8) << std::setfill('0') << hash;
        }

        // Now that we know the cache ID, establish the cache settings for this Layer.
        // Start by cloning whatever CacheSettings were inherited in the read options
        // (typically from the Map).
        CacheSettings* oldSettings = CacheSettings::get(_readOptions.get());
        _cacheSettings = oldSettings ? new CacheSettings(*oldSettings) : new CacheSettings();

        // Store for further propagation!
        _cacheSettings->store(_readOptions.get());

        // Integrate a cache policy from this Layer's options:
        _cacheSettings->integrateCachePolicy(options().cachePolicy());


        // If you created the layer with a pre-created tile source, it will already by set.
        if (!_tileSource.valid())
        {
            osg::ref_ptr<TileSource> ts;

            // as long as we're not in cache-only mode, try to create the TileSource.
            if (_cacheSettings->cachePolicy()->isCacheOnly())
            {
                OE_INFO << LC << "Opening in cache-only mode\n";
            }
            else if (isTileSourceExpected())
            {
                // Initialize the tile source once and only once.
                ts = createAndOpenTileSource();
            }

            // All good
            if (ts.valid() && !_tileSource.valid())
            {
                _tileS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值