OSG创建渲染线程的过程

OSG创建渲染线程的过程

 

图形渲染线程是静态函数,为:

static unsigned int __stdcall StartThread(void *data)

它是在int Thread::start()中被调用:

int Thread::start()

{

pd->tid.set( (void*)_beginthreadex(NULL,pd->stackSize,ThreadPrivateActions::StartThread,static_cast<void *>(this),0,&ID));

。。。

}

 

int ViewerBase::run()

{

    if (!isRealized())

    {

        realize();

    }

  if( ){

        while (!done())

        {

            frame();

        }

    }

}

 

void Viewer::realize()

{

  。。

setUpViewAcrossAllScreens();

setUpThreading();

}

 

void ViewerBase::setUpThreading()

{

  。。

  startThreading();

}

 

void ViewerBase::startThreading()

{

switch(_threadingModel):

case(DrawThreadPerContext)://此处被执行

 

osg::ref_ptr<osg::BarrierOperation> swapReadyBarrier = contexts.empty() ? 0 : newosg::BarrierOperation(contexts.size(), osg::BarrierOperation::NO_OPERATION);

 

    osg::ref_ptr<osg::SwapBuffersOperation> swapOp = new osg::SwapBuffersOperation();

 

gc->createGraphicsThread();

 

gc->getGraphicsThread()->add(new osg::RunOperations());

 

gc->getGraphicsThread()->startThread();

}

----------

void GraphicsContext::createGraphicsThread()

{

    if (!_graphicsThread)//初始时,_graphicsThread= false;

    {

        setGraphicsThread(new GraphicsThread);//此行被执行

    }

}

void GraphicsContext::setGraphicsThread(GraphicsThread* gt)

{

_graphicsThread = gt;

。。。

    _graphicsThread->setParent(this);  

}

---------

int Thread::startThread()

{

    if (_prvData) return start();

    else return 0;

}

int Thread::start() {    pd->tid.set( (void*)_beginthreadex(NULL,pd->stackSize,ThreadPrivateActions::StartThread,static_cast<void *>(this),0,&ID));

 

pd->threadStartedBlock.block();/*主线程阻塞,启动图形渲染线程,static unsigned int __stdcall StartThread(void *data)函数被调用,而且StartThread ()函数中执行到pd->threadStartedBlock.release();后,切换到主线程*/

}

----------

void ViewerBase::frame(double simulationTime)

{

    advance(simulationTime);

   

    eventTraversal();

    updateTraversal();

    renderingTraversals();

}

void ViewerBase::renderingTraversals()

{  。。

    for(Cameras::iterator camItr = cameras.begin();

        camItr != cameras.end();        ++camItr)

    {      

        if (renderer)

        {

            if (!renderer->getGraphicsThreadDoesCull() && !(camera->getCameraThread()))

            {

                renderer->cull();//会被执行

            }

        }

}

 

if (!((*itr)->getGraphicsThread()) && (*itr)->valid())//测试时,没有被调用

    {   makeCurrent(*itr);//测试时,没有被调用

        (*itr)->runOperations();//测试时,没有被调用

    }

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值