Moved GraphicsCostEstimator from osgUtil into core OSG library

This commit is contained in:
Robert Osfield 2011-02-03 12:22:09 +00:00
parent bcda8e4671
commit 88ce98b47d
7 changed files with 42 additions and 30 deletions

View File

@ -22,13 +22,13 @@
#include <osgDB/ReadFile>
#include <osgUtil/GraphicsCostEstimator>
#include <osg/GraphicsCostEstimator>
class CalibrateCostEsimator : public osg::GraphicsOperation
{
public:
CalibrateCostEsimator(osgUtil::GraphicsCostEstimator* gce):
CalibrateCostEsimator(osg::GraphicsCostEstimator* gce):
osg::GraphicsOperation("CalbirateCostEstimator",false),
_gce(gce) {}
@ -38,7 +38,7 @@ public:
_gce->calibrate(renderInfo);
}
osg::ref_ptr<osgUtil::GraphicsCostEstimator> _gce;
osg::ref_ptr<osg::GraphicsCostEstimator> _gce;
};
@ -54,14 +54,14 @@ int main(int argc, char** argv)
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);
if (!node) return 0;
osg::ref_ptr<osgUtil::GraphicsCostEstimator> gce = new osgUtil::GraphicsCostEstimator;
osg::ref_ptr<osg::GraphicsCostEstimator> gce = new osg::GraphicsCostEstimator;
viewer.setSceneData(node.get());
viewer.realize();
osgUtil::CostPair compileCost = gce->estimateCompileCost(node.get());
osgUtil::CostPair drawCost = gce->estimateDrawCost(node.get());
osg::CostPair compileCost = gce->estimateCompileCost(node.get());
osg::CostPair drawCost = gce->estimateDrawCost(node.get());
OSG_NOTICE<<"estimateCompileCost("<<node->getName()<<"), CPU="<<compileCost.first<<" GPU="<<compileCost.second<<std::endl;
OSG_NOTICE<<"estimateDrawCost("<<node->getName()<<"), CPU="<<drawCost.first<<" GPU="<<drawCost.second<<std::endl;

View File

