osgEarth示例分析——osgearth_shadergen

前言

osgearth_shadergen示例,加载一个earth文件,出现一个地球,然后通过StateSetCache::dumpStats() 方法输出一些信息。并不太理解这个例子的目的。

执行命令与输出结果:

// cmd 命令
osgearth_shadergend.exe earth_image\world.earth

// cmd 输出结果
[osgEarth]  [StateSetCache] StateSetCache Dump:
    attr attempts     = 9
    ineligibles attrs = 0
    attr share hits   = 3
    attr share misses = 6

效果

osgEarth示例分析——osgearth_shadergen_第1张图片

 代码分析

#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 

#define LC "[shadergen] "

using namespace osgEarth;

int
usage(const char* name)
{
    OE_NOTICE << "\nUsage: " << name << " file" << std::endl;
    return 0;
}

int
main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);

    // help?
    if ( arguments.read("--help") || argc < 2 )
        return usage(argv[0]);

    // create a viewer:
    osgViewer::Viewer viewer(arguments);

    StateSetCache* cache = Registry::stateSetCache();
    cache->setMaxSize(INT_MAX);

    // load the .earth file
    osg::ref_ptr node = osgDB::readRefNodeFile(
        Stringify() << argv[1] << ".osgearth_shadergen" );

    if (!node.valid())
        return usage(argv[0]);

    if ( cache )
        cache->dumpStats();// 此处输出结果到控制台

#if 0
    osgUtil::Optimizer o;
    o.optimize( node,
        osgUtil::Optimizer::INDEX_MESH |
        osgUtil::Optimizer::VERTEX_PRETRANSFORM |
        osgUtil::Optimizer::VERTEX_POSTTRANSFORM );
#endif

    viewer.setSceneData( node.get() );
    viewer.addEventHandler(new osgViewer::StatsHandler());
    viewer.addEventHandler(new osgViewer::WindowSizeHandler());
    viewer.addEventHandler(new osgViewer::ThreadingHandler());
    viewer.addEventHandler(new osgViewer::LODScaleHandler());
    viewer.addEventHandler(new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()));
    viewer.run();
    return 0;
}

你可能感兴趣的:(osgEarth,c++)