一、窗口线程
这里的contexts与每一个窗口对应。这些窗口从主从相机中获得。
osgViewer/ViewBase.cpp
void ViewerBase::startThreading()
{
for(citr = contexts.begin();
citr != contexts.end();
++citr)
{
osg::GraphicsContext* gc = (*citr);
gc->createGraphicsThread();
}
}
这个线程添加了三个Operation,线程运行时就执行这三个Operation。
osgViewer/ViewBase.cpp
void ViewerBase::startThreading()
{
gc->getGraphicsThread()->add(new osg::RunOperations());
gc->getGraphicsThread()->add(_endRenderingDispatchBarrier.get());
gc->getGraphicsThread()->add(swapOp.get());
}
1、RunOperations主要负责进行opengl绘制
osg/GraphicThread.cpp
void RunOperations::operator () (osg::GraphicsContext* context)
{
context->runOperations();
}
osg/GraphicContext.cpp
void GraphicsContext::runOperations()
{
typedef std::vector<Camera*> CameraVector;
CameraVector camerasCopy;
std::copy(_cameras.begin(), _cameras.end(), std::back_inserter(camerasCopy));
std::sort(camerasCopy.begin(