From b08938485f362f081cb9880bc8dad8c88964c15a Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Sun, 17 Dec 2017 23:55:19 +0000 Subject: [PATCH] Make suspending viewer threads the responsibility of the caller, not the shader manager. --- apps/openmw/mwrender/renderingmanager.cpp | 3 ++- components/shader/shadermanager.cpp | 9 ++------- components/shader/shadermanager.hpp | 3 ++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 5449fd460..41d9969d4 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -244,7 +244,8 @@ namespace MWRender for (auto itr = shadowDefines.begin(); itr != shadowDefines.end(); itr++) globalDefines[itr->first] = itr->second; - mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines, mViewer); + // It is unnecessary to stop/start the viewer as no frames are being rendered yet. + mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines); mPathgrid.reset(new Pathgrid(mRootNode)); diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index 533b3ae56..eb3a88eb4 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -337,12 +337,9 @@ namespace Shader return DefineMap(mGlobalDefines); } - void ShaderManager::setGlobalDefines(DefineMap & defines, osg::ref_ptr viewer) + void ShaderManager::setGlobalDefines(DefineMap & globalDefines) { - mGlobalDefines = defines; - bool threadsStarted = viewer->areThreadsRunning(); - if (threadsStarted) - viewer->stopThreading(); + mGlobalDefines = globalDefines; for (auto shaderMapElement: mShaders) { std::string templateId = shaderMapElement.first.first; @@ -358,8 +355,6 @@ namespace Shader continue; shader->setShaderSource(shaderSource); } - if (threadsStarted) - viewer->startThreading(); } void ShaderManager::releaseGLObjects(osg::State *state) diff --git a/components/shader/shadermanager.hpp b/components/shader/shadermanager.hpp index 16b4d639b..02f35975d 100644 --- a/components/shader/shadermanager.hpp +++ b/components/shader/shadermanager.hpp @@ -39,7 +39,8 @@ namespace Shader /// Set the DefineMap used to construct all shaders /// @param defines The DefineMap to use - void setGlobalDefines(DefineMap & defines, osg::ref_ptr viewer); + /// @note This will change the source code for any shaders already created, potentially causing problems if they're being used to render a frame. It is recommended that any associated Viewers have their threading stopped while this function is running if any shaders are in use. + void setGlobalDefines(DefineMap & globalDefines); void releaseGLObjects(osg::State* state);