Added new osg::Stats class for collecting frame stats of different sorts.

Added s/getStats() to osg::View and osg::Camera.
Added population of View::getStats() with frame stats in osgViewer/Viewer.
Added Basic StatsHandler to osgviewer example.
This commit is contained in:
Robert Osfield
2007-01-19 19:53:23 +00:00
parent a90206bcbb
commit f0e2404541
8 changed files with 351 additions and 16 deletions

View File

@@ -21,6 +21,7 @@
#include <osg/Texture>
#include <osg/Image>
#include <osg/GraphicsContext>
#include <osg/Stats>
#include <OpenThreads/Mutex>
@@ -53,6 +54,16 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
const View* getView() const { return _view; }
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
void setStats(osg::Stats* stats) { _stats = stats; }
/** Get the Stats object.*/
osg::Stats* getStats() { return _stats.get(); }
/** Get the const Stats object.*/
const osg::Stats* getStats() const { return _stats.get(); }
/** Sets the clear color. */
inline void setClearColor(const Vec4& color) { _clearColor = color; }
@@ -80,8 +91,6 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
ColorMask* getColorMask() { return _colorMask.get(); }
/** Set the viewport of the camera to use specified osg::Viewport. */
void setViewport(osg::Viewport* viewport);
@@ -376,6 +385,8 @@ class OSG_EXPORT Camera : public Transform, public CullSettings
View* _view;
osg::ref_ptr<osg::Stats> _stats;
Vec4 _clearColor;
GLbitfield _clearMask;

80
include/osg/Stats Normal file
View File

@@ -0,0 +1,80 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2007 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 OSG_STATS
#define OSG_STATS 1
#include <osg/Referenced>
#include <string>
#include <map>
#include <vector>
#include <ostream>
namespace osg {
class Stats : public osg::Referenced
{
public:
Stats(const std::string& name, unsigned int numberOfFrames=100);
void setName(const std::string& name) { _name = name; }
const std::string& getName() const { return _name; }
void allocate(unsigned int numberOfFrames);
int getEarliestFrameNumber() const { return _latestFrameNumber < static_cast<int>(_attributeMapList.size()) ? 0 : _latestFrameNumber - _attributeMapList.size() + 1; }
int getLatestFrameNumber() const { return _latestFrameNumber; }
typedef std::map<std::string, double> AttributeMap;
typedef std::vector<AttributeMap> AttributeMapList;
bool setAttribute(int frameNumber, const std::string& attributeName, double value);
bool getAttribute(int frameNumber, const std::string& attributeName, double& value) const;
AttributeMap& getAttributeMap(int frameNumber);
const AttributeMap& getAttributeMap(int frameNumber) const;
void report(std::ostream& out);
protected:
virtual ~Stats() {}
int getIndex(int frameNumber) const
{
// reject frame that are in the future
if (frameNumber > _latestFrameNumber) return -1;
// reject frames that are too early
if (frameNumber < getEarliestFrameNumber()) return -1;
if (frameNumber >= _baseFrameNumber) return frameNumber - _baseFrameNumber;
else return _attributeMapList.size() - (_baseFrameNumber-frameNumber);
}
std::string _name;
int _baseFrameNumber;
int _latestFrameNumber;
AttributeMapList _attributeMapList;
AttributeMap _invalidAttributeMap;
};
}
#endif

View File

@@ -31,6 +31,17 @@ class OSG_EXPORT View : public virtual osg::Referenced
View();
/** Set the Stats object used for collect various frame related timing and scene graph stats.*/
void setStats(osg::Stats* stats) { _stats = stats; }
/** Get the Stats object.*/
osg::Stats* getStats() { return _stats.get(); }
/** Get the const Stats object.*/
const osg::Stats* getStats() const { return _stats.get(); }
/** Set the master camera of the view. */
void setCamera(osg::Camera* camera) { _camera = camera; }
@@ -84,6 +95,8 @@ class OSG_EXPORT View : public virtual osg::Referenced
virtual ~View();
osg::ref_ptr<osg::Stats> _stats;
osg::ref_ptr<osg::Camera> _camera;
typedef std::vector<Slave> Slaves;