@ -11,18 +11,22 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_GRAPHICSCOSTESTIMATOR
#define OSGUTIL_GRAPHICSCOSTESTIMATOR
#ifndef OSG_GRAPHICSCOSTESTIMATOR
#define OSG_GRAPHICSCOSTESTIMATOR
#include <osgUtil/Export>
#include <osg/Referenced>
#include <osg/ref_ptr>
#include <utility>
#include <osg/Geometry>
#include <osg/Texture>
#include <osg/Program>
namespace osgUtil
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):
@ -50,7 +54,7 @@ struct ClampedLinearCostFunction1D
typedef std::pair<double, double> CostPair;
class OSGUTIL_EXPORT GeometryCostEstimator : public osg::Referenced
class OSG_EXPORT GeometryCostEstimator : public osg::Referenced
{
public:
GeometryCostEstimator();
@ -70,7 +74,7 @@ protected:
double _displayListCompileFactor;
};
class OSGUTIL_EXPORT TextureCostEstimator : public osg::Referenced
class OSG_EXPORT TextureCostEstimator : public osg::Referenced
{
public:
TextureCostEstimator();
@ -85,7 +89,7 @@ protected:
};
class OSGUTIL_EXPORT ProgramCostEstimator : public osg::Referenced
class OSG_EXPORT ProgramCostEstimator : public osg::Referenced
{
public:
ProgramCostEstimator();
@ -100,7 +104,7 @@ protected:
ClampedLinearCostFunction1D _drawCost;
};
class OSGUTIL_EXPORT GraphicsCostEstimator : public osg::Referenced
class OSG_EXPORT GraphicsCostEstimator : public osg::Referenced
{
public:
GraphicsCostEstimator();

View File

@ -15,7 +15,8 @@
#define OSGUTIL_INCREMENTALCOMPILEOPERATOR
#include <osgUtil/GLObjectsVisitor>
#include <osgUtil/GraphicsCostEstimator>
#include <osg/GraphicsCostEstimator>
#include <osg/Geometry>
namespace osgUtil {
@ -119,8 +120,8 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
osg::Geometry* getForceTextureDownloadGeometry() { return _forceTextureDownloadGeometry.get(); }
const osg::Geometry* getForceTextureDownloadGeometry() const { return _forceTextureDownloadGeometry.get(); }
GraphicsCostEstimator* getGraphicsCostEstimator() { return _graphicsCostEstimator.get(); }
const GraphicsCostEstimator* getGraphicsCostEstimator() const { return _graphicsCostEstimator.get(); }
osg::GraphicsCostEstimator* getGraphicsCostEstimator() { return _graphicsCostEstimator.get(); }
const osg::GraphicsCostEstimator* getGraphicsCostEstimator() const { return _graphicsCostEstimator.get(); }
typedef std::vector<osg::GraphicsContext*> Contexts;
@ -147,6 +148,7 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
double availableTime() { return allocatedTime - timer.elapsedTime(); }
IncrementalCompileOperation* incrementalCompileOperation;
osg::GraphicsCostEstimator* graphicsCostEstimator;
unsigned int maxNumObjectsToCompile;
osg::ElapsedTime timer;
double allocatedTime;
@ -278,7 +280,7 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation
double _conservativeTimeRatio;
osg::ref_ptr<osg::Geometry> _forceTextureDownloadGeometry;
osg::ref_ptr<GraphicsCostEstimator> _graphicsCostEstimator;
osg::ref_ptr<osg::GraphicsCostEstimator> _graphicsCostEstimator;
OpenThreads::Mutex _toCompileMutex;
CompileSets _toCompile;

View File

@ -79,6 +79,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/GLBeginEndAdapter
${HEADER_PATH}/GLObjects
${HEADER_PATH}/GLU
${HEADER_PATH}/GraphicsCostEstimator
${HEADER_PATH}/GraphicsContext
${HEADER_PATH}/GraphicsThread
${HEADER_PATH}/Group
@ -251,6 +252,7 @@ ADD_LIBRARY(${LIB_NAME}
GLObjects.cpp
GLStaticLibrary.h
GLStaticLibrary.cpp
GraphicsCostEstimator.cpp
GraphicsContext.cpp
GraphicsThread.cpp
Group.cpp

View File

@ -11,10 +11,15 @@
* OpenSceneGraph Public License for more details.
*/
#include <osgUtil/GraphicsCostEstimator>
#include <osg/GraphicsCostEstimator>
#include <osg/RenderInfo>
#include <osg/Geometry>
#include <osg/Texture>
#include <osg/Program>
#include <osg/Geode>
namespace osgUtil
namespace osg
{
/////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -18,7 +18,6 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/EdgeCollector
${HEADER_PATH}/Export
${HEADER_PATH}/GLObjectsVisitor
${HEADER_PATH}/GraphicsCostEstimator
${HEADER_PATH}/HalfWayMapGenerator
${HEADER_PATH}/HighlightMapGenerator
${HEADER_PATH}/IntersectionVisitor
@ -63,7 +62,6 @@ ADD_LIBRARY(${LIB_NAME}
DrawElementTypeSimplifier.cpp
EdgeCollector.cpp
GLObjectsVisitor.cpp
GraphicsCostEstimator.cpp
HalfWayMapGenerator.cpp
HighlightMapGenerator.cpp
IntersectionVisitor.cpp

View File

@ -214,7 +214,7 @@ IncrementalCompileOperation::CompileDrawableOp::CompileDrawableOp(osg::Drawable*
double IncrementalCompileOperation::CompileDrawableOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
{
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator;
osg::Geometry* geometry = _drawable->asGeometry();
if (gce && geometry)
{
@ -237,7 +237,7 @@ IncrementalCompileOperation::CompileTextureOp::CompileTextureOp(osg::Texture* te
double IncrementalCompileOperation::CompileTextureOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
{
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator;
if (gce) return gce->estimateCompileCost(_texture.get()).first;
else return 0.0;
}
@ -272,7 +272,7 @@ IncrementalCompileOperation::CompileProgramOp::CompileProgramOp(osg::Program* pr
double IncrementalCompileOperation::CompileProgramOp::estimatedTimeForCompile(CompileInfo& compileInfo) const
{
GraphicsCostEstimator* gce = compileInfo.incrementalCompileOperation->getGraphicsCostEstimator();
osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator;
if (gce) return gce->estimateCompileCost(_program.get()).first;
else return 0.0;
}
@ -288,6 +288,7 @@ IncrementalCompileOperation::CompileInfo::CompileInfo(osg::GraphicsContext* cont
{
setState(context->getState());
incrementalCompileOperation = ico;
graphicsCostEstimator = ico->getGraphicsCostEstimator();
}
@ -443,7 +444,7 @@ IncrementalCompileOperation::IncrementalCompileOperation():
_maximumNumOfObjectsToCompilePerFrame = atoi(ptr);
}
_graphicsCostEstimator = new GraphicsCostEstimator;
_graphicsCostEstimator = new osg::GraphicsCostEstimator;
// assignForceTextureDownloadGeometry();
}