Fixed multi-threaded/multi-pipe crash when primitive stats where output in osgProducer::Viewer's stats.

This commit is contained in:
Robert Osfield
2006-07-29 16:47:28 +00:00
parent f977d7c606
commit b1994cc60d
7 changed files with 90 additions and 92 deletions

View File

@@ -16,6 +16,7 @@
#include <osg/Timer>
#include <osgUtil/SceneView>
#include <osgUtil/Statistics>
#include <Producer/Camera>
@@ -104,6 +105,11 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
Callback* getDrawCallback() { return _drawCallback.get(); }
const Callback* getDrawCallback() const { return _drawCallback.get(); }
void setCollectStats(bool collectStats) { _collectStats = collectStats; }
bool getCollectStats() const { return _collectStats; }
bool getStats(osgUtil::Statistics& primStats);
void setContextID( int id );
void setFlushOfAllDeletedGLObjectsOnNextFrame(bool flag) { _flushOfAllDeletedGLObjectsOnNextFrame = flag; }
@@ -119,17 +125,22 @@ class OSGPRODUCER_EXPORT OsgSceneHandler : public Producer::Camera::SceneHandler
virtual ~OsgSceneHandler() {}
OpenThreads::Mutex _cullMutex;
osg::ref_ptr<osgUtil::SceneView> _sceneView;
osg::ref_ptr<Callback> _clearCallback;
osg::ref_ptr<Callback> _cullCallback;
osg::ref_ptr<Callback> _drawCallback;
osg::ref_ptr<Callback> _clearCallback;
osg::ref_ptr<Callback> _cullCallback;
osg::ref_ptr<Callback> _drawCallback;
osg::Timer_t _frameStartTick;
osg::Timer_t _previousFrameStartTick;
osg::Timer_t _frameStartTick;
osg::Timer_t _previousFrameStartTick;
bool _flushOfAllDeletedGLObjectsOnNextFrame;
bool _cleanUpOnNextFrame;
bool _flushOfAllDeletedGLObjectsOnNextFrame;
bool _cleanUpOnNextFrame;
bool _collectStats;
osgUtil::Statistics _stats;
};
}

View File

@@ -72,9 +72,6 @@ class OSGPRODUCER_EXPORT ViewerEventHandler : public osgGA::GUIEventHandler
bool _firstTimeTogglingFullScreen;
class CameraBarrierCallback;
CameraBarrierCallback* _cameraBarrierCallback;
class StatsAndHelpDrawCallback;
StatsAndHelpDrawCallback* _statsAndHelpDrawCallback;

View File

@@ -56,7 +56,7 @@ class Statistics : public osg::PrimitiveFunctor
reset();
};
enum statsType
enum StatsType
{
STAT_NONE, // default
STAT_FRAMERATE,
@@ -88,7 +88,7 @@ class Statistics : public osg::PrimitiveFunctor
_number_of_vertexes=0;
}
void setType(statsType t) {stattype=t;}
void setType(StatsType t) {stattype=t;}
virtual void setVertexArray(unsigned int count,const osg::Vec3*) { _vertexCount += count; }
virtual void setVertexArray(unsigned int count,const osg::Vec2*) { _vertexCount += count; }
@@ -160,7 +160,39 @@ class Statistics : public osg::PrimitiveFunctor
void setDepth(int d) { depth=d; }
void addBins(int np) { nbins+= np; }
void setBinNo(int n) { _binNo=n;}
void setBinNo(int n) { _binNo=n;}
void add(const Statistics& stats)
{
numDrawables += stats.numDrawables;
nummat += stats.nummat;
depth += stats.depth;
nlights += stats.nlights;
nbins += stats.nbins;
nimpostor += stats.nimpostor;
_vertexCount += stats._vertexCount;
// _primitiveCount += stats._primitiveCount;
for(PrimitiveValueMap::const_iterator pitr = stats._primitiveCount.begin();
pitr != stats._primitiveCount.end();
++pitr)
{
_primitiveCount[pitr->first].first += pitr->second.first;
_primitiveCount[pitr->first].second += pitr->second.second;
}
_currentPrimitiveFunctorMode += stats._currentPrimitiveFunctorMode;
for(PrimitiveCountMap::const_iterator citr = stats._primitives_count.begin();
citr != stats._primitives_count.end();
++citr)
{
_primitives_count[citr->first] += citr->second;
}
_total_primitives_count += stats._total_primitives_count;
_number_of_vertexes += stats._number_of_vertexes;
}
public:
@@ -171,7 +203,7 @@ class Statistics : public osg::PrimitiveFunctor
int nlights;
int depth; // depth into bins - eg 1.1,1.2,1.3 etc
int _binNo;
statsType stattype;
StatsType stattype;
int nimpostor; // number of impostors rendered
unsigned int _vertexCount;