From 6496e3542130f0cf0d38c2c38cf08c8550fa7e72 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 3 Feb 2011 12:42:23 +0000 Subject: [PATCH] Moved GraphicsCostEstimator ref pointer into osg::State --- include/osg/State | 20 ++++++++++++++++++-- include/osgUtil/IncrementalCompileOperation | 7 ------- src/osg/State.cpp | 2 ++ src/osgUtil/IncrementalCompileOperation.cpp | 11 ++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/osg/State b/include/osg/State index 673d23813..2e30a3b27 100644 --- a/include/osg/State +++ b/include/osg/State @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1381,12 +1382,24 @@ class OSG_EXPORT State : public Referenced, public Observer virtual void objectDeleted(void* object); - /** get the GL adapter object used to map OpenGL 1.0 glBegin/glEnd usage to vertex arrays.*/ + /** Get the GL adapter object used to map OpenGL 1.0 glBegin/glEnd usage to vertex arrays.*/ inline GLBeginEndAdapter& getGLBeginEndAdapter() { return _glBeginEndAdapter; } - /** get the helper class for dispatching osg::Arrays as OpenGL attribute data.*/ + /** Get the helper class for dispatching osg::Arrays as OpenGL attribute data.*/ inline ArrayDispatchers& getArrayDispatchers() { return _arrayDispatchers; } + + /** Set the helper class that provides applications with estimate on how much different graphics operations will cost.*/ + inline void setGraphicsCostEstimator(GraphicsCostEstimator* gce) { _graphicsCostEstimator = gce; } + + /** Get the helper class that provides applications with estimate on how much different graphics operations will cost.*/ + inline GraphicsCostEstimator* getGraphicsCostEstimator() { return _graphicsCostEstimator.get(); } + + /** Get the cont helper class that provides applications with estimate on how much different graphics operations will cost.*/ + inline const GraphicsCostEstimator* getGraphicsCostEstimator() const { return _graphicsCostEstimator.get(); } + + + /** Support for synchronizing the system time and the timestamp * counter available with ARB_timer_query. Note that State * doesn't update these values itself. @@ -1822,6 +1835,9 @@ class OSG_EXPORT State : public Referenced, public Observer GLBeginEndAdapter _glBeginEndAdapter; ArrayDispatchers _arrayDispatchers; + + osg::ref_ptr _graphicsCostEstimator; + Timer_t _startTick; Timer_t _gpuTick; GLuint64EXT _gpuTimestamp; diff --git a/include/osgUtil/IncrementalCompileOperation b/include/osgUtil/IncrementalCompileOperation index 4d3a4377c..87fd0912c 100644 --- a/include/osgUtil/IncrementalCompileOperation +++ b/include/osgUtil/IncrementalCompileOperation @@ -15,7 +15,6 @@ #define OSGUTIL_INCREMENTALCOMPILEOPERATOR #include -#include #include namespace osgUtil { @@ -120,10 +119,6 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation osg::Geometry* getForceTextureDownloadGeometry() { return _forceTextureDownloadGeometry.get(); } const osg::Geometry* getForceTextureDownloadGeometry() const { return _forceTextureDownloadGeometry.get(); } - osg::GraphicsCostEstimator* getGraphicsCostEstimator() { return _graphicsCostEstimator.get(); } - const osg::GraphicsCostEstimator* getGraphicsCostEstimator() const { return _graphicsCostEstimator.get(); } - - typedef std::vector Contexts; void assignContexts(Contexts& contexts); void removeContexts(Contexts& contexts); @@ -148,7 +143,6 @@ 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; @@ -280,7 +274,6 @@ class OSGUTIL_EXPORT IncrementalCompileOperation : public osg::GraphicsOperation double _conservativeTimeRatio; osg::ref_ptr _forceTextureDownloadGeometry; - osg::ref_ptr _graphicsCostEstimator; OpenThreads::Mutex _toCompileMutex; CompileSets _toCompile; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index bdb818069..5d3fb3cac 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -159,6 +159,8 @@ State::State(): _glBeginEndAdapter.setState(this); _arrayDispatchers.setState(this); + _graphicsCostEstimator = new GraphicsCostEstimator; + _startTick = 0; _gpuTick = 0; _gpuTimestamp = 0; diff --git a/src/osgUtil/IncrementalCompileOperation.cpp b/src/osgUtil/IncrementalCompileOperation.cpp index 1fa8d2025..9b1b5e87b 100644 --- a/src/osgUtil/IncrementalCompileOperation.cpp +++ b/src/osgUtil/IncrementalCompileOperation.cpp @@ -54,7 +54,7 @@ static osg::ApplicationUsageProxy UCO_e2(osg::ApplicationUsage::ENVIRONMENTAL_VA StateToCompile::StateToCompile(GLObjectsVisitor::Mode mode): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), _mode(mode), - _assignPBOToImages(true) + _assignPBOToImages(false) { } @@ -214,7 +214,7 @@ IncrementalCompileOperation::CompileDrawableOp::CompileDrawableOp(osg::Drawable* double IncrementalCompileOperation::CompileDrawableOp::estimatedTimeForCompile(CompileInfo& compileInfo) const { - osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator; + osg::GraphicsCostEstimator* gce = compileInfo.getState()->getGraphicsCostEstimator(); 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 { - osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator; + osg::GraphicsCostEstimator* gce = compileInfo.getState()->getGraphicsCostEstimator(); 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 { - osg::GraphicsCostEstimator* gce = compileInfo.graphicsCostEstimator; + osg::GraphicsCostEstimator* gce = compileInfo.getState()->getGraphicsCostEstimator(); if (gce) return gce->estimateCompileCost(_program.get()).first; else return 0.0; } @@ -288,7 +288,6 @@ IncrementalCompileOperation::CompileInfo::CompileInfo(osg::GraphicsContext* cont { setState(context->getState()); incrementalCompileOperation = ico; - graphicsCostEstimator = ico->getGraphicsCostEstimator(); } @@ -444,8 +443,6 @@ IncrementalCompileOperation::IncrementalCompileOperation(): _maximumNumOfObjectsToCompilePerFrame = atoi(ptr); } - _graphicsCostEstimator = new osg::GraphicsCostEstimator; - // assignForceTextureDownloadGeometry(); }