2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2001-10-04 23:12:57 +08:00
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-10-23 06:02:47 +08:00
|
|
|
#ifndef OSGUTIL_STATISTICS
|
|
|
|
#define OSGUTIL_STATISTICS 1
|
2001-09-20 05:19:47 +08:00
|
|
|
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
#include <osg/Referenced>
|
2002-02-06 05:54:46 +08:00
|
|
|
#include <osg/Drawable>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2002-07-18 22:20:01 +08:00
|
|
|
#include <map>
|
|
|
|
|
2001-10-07 04:29:42 +08:00
|
|
|
namespace osg {
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Statistics base class. Used to extract primitive information from
|
2001-10-23 06:02:47 +08:00
|
|
|
* the renderBin(s). Add a case of getStats(osgUtil::Statistics *stat)
|
|
|
|
* for any new drawable (or drawable derived class) that you generate
|
2002-06-26 04:27:51 +08:00
|
|
|
* (eg see Geometry.cpp). There are 20 types of drawable counted - actually only
|
2001-10-23 06:02:47 +08:00
|
|
|
* 14 cases can occur in reality. these represent sets of GL_POINTS, GL_LINES
|
|
|
|
* GL_LINESTRIPS, LOOPS, TRIANGLES, TRI-fans, tristrips, quads, quadstrips etc
|
|
|
|
* The number of triangles rendered is inferred:
|
|
|
|
* each triangle = 1 triangle (number of vertices/3)
|
|
|
|
* each quad = 2 triangles (nverts/2)
|
|
|
|
* each trifan or tristrip = (length-2) triangles and so on.
|
2001-09-20 05:19:47 +08:00
|
|
|
*/
|
2001-10-23 06:02:47 +08:00
|
|
|
|
2002-07-18 22:20:01 +08:00
|
|
|
class Statistics : public osg::Referenced, public osg::Drawable::PrimitiveFunctor{
|
2001-09-20 05:19:47 +08:00
|
|
|
public:
|
2002-07-18 22:20:01 +08:00
|
|
|
|
|
|
|
typedef std::pair<unsigned int,unsigned int> PrimitivePair;
|
|
|
|
typedef std::map<GLenum,PrimitivePair> PrimtiveValueMap;
|
|
|
|
|
|
|
|
|
|
|
|
Statistics()
|
2001-11-05 03:29:20 +08:00
|
|
|
{
|
2001-09-20 05:19:47 +08:00
|
|
|
reset();
|
|
|
|
};
|
2001-10-23 06:02:47 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
~Statistics() {}; // no dynamic allocations, so no need to free
|
2001-11-05 03:29:20 +08:00
|
|
|
|
|
|
|
enum statsType
|
|
|
|
{
|
2001-10-23 06:02:47 +08:00
|
|
|
STAT_NONE, // default
|
2002-07-18 22:20:01 +08:00
|
|
|
STAT_FRAMERATE,
|
|
|
|
STAT_GRAPHS,
|
|
|
|
STAT_PRIMS,
|
|
|
|
STAT_PRIMSPERVIEW,
|
|
|
|
STAT_PRIMSPERBIN,
|
2001-10-23 06:02:47 +08:00
|
|
|
STAT_DC,
|
|
|
|
STAT_RESTART // hint to restart the stats
|
|
|
|
};
|
2002-07-18 22:20:01 +08:00
|
|
|
|
2001-11-05 03:29:20 +08:00
|
|
|
void reset()
|
|
|
|
{
|
2002-08-31 03:45:56 +08:00
|
|
|
numDrawables=0, nummat=0; depth=0; stattype=STAT_NONE;
|
2002-07-18 22:20:01 +08:00
|
|
|
nlights=0; nbins=0; nimpostor=0;
|
|
|
|
|
|
|
|
_vertexCount=0;
|
|
|
|
_primitiveCount.clear();
|
|
|
|
|
|
|
|
_currentPrimtiveFunctorMode=0;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2001-11-05 03:29:20 +08:00
|
|
|
void setType(statsType t) {stattype=t;}
|
2002-07-18 22:20:01 +08:00
|
|
|
|
|
|
|
virtual void setVertexArray(unsigned int count,Vec3*) { _vertexCount += count; }
|
2001-11-05 03:29:20 +08:00
|
|
|
|
2002-07-18 22:20:01 +08:00
|
|
|
virtual void drawArrays(GLenum mode,GLint,GLsizei count) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
|
|
|
|
virtual void drawElements(GLenum mode,GLsizei count,GLubyte*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
|
|
|
|
virtual void drawElements(GLenum mode,GLsizei count,GLushort*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
|
|
|
|
virtual void drawElements(GLenum mode,GLsizei count,GLuint*) { PrimitivePair& prim = _primitiveCount[mode]; ++prim.first; prim.second+=count; }
|
2002-02-06 05:54:46 +08:00
|
|
|
|
2002-07-18 22:20:01 +08:00
|
|
|
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() {}
|
2001-11-05 03:29:20 +08:00
|
|
|
|
2002-08-31 03:45:56 +08:00
|
|
|
void addDrawable() { numDrawables++;}
|
2001-11-05 03:29:20 +08:00
|
|
|
void addMatrix() { nummat++;}
|
|
|
|
void addLight(const int np) { nlights+=np;}
|
|
|
|
void addImpostor(const int np) { nimpostor+= np; }
|
|
|
|
inline const int getBins() { return nbins;}
|
|
|
|
void setDepth(const int d) { depth=d; }
|
|
|
|
void addBins(const int np) { nbins+= np; }
|
|
|
|
|
|
|
|
void setBinNo(const int n) { _binNo=n;}
|
|
|
|
|
2001-10-23 06:02:47 +08:00
|
|
|
public:
|
|
|
|
|
2002-08-31 03:45:56 +08:00
|
|
|
int numDrawables, nummat, nbins;
|
2002-07-18 22:20:01 +08:00
|
|
|
int nlights;
|
2001-11-05 03:29:20 +08:00
|
|
|
int depth; // depth into bins - eg 1.1,1.2,1.3 etc
|
|
|
|
int _binNo;
|
|
|
|
statsType stattype;
|
2001-10-23 06:02:47 +08:00
|
|
|
int nimpostor; // number of impostors rendered
|
2002-07-18 22:20:01 +08:00
|
|
|
|
|
|
|
unsigned int _vertexCount;
|
|
|
|
PrimtiveValueMap _primitiveCount;
|
|
|
|
GLenum _currentPrimtiveFunctorMode;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
#endif
|