具有多个图形上下文的OpenSceneGraph分页地形

时间:2018-07-02 17:53:51

标签: c++ opengl openscenegraph

我正在尝试使用两个查看同一场景的窗口运行 OpenSceneGraph 。我通过构造具有单独图形上下文的两个视图来做到这一点。在大多数情况下,一切都按我的预期进行。我遇到的问题是,当我加载页面地形数据库时,性能会大大降低。我是使用以下所述的两个单独的图形上下文,还是使用具有相同上下文的两个单独的视图。表演需要大量潜水。一张视图的地形表现就很好。

具有一个视图: enter image description here 有两个视图: Two Views

#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgViewer/ViewerEventHandlers>

int main(int argc, char** argv)
{
    auto terrain = osgDB::readRefNodeFile("archive.txp");
    osgViewer::CompositeViewer viewer;
    viewer.setThreadingModel(osgViewer::ViewerBase::ThreadingModel::SingleThreaded);

    {
        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
        traits->x = 80;
        traits->y = 80;
        traits->height = 720;
        traits->width = 1280;
        traits->windowDecoration = true;
        traits->windowName = "One";
        traits->doubleBuffer = true;
        traits->sharedContext = nullptr;

        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits);
        gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        osg::ref_ptr<osgViewer::View> view = new osgViewer::View();
        view->getCamera()->setGraphicsContext(gc);
        view->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
        view->getCamera()->setClearColor(osg::Vec4d(0.2, 0.2, 0.2, 1.0));
        view->setCameraManipulator(new osgGA::TrackballManipulator());
        view->setSceneData(terrain);
        view->addEventHandler(new osgViewer::StatsHandler);
        viewer.addView(view);
    }

    {
        osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits();
        traits->x = 80;
        traits->y = 80;
        traits->height = 720;
        traits->width = 1280;
        traits->windowDecoration = true;
        traits->windowName = "Two";
        traits->doubleBuffer = true;
        traits->sharedContext = nullptr;

        osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits);
        gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        osg::ref_ptr<osgViewer::View> view = new osgViewer::View();
        view->getCamera()->setGraphicsContext(gc);
        view->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));
        view->getCamera()->setClearColor(osg::Vec4d(0.2, 0.2, 0.2, 1.0));
        view->setCameraManipulator(new osgGA::TrackballManipulator());
        view->setSceneData(terrain);
        view->addEventHandler(new osgViewer::StatsHandler);
        viewer.addView(view);
    }

    while(viewer.done() == false)
    {
        viewer.frame();
    }

    return 0;
}

很显然,当两个视图都在同一地形上时,还会发生许多其他遍历。我在VTune中对此进行了概要分析,并证实了页面LOD遍历是罪魁祸首。是否需要配置某种优化/清除设置才能处理具有多个视图的分页数据库?

Function / Call Stack   CPU Time
osg::PagedLOD::traverse 18.170s 
osg::Group::traverse    14.624s
osg::PagedLOD::accept   7.617s

0 个答案:

没有答案