第二日学习(一) osgViewer::Viewer::isRealized()

首先回顾下目前的流程

osgViewer::viewBase:: frame()

{

viewerInit();[

                          //创建帧事件,并将漫游器与事件和视口相关联

                            ->   osgViewer::Viewer::ViewerInit()

                           ->  osgViewer::View::Init();

                          ->(1)osgGA::EventQueue::createEvent();

                            (2)osgGA::MatrixManipulator::Init();

                            ->(2.1)各种漫游器::init()

                 ]

isRealized();

realize();

advance(simulationTime);

eventTraversal();

updateTraversal();

renderingTraversals();

}

这次要进行isRealized()了,viewerBase::isRealized()是个纯虚函数

        /** Get whether at least of one of this viewers windows are realized.*/
        virtual bool isRealized() const = 0;

翻一下注释就是判断是否至少有一个视口窗口准备好

那就看看派生类单窗口和复合窗口如何实现的.

单窗口


bool Viewer::isRealized() const
{
    Contexts contexts;
    const_cast<Viewer*>(this)->getContexts(contexts);

    unsigned int numRealizedWindows = 0;

    // clear out all the previously assigned operations
    for(Contexts::iterator citr = contexts.begin();
        citr != contexts.end();
        ++citr)
    {
        if ((*citr)->isRealized()) ++numRealizedWindows;
    }
    
    return numRealizedWindows > 0;
}

复合窗口:


bool CompositeViewer::isRealized() const
{
    Contexts contexts;
    const_cast<CompositeViewer*>(this)->getContexts(contexts);

    unsigned int numRealizedWindows = 0;

    // clear out all the previously assigned operations
    for(Contexts::iterator citr = contexts.begin();
        citr != contexts.end();
        ++citr)
    {
        if ((*citr)->isRealized()) ++numRealizedWindows;
    }
    
    return numRealizedWindows > 0;
}

基本上一样,只有转换视口类型不同。

即先获取t图形上下文数组。再遍历上下文数组,只要有一个准备好就Ok

从这个函数中可以看到目前需要分析的是

1,Contexts,

2,osgViewer::Viewer::getContexts().

3,osg::GraphicContext::isRealized()

 

1,在viewerBase中,定义了一个数组
        typedef std::vector<osg::GraphicsContext*> Contexts;

也就是说Contexts是osg::GraphicsContext图形上下文的数组,在上篇也分析过了,这个图形上下文绝不是只有窗口参数,而是有个操作队列,看看这几个成员变量,就知道绝非那么简单

        OpenThreads::Thread*    _threadOfLastMakeCurrent;
        
        OpenThreads::Mutex                  _operationsMutex;
        osg::ref_ptr<osg::RefBlock>         _operationsBlock;
        OperationQueue                      _operations;
        osg::ref_ptr<Operation>             _currentOperation;

        ref_ptr<GraphicsThread>             _graphicsThread;
        
        ref_ptr<ResizedCallback>            _resizedCallback;

 

只是目前我也没看懂,先留个疑问

 

这个isRealized()用在三个地方

frame(),run()和设置线程模型setThreadingModel()

 

现在流程又可以写下了,还是以单窗口为例

 

osgViewer::viewBase:: frame()

{

viewerInit();[

                          //创建帧事件,并将漫游器与事件和视口相关联

                            ->   osgViewer::Viewer::ViewerInit()

                           ->  osgViewer::View::Init();

                          ->(1)osgGA::EventQueue::createEvent();

                            (2)osgGA::MatrixManipulator::Init();

                            ->(2.1)各种漫游器::init()

                 ]

isRealized();[

                                    //获取图形上下文数组。再遍历上下文数组,只要有一个准备好就Ok

                                  ->   osgViewer::Viewer::isRealized();

                                 ->(1)osgViewer::Viewer::getContexts().

                                ->(2)osg::GraphicContext::isRealized()

 

                    ]

realize();

advance(simulationTime);

eventTraversal();

updateTraversal();

renderingTraversals();

}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值