1. 程式人生 > >osgEarth的Rex引擎原理分析(二)osg是如何根據副檔名尋找需要載入的動態連結庫外掛的

osgEarth的Rex引擎原理分析(二)osg是如何根據副檔名尋找需要載入的動態連結庫外掛的

在(一)中有createLibraryNameForFile,它會根據副檔名構造需要載入的動態連結庫

osgDB/Registry.cpp 

ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor){
    ...
    std::string libraryName = createLibraryNameForFile(readFunctor._filename);
    if (loadLibrary(libraryName)!=NOT_LOADED)
    {
        for(;itr.valid();++itr)
        {
            ReaderWriter::ReadResult rr = readFunctor.doRead(*itr);
            if (readFunctor.isValid(rr)) return rr;
            else results.push_back(rr);
        }
    }
    ...
}

createLibraryNameForFile呼叫createLibraryNameForExtension,最終得到要載入的動態連結庫的路徑和名稱

osgDB/Registry.cpp

std::string Registry::createLibraryNameForExtension(const std::string& ext)
{
    std::string lowercase_ext;
    for(std::string::const_iterator sitr=ext.begin();
        sitr!=ext.end();
        ++sitr)
    {
        lowercase_ext.push_back(tolower(*sitr));
    }

    ExtensionAliasMap::iterator itr=_extAliasMap.find(lowercase_ext);
    if (itr!=_extAliasMap.end() && ext != itr->second) return createLibraryNameForExtension(itr->second);

    std::string prepend = std::string("osgPlugins-")+std::string(osgGetVersion())+std::string("/");

#if defined(__CYGWIN__)
    return prepend+"cygwin_"+"osgdb_"+lowercase_ext+OSG_LIBRARY_POSTFIX_WITH_QUOTES+".dll";
#elif defined(__MINGW32__)
    return prepend+"mingw_"+"osgdb_"+lowercase_ext+OSG_LIBRARY_POSTFIX_WITH_QUOTES+".dll";
#elif defined(WIN32)
    return prepend+"osgdb_"+lowercase_ext+OSG_LIBRARY_POSTFIX_WITH_QUOTES+".dll";
#elif macintosh
    return prepend+"osgdb_"+lowercase_ext+OSG_LIBRARY_POSTFIX_WITH_QUOTES;
#else
    return prepend+"osgdb_"+lowercase_ext+OSG_LIBRARY_POSTFIX_WITH_QUOTES+ADDQUOTES(OSG_PLUGIN_EXTENSION);
#endif

}

待繼續分析列表:

1、osg是如何根據副檔名尋找需要載入的動態連結庫外掛的((一)中問題)

2、載入動態庫外掛的過程是什麼((一)中問題)

3、osgDB::Registry的作用是什麼((一)中問題)

4、.earth檔案如何解析成Config((一)中問題)

5、地圖map圖層的構建過程((一)中問題)

6、地圖節點MapNode的構建過程((一)中問題)