mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 17:59:56 +00:00
Make updating global shader defines update shaders.
This commit is contained in:
parent
8957c92a36
commit
229cc9696f
3 changed files with 25 additions and 4 deletions
|
@ -244,7 +244,7 @@ namespace MWRender
|
||||||
for (auto itr = shadowDefines.begin(); itr != shadowDefines.end(); itr++)
|
for (auto itr = shadowDefines.begin(); itr != shadowDefines.end(); itr++)
|
||||||
globalDefines[itr->first] = itr->second;
|
globalDefines[itr->first] = itr->second;
|
||||||
|
|
||||||
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines);
|
mResourceSystem->getSceneManager()->getShaderManager().setGlobalDefines(globalDefines, mViewer);
|
||||||
|
|
||||||
mPathgrid.reset(new Pathgrid(mRootNode));
|
mPathgrid.reset(new Pathgrid(mRootNode));
|
||||||
|
|
||||||
|
|
|
@ -337,10 +337,29 @@ namespace Shader
|
||||||
return DefineMap(mGlobalDefines);
|
return DefineMap(mGlobalDefines);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderManager::setGlobalDefines(DefineMap & defines)
|
void ShaderManager::setGlobalDefines(DefineMap & defines, osg::ref_ptr<osgViewer::Viewer> viewer)
|
||||||
{
|
{
|
||||||
mGlobalDefines = defines;
|
mGlobalDefines = defines;
|
||||||
// TODO: We need to trigger the regeneration of all shaders.
|
bool threadsStarted = viewer->areThreadsRunning();
|
||||||
|
if (threadsStarted)
|
||||||
|
viewer->stopThreading();
|
||||||
|
for (auto shaderMapElement: mShaders)
|
||||||
|
{
|
||||||
|
std::string templateId = shaderMapElement.first.first;
|
||||||
|
ShaderManager::DefineMap defines = shaderMapElement.first.second;
|
||||||
|
osg::ref_ptr<osg::Shader> shader = shaderMapElement.second;
|
||||||
|
if (shader == nullptr)
|
||||||
|
// I'm not sure how to handle a shader that was already broken as there's no way to get a potential replacement to the nodes that need it.
|
||||||
|
continue;
|
||||||
|
std::string shaderSource = mShaderTemplates[templateId];
|
||||||
|
if (!parseDefines(shaderSource, defines, mGlobalDefines) || !parseFors(shaderSource))
|
||||||
|
// We just broke the shader and there's no way to force existing objects back to fixed-function mode as we would when creating the shader.
|
||||||
|
// If we put a nullptr in the shader map, we just lose the ability to put a working one in later.
|
||||||
|
continue;
|
||||||
|
shader->setShaderSource(shaderSource);
|
||||||
|
}
|
||||||
|
if (threadsStarted)
|
||||||
|
viewer->startThreading();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderManager::releaseGLObjects(osg::State *state)
|
void ShaderManager::releaseGLObjects(osg::State *state)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
#include <osg/Shader>
|
#include <osg/Shader>
|
||||||
|
|
||||||
|
#include <osgViewer/Viewer>
|
||||||
|
|
||||||
#include <OpenThreads/Mutex>
|
#include <OpenThreads/Mutex>
|
||||||
|
|
||||||
namespace Shader
|
namespace Shader
|
||||||
|
@ -37,7 +39,7 @@ namespace Shader
|
||||||
|
|
||||||
/// Set the DefineMap used to construct all shaders
|
/// Set the DefineMap used to construct all shaders
|
||||||
/// @param defines The DefineMap to use
|
/// @param defines The DefineMap to use
|
||||||
void setGlobalDefines(DefineMap& defines);
|
void setGlobalDefines(DefineMap & defines, osg::ref_ptr<osgViewer::Viewer> viewer);
|
||||||
|
|
||||||
void releaseGLObjects(osg::State* state);
|
void releaseGLObjects(osg::State* state);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue