Integrated Geoff Michel's updates to Stats code, whilest move all text rendering

back in the viewer from the Statistics header.

Added a osg::State::captureCurrentState(StateSet&) method and a copy constructor
to osg::StateSet.
This commit is contained in:
Robert Osfield
2001-10-22 22:02:47 +00:00
parent aac507e119
commit 25c8b05914
16 changed files with 453 additions and 345 deletions

View File

@@ -29,6 +29,19 @@ class Vec4;
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 GeoSet.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
{
@@ -136,14 +149,6 @@ class SG_EXPORT Drawable : public Object
COLORS = 0x4,
TEXTURE_COORDS = 0x8,
TEXTURE_COORDS_0 = TEXTURE_COORDS,
/*
* Robert,
* These would have kept you up late if you were
* trying to use these as bitmasks
TEXTURE_COORDS_1 = 0x16,
TEXTURE_COORDS_2 = 0x32,
TEXTURE_COORDS_3 = 0x64
*/
TEXTURE_COORDS_1 = 0x10,
TEXTURE_COORDS_2 = 0x20,
TEXTURE_COORDS_3 = 0x40

View File

@@ -290,6 +290,10 @@ class SG_EXPORT GeoSet : public Drawable
const bool check() const;
/** 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

@@ -111,6 +111,7 @@ class SG_EXPORT ImpostorSprite : public Drawable
/** draw ImpostorSprite directly. */
virtual void drawImmediateMode(State& state);
bool getStats(Statistics &stat);
protected:

View File

@@ -46,6 +46,9 @@ class SG_EXPORT State : public Referenced
/** pop drawstate off state stack.*/
void popStateSet();
/** copy the modes and attributes which captures the current state.*/
void captureCurrentState(StateSet& stateset) const;
/** reset the state object to an empty stack.*/
void reset();

View File

@@ -28,6 +28,8 @@ class SG_EXPORT StateSet : public Object
StateSet();
StateSet(const StateSet&);
virtual Object* clone() const { return new StateSet(); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
virtual const char* className() const { return "StateSet"; }
@@ -154,7 +156,6 @@ class SG_EXPORT StateSet : public Object
virtual ~StateSet();
StateSet(const StateSet&):Object() {}
StateSet& operator = (const StateSet&) { return *this; }

View File

@@ -2,135 +2,57 @@
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_STATISTICS
#define OSG_STATISTICS 1
#ifndef OSGUTIL_STATISTICS
#define OSGUTIL_STATISTICS 1
#include <osg/GeoSet>
#include <osg/Object>
namespace osg {
/**
* Statistics base class. Used to extract primitive information from
* the renderBin(s).
* the renderBin(s). Add a case of getStats(osgUtil::Statistics *stat)
* for any new drawable (or drawable derived class) that you generate
* (eg see GeoSet.cpp). There are 20 types of drawable counted - actually only
* 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.
*/
class /*SG_EXPORT*/ Statistics : public Object
class SG_EXPORT Statistics : public osg::Object
{
public:
Statistics() {
numOpaque=0, nummat=0;
nprims=0, nlights=0; nbins=0;
nprims=0, nlights=0; nbins=0; nimpostor=0;
reset();
};
~Statistics() {}; // no dynamic allocations, so no need to free
void reset() {
for (int i=0; i<20; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0;
}
virtual osg::Object* clone() const { return new Statistics(); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Statistics*>(obj)!=0L; }
virtual const char* className() const { return "Statistics"; }
void addstat(osg::GeoSet *gs) { // analyse the drawable GeoSet
const int np=gs->getNumPrims(); // number of primitives in this geoset
nprims += np;
const int type=gs->getPrimType();
switch (type) {
case osg::GeoSet::POINTS:
case osg::GeoSet::LINES:
case osg::GeoSet::LINE_STRIP:
case osg::GeoSet::FLAT_LINE_STRIP:
case osg::GeoSet::LINE_LOOP:
case osg::GeoSet::TRIANGLE_STRIP:
case osg::GeoSet::FLAT_TRIANGLE_STRIP:
case osg::GeoSet::TRIANGLE_FAN:
case osg::GeoSet::FLAT_TRIANGLE_FAN:
case osg::GeoSet::QUAD_STRIP:
case osg::GeoSet::POLYGON:
primtypes[type]++;
primtypes[0]++;
break;
case osg::GeoSet::TRIANGLES: // should not have any lengths for tris & quads
primtypes[type]++;
primtypes[0]++;
primlens[0]+=np;
primlens[type]+=np;
numprimtypes[type]+=np;
primverts[type]+=3*np;
primverts[0]+=3*np;
break;
case osg::GeoSet::QUADS:
primtypes[type]++;
primtypes[0]++;
primlens[0]+=np*2;
primlens[type]+=np*2; // quad is equiv to 2 triangles
numprimtypes[type]+=np;
primverts[type]+=4*np;
primverts[0]+=4*np;
break;
case osg::GeoSet::NO_TYPE:
default:
break;
}
// now count the lengths, ie efficiency of triangulation
const int *lens=gs->getPrimLengths(); // primitive lengths
for (int i=0; i<np && lens; i++) {
switch (type) {
case osg::GeoSet::POINTS:
case osg::GeoSet::LINES:
case osg::GeoSet::LINE_STRIP:
case osg::GeoSet::FLAT_LINE_STRIP:
case osg::GeoSet::LINE_LOOP:
case osg::GeoSet::TRIANGLES: // should not have any lengths for tris & quads
case osg::GeoSet::QUADS:
case osg::GeoSet::QUAD_STRIP:
case osg::GeoSet::POLYGON:
primlens[0]+=lens[i];
primlens[type]+=lens[i];
break;
case osg::GeoSet::TRIANGLE_STRIP:
case osg::GeoSet::FLAT_TRIANGLE_STRIP:
case osg::GeoSet::TRIANGLE_FAN:
case osg::GeoSet::FLAT_TRIANGLE_FAN:
primlens[0]+=lens[i]-2;
primlens[type]+=lens[i]-2; // tri strips & fans create lens[i]-2 triangles
break;
case osg::GeoSet::NO_TYPE:
default:
break;
}
switch (type) {
case osg::GeoSet::POINTS:
case osg::GeoSet::LINES:
case osg::GeoSet::LINE_STRIP:
case osg::GeoSet::FLAT_LINE_STRIP:
case osg::GeoSet::LINE_LOOP:
case osg::GeoSet::TRIANGLES:
case osg::GeoSet::QUADS:
case osg::GeoSet::TRIANGLE_STRIP:
case osg::GeoSet::FLAT_TRIANGLE_STRIP:
case osg::GeoSet::TRIANGLE_FAN:
case osg::GeoSet::FLAT_TRIANGLE_FAN:
case osg::GeoSet::QUAD_STRIP:
case osg::GeoSet::POLYGON:
numprimtypes[0]++;
numprimtypes[type]++;
primverts[type]+=lens[i];
primverts[0]+=lens[i];
break;
case osg::GeoSet::NO_TYPE:
default:
break;
}
}
enum statsType {
STAT_NONE, // default
STAT_FRAMERATE, STAT_GRAPHS,
STAT_PRIMS, STAT_PRIMSPERVIEW,
STAT_DC,
STAT_RESTART // hint to restart the stats
};
void reset() {
for (int i=0; i<20; i++) primverts[i]=numprimtypes[i]=primlens[i]=primtypes[i]=0;
}
public:
public:
int numOpaque, nummat, nbins;
int nprims, nlights;
int nimpostor; // number of impostors rendered
int numprimtypes[20]; // histogram of number of each type of prim
int primtypes[20]; // histogram of number of each type of prim
int primlens[20]; // histogram of lengths of each type of prim
@@ -138,9 +60,8 @@ class /*SG_EXPORT*/ Statistics : public Object
protected:
};
};
}
#endif

View File

@@ -119,7 +119,7 @@ class OSGGLUT_EXPORT Viewer : public osgUtil::GUIActionAdapter
void setFocusedViewport(unsigned int pos);
int mapWindowXYToSceneView(int x, int y);
void showStats(void);
void showStats(const unsigned int i); // gwm 24.09.01 pass the viewport to collect sta for each viewport
static Viewer* s_theViewer;

View File

@@ -58,7 +58,7 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
virtual void draw_local(osg::State& state,RenderLeaf*& previous);
/** extract stats for current draw list. */
void getPrims(osg::Statistics *primStats);
void getStats(osg::Statistics& primStats);
public:

View File

@@ -116,7 +116,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
void addToDependencyList(RenderStage* rs);
/** extract stats for current draw list. */
void getPrims(osg::Statistics *primStats);
void getStats(osg::Statistics& primStats);
public: