From f8ac71d7e5b06b978cab70fc5428c213c16f36a7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 23 Aug 2007 11:00:12 +0000 Subject: [PATCH] Addd control for serializing draw dispatch. --- include/osg/DisplaySettings | 4 ++++ include/osgViewer/Renderer | 3 --- src/osg/DisplaySettings.cpp | 28 +++++++++++++++++++++++++++- src/osgViewer/Renderer.cpp | 12 +++++++----- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/include/osg/DisplaySettings b/include/osg/DisplaySettings index 81983049e..8db376836 100644 --- a/include/osg/DisplaySettings +++ b/include/osg/DisplaySettings @@ -179,6 +179,9 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced void setCompileContextsHint(bool useCompileContexts) { _compileContextsHint = useCompileContexts; } bool getCompileContextsHint() const { return _compileContextsHint; } + + void setSerializeDrawDispatch(bool serializeDrawDispatch) { _serializeDrawDispatch = serializeDrawDispatch; } + bool getSerializeDrawDispatch() const { return _serializeDrawDispatch; } protected: @@ -214,6 +217,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced unsigned int _numMultiSamples; bool _compileContextsHint; + bool _serializeDrawDispatch; }; diff --git a/include/osgViewer/Renderer b/include/osgViewer/Renderer index 0cba80c08..efea691ed 100644 --- a/include/osgViewer/Renderer +++ b/include/osgViewer/Renderer @@ -81,9 +81,6 @@ class OSGVIEWER_EXPORT Renderer : public osg::GraphicsOperation, public OpenGLQu virtual ~Renderer(); - - bool _serializeDraw; - osg::observer_ptr _camera; bool _done; diff --git a/src/osg/DisplaySettings.cpp b/src/osg/DisplaySettings.cpp index 1adba228a..95e460f2e 100644 --- a/src/osg/DisplaySettings.cpp +++ b/src/osg/DisplaySettings.cpp @@ -72,6 +72,7 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs) _numMultiSamples = vs._numMultiSamples; _compileContextsHint = vs._compileContextsHint; + _serializeDrawDispatch = vs._serializeDrawDispatch; } void DisplaySettings::merge(const DisplaySettings& vs) @@ -89,7 +90,7 @@ void DisplaySettings::merge(const DisplaySettings& vs) if (vs._numMultiSamples>_numMultiSamples) _numMultiSamples = vs._numMultiSamples; if (vs._compileContextsHint) _compileContextsHint = vs._compileContextsHint; - + if (vs._serializeDrawDispatch) _serializeDrawDispatch = vs._serializeDrawDispatch; } void DisplaySettings::setDefaults() @@ -130,6 +131,7 @@ void DisplaySettings::setDefaults() #endif _compileContextsHint = false; + _serializeDrawDispatch = true; } void DisplaySettings::setMaxNumberOfGraphicsContexts(unsigned int num) @@ -165,6 +167,8 @@ static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_ static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION ","number of pixels between viewports"); static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS ","maximum number of graphics contexts to be used with applications."); static ApplicationUsageProxy DisplaySetting_e13(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_COMPIlE_CONTEXTS ","OFF | ON Enable/disable the use a backgrouind compile contexts and threads."); +static ApplicationUsageProxy DisplaySetting_e14(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SERIALIZE_DRAW_DISPATCH ","OFF | ON Enable/disable the use a muetx to serialize the draw dispatch when there are multiple graphics threads."); + void DisplaySettings::readEnvironmentalVariables() { const char* ptr = 0; @@ -328,6 +332,21 @@ void DisplaySettings::readEnvironmentalVariables() _compileContextsHint = true; } } + + if( (ptr = getenv("OSG_SERIALIZE_DRAW_DISPATCH")) != 0) + { + if (strcmp(ptr,"OFF")==0) + { + _serializeDrawDispatch = false; + } + else + if (strcmp(ptr,"ON")==0) + { + _serializeDrawDispatch = true; + } + } + + } void DisplaySettings::readCommandLine(ArgumentParser& arguments) @@ -345,6 +364,7 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) arguments.getApplicationUsage()->addCommandLineOption("--accum-rgba","Request a rgb accumulator buffer visual"); arguments.getApplicationUsage()->addCommandLineOption("--samples ","Request a multisample visual"); arguments.getApplicationUsage()->addCommandLineOption("--cc","Request use of compile contexts and threads"); + arguments.getApplicationUsage()->addCommandLineOption("--serialize-draw ","OFF | ON - set the serialization of draw dispatch"); } std::string str; @@ -403,4 +423,10 @@ void DisplaySettings::readCommandLine(ArgumentParser& arguments) _compileContextsHint = true; } + while(arguments.read("--serialize-draw",str)) + { + if (str=="ON") _serializeDrawDispatch = true; + else if (str=="OFF") _serializeDrawDispatch = false; + } + } diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 46b6823f4..dd68a5921 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -152,7 +152,6 @@ static OpenThreads::Mutex s_drawSerializerMutex; Renderer::Renderer(osg::Camera* camera): osg::GraphicsOperation("Renderer",true), OpenGLQuerySupport(), - _serializeDraw(true), _camera(camera), _done(false), _graphicsThreadDoesCull(true) @@ -305,8 +304,6 @@ void Renderer::draw() osgUtil::SceneView* sceneView = _drawQueue.takeFront(); - - DEBUG_MESSAGE<<"draw() got SceneView "<getState()->getContextID()); @@ -365,8 +362,11 @@ void Renderer::draw() } osg::Timer_t beforeDrawTick; + + + bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch(); - if (_serializeDraw) + if (serializeDraw) { OpenThreads::ScopedLock lock(s_drawSerializerMutex); beforeDrawTick = osg::Timer::instance()->tick(); @@ -487,7 +487,9 @@ void Renderer::cull_draw() osg::Timer_t beforeDrawTick; - if (_serializeDraw) + bool serializeDraw = sceneView->getDisplaySettings()->getSerializeDrawDispatch(); + + if (serializeDraw) { OpenThreads::ScopedLock lock(s_drawSerializerMutex);