1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSG_GRAPHICSCOSTESTIMATOR
15#define OSG_GRAPHICSCOSTESTIMATOR
17#include <osg/Referenced>
30struct ClampedLinearCostFunction1D
32 ClampedLinearCostFunction1D(double cost0=0.0, double dcost_di=0.0, unsigned int min_input=0):
35 _min_input(min_input) {}
37 void set(double cost0, double dcost_di, unsigned int min_input)
41 _min_input = min_input;
44 double operator() (unsigned int input) const
46 return _cost0 + _dcost_di * double(input<=_min_input ? 0u : input-_min_input);
50 unsigned int _min_input;
53/** Pair of double representing CPU and GPU times in seconds as first and second elements in std::pair. */
54typedef std::pair<double, double> CostPair;
57class OSG_EXPORT GeometryCostEstimator : public osg::Referenced
60 GeometryCostEstimator();
62 void calibrate(osg::RenderInfo& renderInfo);
63 CostPair estimateCompileCost(const osg::Geometry* geometry) const;
64 CostPair estimateDrawCost(const osg::Geometry* geometry) const;
67 ClampedLinearCostFunction1D _arrayCompileCost;
68 ClampedLinearCostFunction1D _primtiveSetCompileCost;
70 ClampedLinearCostFunction1D _arrayDrawCost;
71 ClampedLinearCostFunction1D _primtiveSetDrawCost;
73 double _displayListCompileConstant;
74 double _displayListCompileFactor;
77class OSG_EXPORT TextureCostEstimator : public osg::Referenced
80 TextureCostEstimator();
82 void calibrate(osg::RenderInfo& renderInfo);
83 CostPair estimateCompileCost(const osg::Texture* texture) const;
84 CostPair estimateDrawCost(const osg::Texture* texture) const;
87 ClampedLinearCostFunction1D _compileCost;
88 ClampedLinearCostFunction1D _drawCost;
92class OSG_EXPORT ProgramCostEstimator : public osg::Referenced
95 ProgramCostEstimator();
97 void calibrate(osg::RenderInfo& renderInfo);
98 CostPair estimateCompileCost(const osg::Program* program) const;
99 CostPair estimateDrawCost(const osg::Program* program) const;
102 ClampedLinearCostFunction1D _shaderCompileCost;
103 ClampedLinearCostFunction1D _linkCost;
104 ClampedLinearCostFunction1D _drawCost;
107class OSG_EXPORT GraphicsCostEstimator : public osg::Referenced
110 GraphicsCostEstimator();
112 /** set defaults for computing the costs.*/
115 /** calibrate the costs of various compile and draw operations */
116 void calibrate(osg::RenderInfo& renderInfo);
118 CostPair estimateCompileCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateCompileCost(geometry); }
119 CostPair estimateDrawCost(const osg::Geometry* geometry) const { return _geometryEstimator->estimateDrawCost(geometry); }
121 CostPair estimateCompileCost(const osg::Texture* texture) const { return _textureEstimator->estimateCompileCost(texture); }
122 CostPair estimateDrawCost(const osg::Texture* texture) const { return _textureEstimator->estimateDrawCost(texture); }
124 CostPair estimateCompileCost(const osg::Program* program) const { return _programEstimator->estimateCompileCost(program); }
125 CostPair estimateDrawCost(const osg::Program* program) const { return _programEstimator->estimateDrawCost(program); }
127 CostPair estimateCompileCost(const osg::Node* node) const;
128 CostPair estimateDrawCost(const osg::Node* node) const;
132 virtual ~GraphicsCostEstimator();
134 osg::ref_ptr<GeometryCostEstimator> _geometryEstimator;
135 osg::ref_ptr<TextureCostEstimator> _textureEstimator;
136 osg::ref_ptr<ProgramCostEstimator> _programEstimator;