GraphicsCostEstimator
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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_GRAPHICSCOSTESTIMATOR
#define OSG_GRAPHICSCOSTESTIMATOR
#include <osg/Referenced>
#include <osg/ref_ptr>
#include <utility>
namespace osg
{
class Geometry;
class Texture;
class Program;
class Node;
class RenderInfo;
struct ClampedLinearCostFunction1D
{
ClampedLinearCostFunction1D(double cost0=0.0, double dcost_di=0.0, unsigned int min_input=0):
_cost0(cost0),
_dcost_di(dcost_di),
_min_input(min_input) {}
void set(double cost0, double dcost_di, unsigned int min_input)
{
_cost0 = cost0;
_dcost_di = dcost_di;
_min_input = min_input;
}
double operator() (unsigned int input) const
{
return _cost0 + _dcost_di * double(input<=_min_input ? 0u : input-_min_input);
}
double _cost0;
double _dcost_di;
unsigned int _min_input;
};
typedef std::pair<double, double> CostPair;
class OSG_EXPORT GeometryCostEstimator : public osg::Referenced
{
public:
GeometryCostEstimator();
void setDefaults();
void calibrate(osg::RenderInfo& renderInfo);
CostPair estimateCompileCost(const osg::Geometry* geometry) const;
CostPair estimateDrawCost(const osg::Geometry* geometry) const;
protected:
ClampedLinearCostFunction1D _arrayCompileCost;
ClampedLinearCostFunction1D _primtiveSetCompileCost;
ClampedLinearCostFunction1D _arrayDrawCost;
ClampedLinearCostFunction1D _primtiveSetDrawCost;
double _displayListCompileConstant;
double _displayListCompileFactor;
};
class OSG_EXPORT TextureCostEstimator : public osg::Referenced
{
public:
TextureCostEstimator();
void setDefaults();
void calibrate(osg::RenderInfo& renderInfo);
CostPair estimateCompileCost(const osg::Texture* texture) const;
CostPair estimateDrawCost(const osg::Texture* texture) const;
protected:
ClampedLinearCostFunction1D _compileCost;
ClampedLinearCostFunction1D _drawCost;
};
class OSG_EXPORT ProgramCostEstimator : public osg::Referenced
{
public:
ProgramCostEstimator();
void setDefaults();
void calibrate(osg::RenderInfo& renderInfo);
CostPair estimateCompileCost(const osg::Program* program) const;
CostPair estimateDrawCost(const osg::Program* program) const;
protected:
ClampedLinearCostFunction1D _shaderCompileCost;
ClampedLinearCostFunction1D _linkCost;
ClampedLinearCostFunction1D _drawCost;
};
class OSG_EXPORT GraphicsCostEstimator : public osg::Referenced
{
public:
GraphicsCostEstimator();
void setDefaults();
void calibrate(osg::RenderInfo& renderInfo);
CostPair estimateCompileCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateCompileCost(geometry); }
CostPair estimateDrawCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateDrawCost(geometry); }
CostPair estimateCompileCost(const osg::Texture* texture) const { return _textureEstimator->estimateCompileCost(texture); }
CostPair estimateDrawCost(const osg::Texture* texture) const { return _textureEstimator->estimateDrawCost(texture); }
CostPair estimateCompileCost(const osg::Program* program) const { return _programEstimator->estimateCompileCost(program); }
CostPair estimateDrawCost(const osg::Program* program) const { return _programEstimator->estimateDrawCost(program); }
CostPair estimateCompileCost(const osg::Node* node) const;
CostPair estimateDrawCost(const osg::Node* node) const;
protected:
virtual ~GraphicsCostEstimator();
osg::ref_ptr<GeometryCostEstimator> _geometryEstimator;
osg::ref_ptr<TextureCostEstimator> _textureEstimator;
osg::ref_ptr<ProgramCostEstimator> _programEstimator;
};
}
#endif
Referenced
osg::GeometryCostEstimator::_displayListCompileConstant
double _displayListCompileConstant
Definition GraphicsCostEstimator:73
osg::GeometryCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Geometry *geometry) const
osg::GeometryCostEstimator::_primtiveSetCompileCost
ClampedLinearCostFunction1D _primtiveSetCompileCost
Definition GraphicsCostEstimator:68
osg::GeometryCostEstimator::_displayListCompileFactor
double _displayListCompileFactor
Definition GraphicsCostEstimator:74
osg::GeometryCostEstimator::GeometryCostEstimator
GeometryCostEstimator()
osg::GeometryCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Geometry *geometry) const
osg::GeometryCostEstimator::calibrate
void calibrate(osg::RenderInfo &renderInfo)
osg::GeometryCostEstimator::_arrayDrawCost
ClampedLinearCostFunction1D _arrayDrawCost
Definition GraphicsCostEstimator:70
osg::GeometryCostEstimator::setDefaults
void setDefaults()
osg::GeometryCostEstimator::_primtiveSetDrawCost
ClampedLinearCostFunction1D _primtiveSetDrawCost
Definition GraphicsCostEstimator:71
osg::GeometryCostEstimator::_arrayCompileCost
ClampedLinearCostFunction1D _arrayCompileCost
Definition GraphicsCostEstimator:67
osg::Geometry
Definition Geometry:31
osg::GraphicsCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Node *node) const
osg::GraphicsCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Texture *texture) const
Definition GraphicsCostEstimator:122
osg::GraphicsCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Program *program) const
Definition GraphicsCostEstimator:125
osg::GraphicsCostEstimator::_geometryEstimator
osg::ref_ptr< GeometryCostEstimator > _geometryEstimator
Definition GraphicsCostEstimator:134
osg::GraphicsCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Geometry *geometry) const
Definition GraphicsCostEstimator:118
osg::GraphicsCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Program *program) const
Definition GraphicsCostEstimator:124
osg::GraphicsCostEstimator::calibrate
void calibrate(osg::RenderInfo &renderInfo)
osg::GraphicsCostEstimator::GraphicsCostEstimator
GraphicsCostEstimator()
osg::GraphicsCostEstimator::_textureEstimator
osg::ref_ptr< TextureCostEstimator > _textureEstimator
Definition GraphicsCostEstimator:135
osg::GraphicsCostEstimator::_programEstimator
osg::ref_ptr< ProgramCostEstimator > _programEstimator
Definition GraphicsCostEstimator:136
osg::GraphicsCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Geometry *geometry) const
Definition GraphicsCostEstimator:119
osg::GraphicsCostEstimator::~GraphicsCostEstimator
virtual ~GraphicsCostEstimator()
osg::GraphicsCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Texture *texture) const
Definition GraphicsCostEstimator:121
osg::GraphicsCostEstimator::setDefaults
void setDefaults()
osg::GraphicsCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Node *node) const
osg::Node
Definition Node:72
osg::ProgramCostEstimator::setDefaults
void setDefaults()
osg::ProgramCostEstimator::ProgramCostEstimator
ProgramCostEstimator()
osg::ProgramCostEstimator::_shaderCompileCost
ClampedLinearCostFunction1D _shaderCompileCost
Definition GraphicsCostEstimator:102
osg::ProgramCostEstimator::_drawCost
ClampedLinearCostFunction1D _drawCost
Definition GraphicsCostEstimator:104
osg::ProgramCostEstimator::_linkCost
ClampedLinearCostFunction1D _linkCost
Definition GraphicsCostEstimator:103
osg::ProgramCostEstimator::calibrate
void calibrate(osg::RenderInfo &renderInfo)
osg::ProgramCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Program *program) const
osg::ProgramCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Program *program) const
osg::Program
Definition osg/Program:52
osg::Referenced
Definition Referenced:44
osg::RenderInfo
Definition RenderInfo:28
osg::TextureCostEstimator::estimateDrawCost
CostPair estimateDrawCost(const osg::Texture *texture) const
osg::TextureCostEstimator::estimateCompileCost
CostPair estimateCompileCost(const osg::Texture *texture) const
osg::TextureCostEstimator::setDefaults
void setDefaults()
osg::TextureCostEstimator::_compileCost
ClampedLinearCostFunction1D _compileCost
Definition GraphicsCostEstimator:87
osg::TextureCostEstimator::calibrate
void calibrate(osg::RenderInfo &renderInfo)
osg::TextureCostEstimator::TextureCostEstimator
TextureCostEstimator()
osg::TextureCostEstimator::_drawCost
ClampedLinearCostFunction1D _drawCost
Definition GraphicsCostEstimator:88
osg::Texture
Definition Texture:422
osg::ref_ptr
Definition ref_ptr:32
osg
Definition AlphaFunc:19
osg::CostPair
std::pair< double, double > CostPair
Definition GraphicsCostEstimator:54
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39
ref_ptr
osg::ClampedLinearCostFunction1D
Definition GraphicsCostEstimator:31
osg::ClampedLinearCostFunction1D::set
void set(double cost0, double dcost_di, unsigned int min_input)
Definition GraphicsCostEstimator:37
osg::ClampedLinearCostFunction1D::operator()
double operator()(unsigned int input) const
Definition GraphicsCostEstimator:44
osg::ClampedLinearCostFunction1D::_cost0
double _cost0
Definition GraphicsCostEstimator:48
osg::ClampedLinearCostFunction1D::_min_input
unsigned int _min_input
Definition GraphicsCostEstimator:50
osg::ClampedLinearCostFunction1D::_dcost_di
double _dcost_di
Definition GraphicsCostEstimator:49
osg::ClampedLinearCostFunction1D::ClampedLinearCostFunction1D
ClampedLinearCostFunction1D(double cost0=0.0, double dcost_di=0.0, unsigned int min_input=0)
Definition GraphicsCostEstimator:32