Statistics
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_STATISTICS
#define OSGUTIL_STATISTICS 1
#include <osgUtil/Export>
#include <osg/PrimitiveSet>
#include <osg/Drawable>
#include <osg/NodeVisitor>
#include <osg/Geode>
#include <osg/LOD>
#include <osg/Switch>
#include <osg/Geometry>
#include <osg/Transform>
#include <map>
#include <set>
#include <ostream>
namespace osgUtil {
class OSGUTIL_EXPORT Statistics : public osg::PrimitiveFunctor
{
public:
typedef std::pair<unsigned int,unsigned int> PrimitivePair;
typedef std::map<GLenum,PrimitivePair> PrimitiveValueMap;
typedef std::map<GLenum, unsigned int> PrimitiveCountMap;
Statistics();
enum StatsType
{
STAT_NONE, // default
STAT_FRAMERATE,
STAT_GRAPHS,
STAT_PRIMS,
STAT_PRIMSPERVIEW,
STAT_PRIMSPERBIN,
STAT_DC,
STAT_RESTART // hint to restart the stats
};
void reset();
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; }
virtual void setVertexArray(unsigned int count,const osg::Vec4*) { _vertexCount += count; }
virtual void setVertexArray(unsigned int count,const osg::Vec3d*) { _vertexCount += count; }
virtual void setVertexArray(unsigned int count,const osg::Vec2d*) { _vertexCount += count; }
virtual void setVertexArray(unsigned int count,const osg::Vec4d*) { _vertexCount += count; }
virtual void drawArrays(GLenum mode,GLint,GLsizei count);
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*);
virtual void drawElements(GLenum mode,GLsizei count,const GLushort*);
virtual void drawElements(GLenum mode,GLsizei count,const GLuint*);
virtual void begin(GLenum mode);
inline void vertex()
{
PrimitivePair& prim = _primitiveCount[_currentPrimitiveFunctorMode];
++prim.second;
_number_of_vertexes++;
}
virtual void vertex(float,float,float) { vertex(); }
virtual void vertex(const osg::Vec3&) { vertex(); }
virtual void vertex(const osg::Vec2&) { vertex(); }
virtual void vertex(const osg::Vec4&) { vertex(); }
virtual void vertex(float,float) { vertex(); }
virtual void vertex(float,float,float,float) { vertex(); }
virtual void end();
void addDrawable() { numDrawables++;}
void addFastDrawable() { numFastDrawables++;}
void addMatrix() { nummat++;}
void addLight(int np) { nlights+=np;}
void addImpostor(int np) { nimpostor+= np; }
inline int getBins() { return nbins;}
void setDepth(int d) { depth=d; }
void addBins(int np) { nbins+= np; }
void setBinNo(int n) { _binNo=n;}
void addStateGraphs(int n) { numStateGraphs += n; }
void addOrderedLeaves(int n) { numOrderedLeaves += n; }
void add(const Statistics& stats);
public:
PrimitiveCountMap& getPrimitiveCountMap() { return _primitives_count; }
const PrimitiveCountMap& getPrimitiveCountMap() const { return _primitives_count; }
PrimitiveValueMap& getPrimitiveValueMap() { return _primitiveCount; }
const PrimitiveValueMap& getPrimitiveValueMap() const { return _primitiveCount; }
PrimitiveCountMap::iterator GetPrimitivesBegin() { return _primitives_count.begin(); }
PrimitiveCountMap::iterator GetPrimitivesEnd() { return _primitives_count.end(); }
int numDrawables, nummat, nbins, numStateGraphs;
int numFastDrawables;
int nlights;
int depth; // depth into bins - eg 1.1,1.2,1.3 etc
int _binNo;
StatsType stattype;
int nimpostor; // number of impostors rendered
int numOrderedLeaves; // leaves from RenderBin fine grain ordering
unsigned int _vertexCount;
PrimitiveValueMap _primitiveCount;
GLenum _currentPrimitiveFunctorMode;
private:
PrimitiveCountMap _primitives_count;
unsigned int _total_primitives_count;
unsigned int _number_of_vertexes;
inline 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 / 2 - 1;
default: return 0;
}
}
class OSGUTIL_EXPORT StatsVisitor : public osg::NodeVisitor
{
public:
typedef std::set<osg::Node*> NodeSet;
typedef std::set<osg::Drawable*> DrawableSet;
typedef std::set<osg::StateSet*> StateSetSet;
StatsVisitor();
META_NodeVisitor(osgUtil, StatsVisitor)
virtual void reset();
virtual void apply(osg::Node& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::Transform& node);
virtual void apply(osg::LOD& node);
virtual void apply(osg::Switch& node);
virtual void apply(osg::Geode& node);
virtual void apply(osg::Drawable& drawable);
virtual void apply(osg::StateSet& ss);
virtual void totalUpStats();
virtual void print(std::ostream& out);
unsigned int _numInstancedGroup;
unsigned int _numInstancedSwitch;
unsigned int _numInstancedLOD;
unsigned int _numInstancedTransform;
unsigned int _numInstancedGeode;
unsigned int _numInstancedDrawable;
unsigned int _numInstancedGeometry;
unsigned int _numInstancedFastGeometry;
unsigned int _numInstancedStateSet;
NodeSet _groupSet;
NodeSet _transformSet;
NodeSet _lodSet;
NodeSet _switchSet;
NodeSet _geodeSet;
DrawableSet _drawableSet;
DrawableSet _geometrySet;
DrawableSet _fastGeometrySet;
StateSetSet _statesetSet;
osgUtil::Statistics _uniqueStats;
osgUtil::Statistics _instancedStats;
};
}
#endif
Drawable
Geode
Geometry
LOD
NodeVisitor
PrimitiveSet
Switch
Transform
osgUtil::Statistics
Definition Statistics:48
osgUtil::Statistics::getBins
int getBins()
Definition Statistics:109
osgUtil::Statistics::addStateGraphs
void addStateGraphs(int n)
Definition Statistics:114
osgUtil::Statistics::vertex
virtual void vertex(float, float, float, float)
Definition Statistics:100
osgUtil::Statistics::addLight
void addLight(int np)
Definition Statistics:107
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec4d *)
Definition Statistics:79
osgUtil::Statistics::_binNo
int _binNo
Definition Statistics:137
osgUtil::Statistics::setDepth
void setDepth(int d)
Definition Statistics:110
osgUtil::Statistics::drawElements
virtual void drawElements(GLenum mode, GLsizei count, const GLubyte *)
Mimics the OpenGL glDrawElements() function.
osgUtil::Statistics::begin
virtual void begin(GLenum mode)
osgUtil::Statistics::_currentPrimitiveFunctorMode
GLenum _currentPrimitiveFunctorMode
Definition Statistics:144
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec4 *)
Definition Statistics:76
osgUtil::Statistics::addOrderedLeaves
void addOrderedLeaves(int n)
Definition Statistics:115
osgUtil::Statistics::PrimitiveCountMap
std::map< GLenum, unsigned int > PrimitiveCountMap
Definition Statistics:53
osgUtil::Statistics::_primitiveCount
PrimitiveValueMap _primitiveCount
Definition Statistics:143
osgUtil::Statistics::drawArrays
virtual void drawArrays(GLenum mode, GLint, GLsizei count)
Mimics the OpenGL glDrawArrays() function.
osgUtil::Statistics::vertex
virtual void vertex(const osg::Vec3 &)
Definition Statistics:96
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec3 *)
Definition Statistics:74
osgUtil::Statistics::GetPrimitivesBegin
PrimitiveCountMap::iterator GetPrimitivesBegin()
deprecated
Definition Statistics:129
osgUtil::Statistics::numFastDrawables
int numFastDrawables
Definition Statistics:134
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec3d *)
Definition Statistics:77
osgUtil::Statistics::_vertexCount
unsigned int _vertexCount
Definition Statistics:142
osgUtil::Statistics::stattype
StatsType stattype
Definition Statistics:138
osgUtil::Statistics::PrimitiveValueMap
std::map< GLenum, PrimitivePair > PrimitiveValueMap
Definition Statistics:52
osgUtil::Statistics::nlights
int nlights
Definition Statistics:135
osgUtil::Statistics::getPrimitiveCountMap
const PrimitiveCountMap & getPrimitiveCountMap() const
Definition Statistics:122
osgUtil::Statistics::nimpostor
int nimpostor
Definition Statistics:139
osgUtil::Statistics::vertex
virtual void vertex(const osg::Vec4 &)
Definition Statistics:98
osgUtil::Statistics::addDrawable
void addDrawable()
Definition Statistics:104
osgUtil::Statistics::vertex
void vertex()
Definition Statistics:88
osgUtil::Statistics::addFastDrawable
void addFastDrawable()
Definition Statistics:105
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec2 *)
Definition Statistics:75
osgUtil::Statistics::numDrawables
int numDrawables
Definition Statistics:133
osgUtil::Statistics::depth
int depth
Definition Statistics:136
osgUtil::Statistics::addMatrix
void addMatrix()
Definition Statistics:106
osgUtil::Statistics::setBinNo
void setBinNo(int n)
Definition Statistics:113
osgUtil::Statistics::vertex
virtual void vertex(float, float)
Definition Statistics:99
osgUtil::Statistics::getPrimitiveValueMap
PrimitiveValueMap & getPrimitiveValueMap()
Definition Statistics:124
osgUtil::Statistics::drawElements
virtual void drawElements(GLenum mode, GLsizei count, const GLushort *)
Mimics the OpenGL glDrawElements() function.
osgUtil::Statistics::end
virtual void end()
osgUtil::Statistics::vertex
virtual void vertex(float, float, float)
Definition Statistics:95
osgUtil::Statistics::add
void add(const Statistics &stats)
osgUtil::Statistics::getPrimitiveValueMap
const PrimitiveValueMap & getPrimitiveValueMap() const
Definition Statistics:125
osgUtil::Statistics::nummat
int nummat
Definition Statistics:133
osgUtil::Statistics::GetPrimitivesEnd
PrimitiveCountMap::iterator GetPrimitivesEnd()
deprecated
Definition Statistics:131
osgUtil::Statistics::setType
void setType(StatsType t)
Definition Statistics:72
osgUtil::Statistics::numOrderedLeaves
int numOrderedLeaves
Definition Statistics:140
osgUtil::Statistics::getPrimitiveCountMap
PrimitiveCountMap & getPrimitiveCountMap()
Definition Statistics:121
osgUtil::Statistics::drawElements
virtual void drawElements(GLenum mode, GLsizei count, const GLuint *)
Mimics the OpenGL glDrawElements() function.
osgUtil::Statistics::Statistics
Statistics()
osgUtil::Statistics::setVertexArray
virtual void setVertexArray(unsigned int count, const osg::Vec2d *)
Definition Statistics:78
osgUtil::Statistics::reset
void reset()
osgUtil::Statistics::numStateGraphs
int numStateGraphs
Definition Statistics:133
osgUtil::Statistics::nbins
int nbins
Definition Statistics:133
osgUtil::Statistics::addBins
void addBins(int np)
Definition Statistics:111
osgUtil::Statistics::StatsType
StatsType
Definition Statistics:59
osgUtil::Statistics::STAT_PRIMS
@ STAT_PRIMS
Definition Statistics:63
osgUtil::Statistics::STAT_GRAPHS
@ STAT_GRAPHS
Definition Statistics:62
osgUtil::Statistics::STAT_NONE
@ STAT_NONE
Definition Statistics:60
osgUtil::Statistics::STAT_DC
@ STAT_DC
Definition Statistics:66
osgUtil::Statistics::STAT_PRIMSPERVIEW
@ STAT_PRIMSPERVIEW
Definition Statistics:64
osgUtil::Statistics::STAT_FRAMERATE
@ STAT_FRAMERATE
Definition Statistics:61
osgUtil::Statistics::STAT_PRIMSPERBIN
@ STAT_PRIMSPERBIN
Definition Statistics:65
osgUtil::Statistics::STAT_RESTART
@ STAT_RESTART
Definition Statistics:67
osgUtil::Statistics::PrimitivePair
std::pair< unsigned int, unsigned int > PrimitivePair
Definition Statistics:51
osgUtil::Statistics::vertex
virtual void vertex(const osg::Vec2 &)
Definition Statistics:97
osgUtil::Statistics::addImpostor
void addImpostor(int np)
Definition Statistics:108
osgUtil::StatsVisitor::apply
virtual void apply(osg::Group &node)
osgUtil::StatsVisitor::META_NodeVisitor
META_NodeVisitor(osgUtil, StatsVisitor) virtual void reset()
osgUtil::StatsVisitor::NodeSet
std::set< osg::Node * > NodeSet
Definition Statistics:178
osgUtil::StatsVisitor::StateSetSet
std::set< osg::StateSet * > StateSetSet
Definition Statistics:180
osgUtil::StatsVisitor::_numInstancedDrawable
unsigned int _numInstancedDrawable
Definition Statistics:206
osgUtil::StatsVisitor::apply
virtual void apply(osg::Switch &node)
osgUtil::StatsVisitor::_statesetSet
StateSetSet _statesetSet
Definition Statistics:219
osgUtil::StatsVisitor::_numInstancedLOD
unsigned int _numInstancedLOD
Definition Statistics:203
osgUtil::StatsVisitor::apply
virtual void apply(osg::Transform &node)
osgUtil::StatsVisitor::_lodSet
NodeSet _lodSet
Definition Statistics:213
osgUtil::StatsVisitor::_switchSet
NodeSet _switchSet
Definition Statistics:214
osgUtil::StatsVisitor::_geometrySet
DrawableSet _geometrySet
Definition Statistics:217
osgUtil::StatsVisitor::_instancedStats
osgUtil::Statistics _instancedStats
Definition Statistics:222
osgUtil::StatsVisitor::apply
virtual void apply(osg::StateSet &ss)
osgUtil::StatsVisitor::_transformSet
NodeSet _transformSet
Definition Statistics:212
osgUtil::StatsVisitor::DrawableSet
std::set< osg::Drawable * > DrawableSet
Definition Statistics:179
osgUtil::StatsVisitor::_numInstancedSwitch
unsigned int _numInstancedSwitch
Definition Statistics:202
osgUtil::StatsVisitor::_numInstancedStateSet
unsigned int _numInstancedStateSet
Definition Statistics:209
osgUtil::StatsVisitor::_numInstancedFastGeometry
unsigned int _numInstancedFastGeometry
Definition Statistics:208
osgUtil::StatsVisitor::_numInstancedTransform
unsigned int _numInstancedTransform
Definition Statistics:204
osgUtil::StatsVisitor::print
virtual void print(std::ostream &out)
osgUtil::StatsVisitor::apply
virtual void apply(osg::LOD &node)
osgUtil::StatsVisitor::_fastGeometrySet
DrawableSet _fastGeometrySet
Definition Statistics:218
osgUtil::StatsVisitor::_numInstancedGeometry
unsigned int _numInstancedGeometry
Definition Statistics:207
osgUtil::StatsVisitor::_uniqueStats
osgUtil::Statistics _uniqueStats
Definition Statistics:221
osgUtil::StatsVisitor::apply
virtual void apply(osg::Geode &node)
osgUtil::StatsVisitor::_groupSet
NodeSet _groupSet
Definition Statistics:211
osgUtil::StatsVisitor::totalUpStats
virtual void totalUpStats()
osgUtil::StatsVisitor::_numInstancedGeode
unsigned int _numInstancedGeode
Definition Statistics:205
osgUtil::StatsVisitor::StatsVisitor
StatsVisitor()
osgUtil::StatsVisitor::_drawableSet
DrawableSet _drawableSet
Definition Statistics:216
osgUtil::StatsVisitor::_numInstancedGroup
unsigned int _numInstancedGroup
Definition Statistics:201
osgUtil::StatsVisitor::_geodeSet
NodeSet _geodeSet
Definition Statistics:215
osgUtil::StatsVisitor::apply
virtual void apply(osg::Node &node)
osgUtil::StatsVisitor::apply
virtual void apply(osg::Drawable &drawable)
osg::Drawable
Definition Drawable:89
osg::Geode
Definition Geode:29
osg::Group
Definition Group:29
osg::LOD
Definition LOD:36
osg::NodeVisitor
Definition NodeVisitor:82
osg::NodeVisitor::reset
virtual void reset()
Definition NodeVisitor:167
osg::Node
Definition Node:72
osg::PrimitiveFunctor
Definition PrimitiveSet:54
osg::StateSet
Definition StateSet:46
osg::Switch
Definition Switch:27
osg::Transform
Definition Transform:75
osg::Vec2d
Definition Vec2d:29
osg::Vec3d
Definition Vec3d:30
osg::Vec4d
Definition Vec4d:29
osgUtil
Definition NodeVisitor:25
osg::Vec2
Vec2f Vec2
Definition Vec2:21
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::Vec4
Vec4f Vec4
Definition Vec4:21
Export
OSGUTIL_EXPORT
#define OSGUTIL_EXPORT
Definition osgUtil/Export:40