Rewrote osg:Statistics so that it is PrimitiveFunctor as is now completely

decoupled from osg::Drawable.  The Drawable::getStats() virtual method
no longer exists.

Updated the Viewer to use the osg::Statistics incarnation and reformated stats
to clean it up.
This commit is contained in:
Robert Osfield
2002-07-18 14:20:01 +00:00
parent f2b6f8c873
commit 8036901ea1
14 changed files with 109 additions and 320 deletions

View File

@@ -17,7 +17,6 @@
namespace osg {
class Statistics;
class Vec2;
class Vec3;
class Vec4;
@@ -36,19 +35,6 @@ class Node;
for a Drawable are maintained in StateSet which the Drawable maintains
a referenced counted pointer to. Both Drawable's and StateSet's can
be shared for optimal memory usage and graphics performance.
Subclasses should provide an instance of getStats(Statistics *st) if the subclass
contains drawing primitives. This member function should add the primitives it
draws into the Statistics class; for example add the number of quads, triangles etc
created. For an example see Geometry.cpp:
getStats(osgUtil::Statistics *stat).
Failure to implement this routine will only result in the stats displayed for
your drawable being wrong.
Another example is in the InfinitePlane class- this draws a normal geoset AND
its own special set of quads, so this case of getPrims calls:
the normal geoset stats gs->getStats(..), and then adds the number of quads
rendered directly (it is rendered in a display list, but we do know how many
quads are in the display list).
*/
class SG_EXPORT Drawable : public Object
{
@@ -231,11 +217,6 @@ class SG_EXPORT Drawable : public Object
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(uint contextID);
/** Collect Stistics count from Drawable.*/
virtual bool getStats(Statistics&) { return false; }
typedef uint AttributeBitMask;

View File

@@ -328,12 +328,6 @@ class SG_EXPORT GeoSet : public Drawable
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
/** Statistics collection for each drawable- 26.09.01
*/
bool getStats(Statistics &);
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
virtual AttributeBitMask suppportsAttributeOperation() const;

View File

@@ -91,10 +91,6 @@ class SG_EXPORT Geometry : public Drawable
*/
virtual void drawImmediateMode(State& state);
/** Statistics collection for each drawable- 26.09.01
*/
bool getStats(Statistics &);
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
virtual AttributeBitMask suppportsAttributeOperation() const;

View File

@@ -113,11 +113,8 @@ class SG_EXPORT ImpostorSprite : public Drawable
const int s() const { return _s; }
const int t() const { return _t; }
/** draw ImpostorSprite directly. */
virtual void drawImmediateMode(State& state);
bool getStats(Statistics &stat);
protected:

View File

@@ -8,6 +8,8 @@
#include <osg/Referenced>
#include <osg/Drawable>
#include <map>
namespace osg {
/**
@@ -23,84 +25,60 @@ namespace osg {
* each trifan or tristrip = (length-2) triangles and so on.
*/
class Statistics : public osg::Referenced, public osg::Drawable::AttributeFunctor
{
class Statistics : public osg::Referenced, public osg::Drawable::PrimitiveFunctor{
public:
Statistics():
osg::Drawable::AttributeFunctor(osg::Drawable::COORDS)
typedef std::pair<unsigned int,unsigned int> PrimitivePair;
typedef std::map<GLenum,PrimitivePair> PrimtiveValueMap;
Statistics()
{
reset();
};
enum PrimitiveType
{
NO_TYPE,
POINTS,
LINES,
LINE_STRIP,
FLAT_LINE_STRIP,
LINE_LOOP,
TRIANGLES,
TRIANGLE_STRIP,
FLAT_TRIANGLE_STRIP,
TRIANGLE_FAN,
FLAT_TRIANGLE_FAN,
QUADS,
QUAD_STRIP,
POLYGON,
IMPOSTOR
};
~Statistics() {}; // no dynamic allocations, so no need to free
enum statsType
{
STAT_NONE, // default
STAT_FRAMERATE, STAT_GRAPHS,
STAT_VIEWPARMS, // descrbe the view parameters (FOV, near/far...)
STAT_PRIMS, STAT_PRIMSPERVIEW, STAT_PRIMSPERBIN,
STAT_FRAMERATE,
STAT_GRAPHS,
STAT_PRIMS,
STAT_PRIMSPERVIEW,
STAT_PRIMSPERBIN,
STAT_DC,
STAT_RESTART // hint to restart the stats
};
void reset()
{
numOpaque=0, nummat=0; depth=0; stattype=STAT_NONE;
nprims=0, nlights=0; nbins=0; nimpostor=0;
for (int i=0; i<=POLYGON; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0;
nlights=0; nbins=0; nimpostor=0;
_vertexCount=0;
_primitiveCount.clear();
_currentPrimtiveFunctorMode=0;
}
void setType(statsType t) {stattype=t;}
virtual void setVertexArray(unsigned int count,Vec3*) { _vertexCount += count; }
virtual bool apply(osg::Drawable::AttributeBitMask abm,osg::Vec3* begin,osg::Vec3* end)
{
if (abm == osg::Drawable::COORDS)
{
primverts[0] += (end-begin);
return true;
}
return false;
}
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; }
void addNumPrims(const int typ, const int nprimlen, const int numprimtype, const int primvert)
{
if (typ>NO_TYPE && typ<=POLYGON) {
primtypes[0]++;
primtypes[typ]++;
numprimtypes[0]+=numprimtype;
numprimtypes[typ]+=numprimtype;
primlens[0]+=nprimlen;
primlens[typ]+=nprimlen;
//primverts[0]+=primvert;
primverts[typ]+=primvert;
}
}
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() {}
void addOpaque() { numOpaque++;}
void addMatrix() { nummat++;}
void addLight(const int np) { nlights+=np;}
void addNumPrims(const int np) { nprims += np; }
void addImpostor(const int np) { nimpostor+= np; }
inline const int getBins() { return nbins;}
void setDepth(const int d) { depth=d; }
@@ -111,15 +89,15 @@ class Statistics : public osg::Referenced, public osg::Drawable::AttributeFuncto
public:
int numOpaque, nummat, nbins;
int nprims, nlights;
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 numprimtypes[16]; // histogram of number of each type of prim
int primtypes[16]; // histogram of number of each type of prim
int primlens[16]; // histogram of lengths of each type of prim
int primverts[16]; // histogram of number of vertices to be transformed
unsigned int _vertexCount;
PrimtiveValueMap _primitiveCount;
GLenum _currentPrimtiveFunctorMode;
};

View File

@@ -19,7 +19,6 @@
#include <osg/CopyOp>
#include <osg/State>
#include <osg/Vec3>
#include <osg/Statistics>
#include <osg/BoundingBox>
namespace osgParticle
@@ -117,9 +116,8 @@ namespace osgParticle
/// Update the particles. Don't call this directly, use a <CODE>ParticleSystemUpdater</CODE> instead.
virtual void update(double dt);
inline virtual bool getStats(osg::Statistics &stats);
protected:
virtual ~ParticleSystem();
ParticleSystem &operator=(const ParticleSystem &) { return *this; }
@@ -231,12 +229,6 @@ namespace osgParticle
return true;
}
inline bool ParticleSystem::getStats(osg::Statistics &stats)
{
stats.addNumPrims(draw_count_);
return true;
}
inline void ParticleSystem::update_bounds(const osg::Vec3 &p, float r)
{
if (reset_bounds_flag_) {

View File

@@ -6,12 +6,14 @@
#define OSGUTIL_RENDERBIN 1
#include <osgUtil/RenderGraph>
#include <osg/Statistics>
#include <map>
#include <vector>
#include <string>
// forward declare Statistics to remove link dependancy.
namespace osg { class Statistics; }
namespace osgUtil {
class RenderStage;