diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 7b86a8d7e..c5847eb7c 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -785,10 +785,6 @@ SOURCE=..\..\Include\Osg\StateSet # End Source File # Begin Source File -SOURCE=..\..\include\osg\Statistics -# End Source File -# Begin Source File - SOURCE=..\..\Include\Osg\Stencil # End Source File # Begin Source File diff --git a/VisualStudio/osgUtil/osgUtil.dsp b/VisualStudio/osgUtil/osgUtil.dsp index 88885d33f..0753371e9 100755 --- a/VisualStudio/osgUtil/osgUtil.dsp +++ b/VisualStudio/osgUtil/osgUtil.dsp @@ -277,6 +277,10 @@ SOURCE=..\..\include\osgUtil\SmoothingVisitor # End Source File # Begin Source File +SOURCE=..\..\include\osgUtil\Statistics +# End Source File +# Begin Source File + SOURCE=..\..\include\osgUtil\Tesselator # End Source File # Begin Source File diff --git a/include/osgUtil/RenderBin b/include/osgUtil/RenderBin index 1f9fe069b..d953bd078 100644 --- a/include/osgUtil/RenderBin +++ b/include/osgUtil/RenderBin @@ -20,13 +20,10 @@ #include #include -// forward declare Statistics to remove link dependancy. -namespace osg { class Statistics; } - namespace osgUtil { class RenderStage; - +class Statistics; /** * RenderBin base class. */ @@ -110,9 +107,9 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object /** extract stats for current draw list. */ - bool getStats(osg::Statistics* primStats); - void getPrims(osg::Statistics* primStats); - bool getPrims(osg::Statistics* primStats, int nbin); + bool getStats(Statistics* primStats); + void getPrims(Statistics* primStats); + bool getPrims(Statistics* primStats, int nbin); public: diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 7b6f00217..d0d61d788 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -126,7 +126,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin void addToDependencyList(RenderStage* rs); /** extract stats for current draw list. */ - bool getStats(osg::Statistics* primStats); + bool getStats(Statistics* primStats); public: diff --git a/include/osg/Statistics b/include/osgUtil/Statistics similarity index 52% rename from include/osg/Statistics rename to include/osgUtil/Statistics index 396b0c535..2b8598e9e 100644 --- a/include/osg/Statistics +++ b/include/osgUtil/Statistics @@ -19,7 +19,7 @@ #include -namespace osg { +namespace osgUtil { /** * Statistics base class. Used to extract primitive information from @@ -34,11 +34,13 @@ namespace osg { * each trifan or tristrip = (length-2) triangles and so on. */ -class Statistics : public osg::Drawable::PrimitiveFunctor{ +class Statistics : public osg::Drawable::PrimitiveFunctor +{ public: typedef std::pair PrimitivePair; typedef std::map PrimtiveValueMap; + typedef std::map PrimtiveCountMap; Statistics() @@ -71,17 +73,61 @@ class Statistics : public osg::Drawable::PrimitiveFunctor{ void setType(statsType t) {stattype=t;} - virtual void setVertexArray(unsigned int count,const Vec3*) { _vertexCount += count; } + virtual void setVertexArray(unsigned int count,const osg::Vec3*) { _vertexCount += count; } - virtual void drawArrays(GLenum mode,GLint,GLsizei count) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; } - virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; } - virtual void drawElements(GLenum mode,GLsizei count,const GLushort*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; } - virtual void drawElements(GLenum mode,GLsizei count,const GLuint*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; } + virtual void drawArrays(GLenum mode,GLint,GLsizei count) + { + PrimitivePair& prim = _primitiveCount[mode]; + ++prim.first; + prim.second+=count; + _primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count); + } + virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*) + { + PrimitivePair& prim = _primitiveCount[mode]; + ++prim.first; + prim.second+=count; + _primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count); + } + virtual void drawElements(GLenum mode,GLsizei count,const GLushort*) + { + PrimitivePair& prim = _primitiveCount[mode]; + ++prim.first; + prim.second+=count; + _primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count); + } + virtual void drawElements(GLenum mode,GLsizei count,const GLuint*) + { + PrimitivePair& prim = _primitiveCount[mode]; + ++prim.first; + prim.second+=count; + _primitives_count[mode] += _calculate_primitives_number_by_mode(mode, count); + } - virtual void begin(GLenum mode) { _currentPrimtiveFunctorMode=mode; PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; } - virtual void vertex(const Vec3&) { PrimitivePair& prim = _primitiveCount[_currentPrimtiveFunctorMode]; ++prim.second; } - virtual void vertex(float,float,float) { PrimitivePair& prim = _primitiveCount[_currentPrimtiveFunctorMode]; ++prim.second; } - virtual void end() {} + virtual void begin(GLenum mode) + { + _currentPrimtiveFunctorMode=mode; + PrimitivePair& prim = _primitiveCount[mode]; + ++prim.first; + _number_of_vertexes = 0; + } + virtual void vertex(const osg::Vec3&) + { + PrimitivePair& prim = _primitiveCount[_currentPrimtiveFunctorMode]; + ++prim.second; + _number_of_vertexes++; + } + virtual void vertex(float,float,float) + { + PrimitivePair& prim = _primitiveCount[_currentPrimtiveFunctorMode]; + ++prim.second; + _number_of_vertexes++; + } + virtual void end() + { + _primitives_count[_currentPrimtiveFunctorMode] += + _calculate_primitives_number_by_mode(_currentPrimtiveFunctorMode, _number_of_vertexes); + } void addDrawable() { numDrawables++;} void addMatrix() { nummat++;} @@ -95,6 +141,9 @@ class Statistics : public osg::Drawable::PrimitiveFunctor{ public: + PrimtiveCountMap::iterator GetPrimitivesBegin() { return _primitives_count.begin(); } + PrimtiveCountMap::iterator GetPrimitivesEnd() { return _primitives_count.end(); } + int numDrawables, nummat, nbins; int nlights; int depth; // depth into bins - eg 1.1,1.2,1.3 etc @@ -105,10 +154,34 @@ class Statistics : public osg::Drawable::PrimitiveFunctor{ unsigned int _vertexCount; PrimtiveValueMap _primitiveCount; GLenum _currentPrimtiveFunctorMode; - + private: + PrimtiveCountMap _primitives_count; + + unsigned int _total_primitives_count; + unsigned int _number_of_vertexes; + + unsigned int _calculate_primitives_number_by_mode(GLenum, GLsizei); }; +inline unsigned int Statistics::_calculate_primitives_number_by_mode(GLenum mode, GLsizei count) +{ + switch (mode) + { + case GL_POINTS: + case GL_LINE_LOOP: + case GL_POLYGON: return count; + case GL_LINES: return count / 2; + case GL_LINE_STRIP: return count - 1; + case GL_TRIANGLES: return count / 3; + case GL_TRIANGLE_STRIP: + case GL_TRIANGLE_FAN: return count - 2; + case GL_QUADS: return count / 4; + case GL_QUAD_STRIP: return count - 3; + default: return 0; + } +} + } #endif diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index f9fe18300..7aa25a561 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -12,8 +12,8 @@ */ #include #include +#include -#include #include #include @@ -334,7 +334,7 @@ void RenderBin::drawImplementation(osg::State& state,RenderLeaf*& previous) } // stats -bool RenderBin::getStats(osg::Statistics* primStats) +bool RenderBin::getStats(Statistics* primStats) { // different by return type - collects the stats in this renderrBin bool somestats=false; @@ -382,7 +382,7 @@ bool RenderBin::getStats(osg::Statistics* primStats) return somestats; } -void RenderBin::getPrims(osg::Statistics* primStats) +void RenderBin::getPrims(Statistics* primStats) { static int ndepth; ndepth++; @@ -398,7 +398,7 @@ void RenderBin::getPrims(osg::Statistics* primStats) } -bool RenderBin::getPrims(osg::Statistics* primStats, int nbin) +bool RenderBin::getPrims(Statistics* primStats, int nbin) { // collect stats for array of bins, maximum nbin // (which will be modified on next call if array of primStats is too small); // return 1 for OK; diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index c679b1ed6..e07d6614c 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -12,7 +12,7 @@ */ #include #include -#include +#include #include