OpenSceneGraph 3.6.5
Statistics
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGUTIL_STATISTICS
15#define OSGUTIL_STATISTICS 1
16
17#include <osgUtil/Export>
18
19#include <osg/PrimitiveSet>
20#include <osg/Drawable>
21#include <osg/NodeVisitor>
22#include <osg/Geode>
23#include <osg/LOD>
24#include <osg/Switch>
25#include <osg/Geometry>
26#include <osg/Transform>
27
28#include <map>
29#include <set>
30#include <ostream>
31
32namespace osgUtil {
33
46
48{
49 public:
50
51 typedef std::pair<unsigned int,unsigned int> PrimitivePair;
52 typedef std::map<GLenum,PrimitivePair> PrimitiveValueMap;
53 typedef std::map<GLenum, unsigned int> PrimitiveCountMap;
54
55
57
69
70 void reset();
71
72 void setType(StatsType t) { stattype=t; }
73
74 virtual void setVertexArray(unsigned int count,const osg::Vec3*) { _vertexCount += count; }
75 virtual void setVertexArray(unsigned int count,const osg::Vec2*) { _vertexCount += count; }
76 virtual void setVertexArray(unsigned int count,const osg::Vec4*) { _vertexCount += count; }
77 virtual void setVertexArray(unsigned int count,const osg::Vec3d*) { _vertexCount += count; }
78 virtual void setVertexArray(unsigned int count,const osg::Vec2d*) { _vertexCount += count; }
79 virtual void setVertexArray(unsigned int count,const osg::Vec4d*) { _vertexCount += count; }
80
81 virtual void drawArrays(GLenum mode,GLint,GLsizei count);
82 virtual void drawElements(GLenum mode,GLsizei count,const GLubyte*);
83 virtual void drawElements(GLenum mode,GLsizei count,const GLushort*);
84 virtual void drawElements(GLenum mode,GLsizei count,const GLuint*);
85
86 virtual void begin(GLenum mode);
87
88 inline void vertex()
89 {
91 ++prim.second;
92 _number_of_vertexes++;
93 }
94
95 virtual void vertex(float,float,float) { vertex(); }
96 virtual void vertex(const osg::Vec3&) { vertex(); }
97 virtual void vertex(const osg::Vec2&) { vertex(); }
98 virtual void vertex(const osg::Vec4&) { vertex(); }
99 virtual void vertex(float,float) { vertex(); }
100 virtual void vertex(float,float,float,float) { vertex(); }
101
102 virtual void end();
103
106 void addMatrix() { nummat++;}
107 void addLight(int np) { nlights+=np;}
108 void addImpostor(int np) { nimpostor+= np; }
109 inline int getBins() { return nbins;}
110 void setDepth(int d) { depth=d; }
111 void addBins(int np) { nbins+= np; }
112
113 void setBinNo(int n) { _binNo=n;}
114 void addStateGraphs(int n) { numStateGraphs += n; }
115 void addOrderedLeaves(int n) { numOrderedLeaves += n; }
116
117 void add(const Statistics& stats);
118
119 public:
120
121 PrimitiveCountMap& getPrimitiveCountMap() { return _primitives_count; }
122 const PrimitiveCountMap& getPrimitiveCountMap() const { return _primitives_count; }
123
126
127
129 PrimitiveCountMap::iterator GetPrimitivesBegin() { return _primitives_count.begin(); }
131 PrimitiveCountMap::iterator GetPrimitivesEnd() { return _primitives_count.end(); }
132
136 int depth; // depth into bins - eg 1.1,1.2,1.3 etc
139 int nimpostor; // number of impostors rendered
140 int numOrderedLeaves; // leaves from RenderBin fine grain ordering
141
142 unsigned int _vertexCount;
145
146 private:
147 PrimitiveCountMap _primitives_count;
148
149 unsigned int _total_primitives_count;
150 unsigned int _number_of_vertexes;
151
152 inline unsigned int _calculate_primitives_number_by_mode(GLenum, GLsizei);
153};
154
155inline unsigned int Statistics::_calculate_primitives_number_by_mode(GLenum mode, GLsizei count)
156{
157 switch (mode)
158 {
159 case GL_POINTS:
160 case GL_LINE_LOOP:
161 case GL_POLYGON: return count;
162 case GL_LINES: return count / 2;
163 case GL_LINE_STRIP: return count - 1;
164 case GL_TRIANGLES: return count / 3;
165 case GL_TRIANGLE_STRIP:
166 case GL_TRIANGLE_FAN: return count - 2;
167 case GL_QUADS: return count / 4;
168 case GL_QUAD_STRIP: return count / 2 - 1;
169 default: return 0;
170 }
171}
172
175{
176public:
177
178 typedef std::set<osg::Node*> NodeSet;
179 typedef std::set<osg::Drawable*> DrawableSet;
180 typedef std::set<osg::StateSet*> StateSetSet;
181
183
185
186 virtual void reset();
187
188 virtual void apply(osg::Node& node);
189 virtual void apply(osg::Group& node);
190 virtual void apply(osg::Transform& node);
191 virtual void apply(osg::LOD& node);
192 virtual void apply(osg::Switch& node);
193 virtual void apply(osg::Geode& node);
194 virtual void apply(osg::Drawable& drawable);
195 virtual void apply(osg::StateSet& ss);
196
197 virtual void totalUpStats();
198
199 virtual void print(std::ostream& out);
200
201 unsigned int _numInstancedGroup;
203 unsigned int _numInstancedLOD;
205 unsigned int _numInstancedGeode;
210
220
223};
224
225}
226
227#endif
Vec2f Vec2
Definition Vec2:21
Vec3f Vec3
Definition Vec3:21
Vec4f Vec4
Definition Vec4:21
The osgUtil library provides general purpose utility classes such as update, cull and draw traverses,...
Definition NodeVisitor:25
Pure virtual base class for drawable geometry.
Definition Drawable:89
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
General group node which maintains a list of children.
Definition Group:29
LOD - Level Of Detail group node which allows switching between children depending on distance from e...
Definition LOD:36
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
virtual void reset()
Method to call to reset visitor.
Definition NodeVisitor:167
A PrimitiveFunctor is used (in conjunction with osg::Drawable::accept (PrimitiveFunctor&)) to get acc...
Definition PrimitiveSet:54
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
Switch is a Group node that allows switching between children.
Definition Switch:27
A Transform is a group node for which all children are transformed by a 4x4 matrix.
Definition Transform:75
General purpose double pair, uses include representation of texture coordinates.
Definition Vec2d:29
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
General purpose double quad.
Definition Vec4d:29
Statistics base class.
Definition Statistics:48
int getBins()
Definition Statistics:109
void addStateGraphs(int n)
Definition Statistics:114
virtual void vertex(float, float, float, float)
Definition Statistics:100
void addLight(int np)
Definition Statistics:107
virtual void setVertexArray(unsigned int count, const osg::Vec4d *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:79
int _binNo
Definition Statistics:137
void setDepth(int d)
Definition Statistics:110
virtual void drawElements(GLenum mode, GLsizei count, const GLubyte *)
Mimics the OpenGL glDrawElements() function.
virtual void begin(GLenum mode)
GLenum _currentPrimitiveFunctorMode
Definition Statistics:144
virtual void setVertexArray(unsigned int count, const osg::Vec4 *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:76
void addOrderedLeaves(int n)
Definition Statistics:115
std::map< GLenum, unsigned int > PrimitiveCountMap
Definition Statistics:53
PrimitiveValueMap _primitiveCount
Definition Statistics:143
virtual void drawArrays(GLenum mode, GLint, GLsizei count)
Mimics the OpenGL glDrawArrays() function.
virtual void vertex(const osg::Vec3 &)
Definition Statistics:96
virtual void setVertexArray(unsigned int count, const osg::Vec3 *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:74
PrimitiveCountMap::iterator GetPrimitivesBegin()
deprecated
Definition Statistics:129
int numFastDrawables
Definition Statistics:134
virtual void setVertexArray(unsigned int count, const osg::Vec3d *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:77
unsigned int _vertexCount
Definition Statistics:142
StatsType stattype
Definition Statistics:138
std::map< GLenum, PrimitivePair > PrimitiveValueMap
Definition Statistics:52
int nlights
Definition Statistics:135
const PrimitiveCountMap & getPrimitiveCountMap() const
Definition Statistics:122
int nimpostor
Definition Statistics:139
virtual void vertex(const osg::Vec4 &)
Definition Statistics:98
void addDrawable()
Definition Statistics:104
void vertex()
Definition Statistics:88
void addFastDrawable()
Definition Statistics:105
virtual void setVertexArray(unsigned int count, const osg::Vec2 *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:75
int numDrawables
Definition Statistics:133
int depth
Definition Statistics:136
void addMatrix()
Definition Statistics:106
void setBinNo(int n)
Definition Statistics:113
virtual void vertex(float, float)
Definition Statistics:99
PrimitiveValueMap & getPrimitiveValueMap()
Definition Statistics:124
virtual void drawElements(GLenum mode, GLsizei count, const GLushort *)
Mimics the OpenGL glDrawElements() function.
virtual void end()
virtual void vertex(float, float, float)
Definition Statistics:95
void add(const Statistics &stats)
const PrimitiveValueMap & getPrimitiveValueMap() const
Definition Statistics:125
int nummat
Definition Statistics:133
PrimitiveCountMap::iterator GetPrimitivesEnd()
deprecated
Definition Statistics:131
void setType(StatsType t)
Definition Statistics:72
int numOrderedLeaves
Definition Statistics:140
PrimitiveCountMap & getPrimitiveCountMap()
Definition Statistics:121
virtual void drawElements(GLenum mode, GLsizei count, const GLuint *)
Mimics the OpenGL glDrawElements() function.
virtual void setVertexArray(unsigned int count, const osg::Vec2d *)
Sets the array of vertices used to describe the primitives.
Definition Statistics:78
int numStateGraphs
Definition Statistics:133
int nbins
Definition Statistics:133
void addBins(int np)
Definition Statistics:111
StatsType
Definition Statistics:59
@ STAT_PRIMS
Definition Statistics:63
@ STAT_GRAPHS
Definition Statistics:62
@ STAT_NONE
Definition Statistics:60
@ STAT_DC
Definition Statistics:66
@ STAT_PRIMSPERVIEW
Definition Statistics:64
@ STAT_FRAMERATE
Definition Statistics:61
@ STAT_PRIMSPERBIN
Definition Statistics:65
@ STAT_RESTART
Definition Statistics:67
std::pair< unsigned int, unsigned int > PrimitivePair
Definition Statistics:51
virtual void vertex(const osg::Vec2 &)
Definition Statistics:97
void addImpostor(int np)
Definition Statistics:108
virtual void apply(osg::Group &node)
META_NodeVisitor(osgUtil, StatsVisitor) virtual void reset()
std::set< osg::Node * > NodeSet
Definition Statistics:178
std::set< osg::StateSet * > StateSetSet
Definition Statistics:180
unsigned int _numInstancedDrawable
Definition Statistics:206
virtual void apply(osg::Switch &node)
StateSetSet _statesetSet
Definition Statistics:219
unsigned int _numInstancedLOD
Definition Statistics:203
virtual void apply(osg::Transform &node)
NodeSet _lodSet
Definition Statistics:213
NodeSet _switchSet
Definition Statistics:214
DrawableSet _geometrySet
Definition Statistics:217
osgUtil::Statistics _instancedStats
Definition Statistics:222
virtual void apply(osg::StateSet &ss)
NodeSet _transformSet
Definition Statistics:212
std::set< osg::Drawable * > DrawableSet
Definition Statistics:179
unsigned int _numInstancedSwitch
Definition Statistics:202
unsigned int _numInstancedStateSet
Definition Statistics:209
unsigned int _numInstancedFastGeometry
Definition Statistics:208
unsigned int _numInstancedTransform
Definition Statistics:204
virtual void print(std::ostream &out)
virtual void apply(osg::LOD &node)
DrawableSet _fastGeometrySet
Definition Statistics:218
unsigned int _numInstancedGeometry
Definition Statistics:207
osgUtil::Statistics _uniqueStats
Definition Statistics:221
virtual void apply(osg::Geode &node)
NodeSet _groupSet
Definition Statistics:211
virtual void totalUpStats()
unsigned int _numInstancedGeode
Definition Statistics:205
DrawableSet _drawableSet
Definition Statistics:216
unsigned int _numInstancedGroup
Definition Statistics:201
NodeSet _geodeSet
Definition Statistics:215
virtual void apply(osg::Node &node)
virtual void apply(osg::Drawable &drawable)
#define OSGUTIL_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.