Further work on new threading model.

This commit is contained in:
Robert Osfield
2007-01-31 22:24:20 +00:00
parent 019cdd9116
commit 8dfc5155f4
7 changed files with 795 additions and 254 deletions

View File

@@ -176,6 +176,21 @@ class OSG_EXPORT GraphicsContext : public Referenced
/** Run the operations. */
void runOperations();
typedef std::list< ref_ptr<GraphicsOperation> > OperationQueue;
/** Get the operations queue, not you must use the OperationsMutex when accessing the queue.*/
OperationQueue& getOperationsQueue() { return _operations; }
/** Get the operations queue mutex.*/
OpenThreads::Mutex& getOperationsMutex() { return _operationsMutex; }
/** Get the operations queue block used to mark an empty queue, if you end items into the empty queu you must release this block.*/
osg::Block* getOperationsBlock() { return _operationsBlock.get(); }
/** Get the current operations that is being run.*/
GraphicsOperation* getCurrentOperation() { return _currentOperation.get(); }
public:
/** Get the traits of the GraphicsContext.*/
@@ -354,8 +369,6 @@ class OSG_EXPORT GraphicsContext : public Referenced
OpenThreads::Thread* _threadOfLastMakeCurrent;
typedef std::list< ref_ptr<GraphicsOperation> > OperationQueue;
OpenThreads::Mutex _operationsMutex;
osg::ref_ptr<osg::Block> _operationsBlock;
OperationQueue _operations;

View File

@@ -443,6 +443,9 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
/** Do draw traversal of draw bins generated by cull traversal.*/
virtual void draw();
/** Compute the number of dynamic objects that will be held in the rendering backend */
unsigned int getDynamicObjectCount() const { return _dynamicObjectCount; }
/** Release all OpenGL objects from the scene graph, such as texture objects, display lists etc.
* These released scene graphs placed in the respective delete GLObjects cache, which
* then need to be deleted in OpenGL by SceneView::flushAllDeleteGLObjects(). */
@@ -515,7 +518,7 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
int _interlacedStereoStencilWidth;
int _interlacedStereoStencilHeight;
unsigned int _dynamicObjectCount;
};
}

View File

@@ -29,15 +29,17 @@ class OSGVIEWER_EXPORT EndOfDynamicDrawBlock : public osg::State::DynamicObjectR
{
public:
EndOfDynamicDrawBlock();
EndOfDynamicDrawBlock(unsigned int);
void completed(osg::State* state);
void block();
void reset();
void release();
void set(unsigned int blockCount);
void setNumOfBlocks(unsigned int blockCount);
protected:
@@ -45,6 +47,7 @@ class OSGVIEWER_EXPORT EndOfDynamicDrawBlock : public osg::State::DynamicObjectR
OpenThreads::Mutex _mut;
OpenThreads::Condition _cond;
unsigned int _numberOfBlocks;
unsigned int _blockCount;
};

View File

@@ -170,8 +170,8 @@ class OSGVIEWER_EXPORT Viewer : public osgViewer::View
unsigned int _numThreadsOnBarrier;
typedef std::map<osg::ref_ptr<osg::Camera>, osg::ref_ptr<osgUtil::SceneView> > CameraSceneViewMap;
CameraSceneViewMap _cameraSceneViewMap;
typedef std::list< osg::ref_ptr<osgUtil::SceneView> > SceneViews;
SceneViews _sceneViews;
osg::Timer_t _startTick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;

View File

@@ -116,6 +116,8 @@ SceneView::SceneView(DisplaySettings* ds)
_redrawInterlacedStereoStencilMask = true;
_interlacedStereoStencilWidth = 0;
_interlacedStereoStencilHeight = 0;
_dynamicObjectCount = 0;
}
SceneView::SceneView(const SceneView& rhs, const osg::CopyOp& copyop):
@@ -145,6 +147,8 @@ SceneView::SceneView(const SceneView& rhs, const osg::CopyOp& copyop):
_redrawInterlacedStereoStencilMask = rhs._redrawInterlacedStereoStencilMask;
_interlacedStereoStencilWidth = rhs._interlacedStereoStencilWidth;
_interlacedStereoStencilHeight = rhs._interlacedStereoStencilHeight;
_dynamicObjectCount = 0;
}
SceneView::~SceneView()
@@ -254,7 +258,6 @@ void SceneView::setSceneData(osg::Node* node)
void SceneView::init()
{
_initCalled = true;
// force the initialization of the OpenGL extension string
@@ -494,6 +497,8 @@ osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& vi
void SceneView::cull()
{
_dynamicObjectCount = 0;
if (_camera->getNodeMask()==0) return;
_renderInfo.setView(_camera->getView());
@@ -779,9 +784,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
rendergraph->prune();
// set the number of dynamic objects in the scene.
getState()->setDynamicObjectCount( getState()->getDynamicObjectCount() + renderStage->computeNumberOfDynamicRenderLeaves());
// osg::notify(osg::NOTICE)<<"SceneView cull() DynamicObjectCount"<<getState()->getDynamicObjectCount()<<std::endl;
_dynamicObjectCount += renderStage->computeNumberOfDynamicRenderLeaves();
}
void SceneView::releaseAllGLObjects()

View File

@@ -504,7 +504,8 @@ bool View::computeIntersections(float x,float y, osg::NodePath& nodePath, osgUti
//
// EndOfDynamicDrawBlock
//
EndOfDynamicDrawBlock::EndOfDynamicDrawBlock():
EndOfDynamicDrawBlock::EndOfDynamicDrawBlock(unsigned int numberOfBlocks):
_numberOfBlocks(numberOfBlocks),
_blockCount(0)
{
}
@@ -541,17 +542,23 @@ void EndOfDynamicDrawBlock::release()
}
}
void EndOfDynamicDrawBlock::set(unsigned int blockCount)
void EndOfDynamicDrawBlock::reset()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (blockCount!=_blockCount)
if (_numberOfBlocks!=_blockCount)
{
if (blockCount==0) _cond.broadcast();
_blockCount = blockCount;
if (_numberOfBlocks==0) _cond.broadcast();
_blockCount = _numberOfBlocks;
}
}
void EndOfDynamicDrawBlock::setNumOfBlocks(unsigned int blockCount)
{
_numberOfBlocks = blockCount;
}
EndOfDynamicDrawBlock::~EndOfDynamicDrawBlock()
{
_blockCount = 0;
release();
}

File diff suppressed because it is too large Load Diff