mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Make shadow debug HUD thread-safe
* Double buffer the frustum uniforms. * Don't mess with the debug geometry's StateSet. * Change two-element vectors to arrays so the size is explicit.
This commit is contained in:
parent
5c37b5bc4b
commit
98b2d5d921
@ -3104,12 +3104,12 @@ SceneUtil::MWShadowTechnique::DebugHUD::DebugHUD(int numberOfShadowMapsPerLight)
|
||||
fragmentShader = new osg::Shader(osg::Shader::FRAGMENT, debugFrustumFragmentShaderSource);
|
||||
frustumProgram->addShader(fragmentShader);
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
for (auto& frustumGeometry : mFrustumGeometries)
|
||||
{
|
||||
mFrustumGeometries.emplace_back(new osg::Geometry());
|
||||
mFrustumGeometries[i]->setCullingActive(false);
|
||||
frustumGeometry = new osg::Geometry();
|
||||
frustumGeometry->setCullingActive(false);
|
||||
|
||||
mFrustumGeometries[i]->getOrCreateStateSet()->setAttributeAndModes(frustumProgram, osg::StateAttribute::ON);
|
||||
frustumGeometry->getOrCreateStateSet()->setAttributeAndModes(frustumProgram, osg::StateAttribute::ON);
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::DrawElementsUShort> frustumDrawElements = new osg::DrawElementsUShort(osg::PrimitiveSet::LINE_STRIP);
|
||||
@ -3145,12 +3145,14 @@ void SceneUtil::MWShadowTechnique::DebugHUD::draw(osg::ref_ptr<osg::Texture2D> t
|
||||
// It might be possible to change shadow settings at runtime
|
||||
if (shadowMapNumber > mDebugCameras.size())
|
||||
addAnotherShadowMap();
|
||||
|
||||
mFrustumUniforms[shadowMapNumber]->set(matrix);
|
||||
|
||||
osg::ref_ptr<osg::StateSet> stateSet = mDebugGeometry[shadowMapNumber]->getOrCreateStateSet();
|
||||
osg::ref_ptr<osg::StateSet> stateSet = new osg::StateSet();
|
||||
stateSet->setTextureAttributeAndModes(sDebugTextureUnit, texture, osg::StateAttribute::ON);
|
||||
|
||||
auto frustumUniform = mFrustumUniforms[cv.getTraversalNumber() % 2][shadowMapNumber];
|
||||
frustumUniform->set(matrix);
|
||||
stateSet->addUniform(frustumUniform);
|
||||
|
||||
// Some of these calls may be superfluous.
|
||||
unsigned int traversalMask = cv.getTraversalMask();
|
||||
cv.setTraversalMask(mDebugGeometry[shadowMapNumber]->getNodeMask());
|
||||
@ -3205,6 +3207,6 @@ void SceneUtil::MWShadowTechnique::DebugHUD::addAnotherShadowMap()
|
||||
mFrustumTransforms[shadowMapNumber]->setCullingActive(false);
|
||||
mDebugCameras[shadowMapNumber]->addChild(mFrustumTransforms[shadowMapNumber]);
|
||||
|
||||
mFrustumUniforms.push_back(new osg::Uniform(osg::Uniform::FLOAT_MAT4, "transform"));
|
||||
mFrustumTransforms[shadowMapNumber]->getOrCreateStateSet()->addUniform(mFrustumUniforms[shadowMapNumber]);
|
||||
for(auto& uniformVector : mFrustumUniforms)
|
||||
uniformVector.push_back(new osg::Uniform(osg::Uniform::FLOAT_MAT4, "transform"));
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H
|
||||
#define COMPONENTS_SCENEUTIL_MWSHADOWTECHNIQUE_H 1
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include <osg/Camera>
|
||||
@ -282,8 +283,8 @@ namespace SceneUtil {
|
||||
osg::ref_ptr<osg::Program> mDebugProgram;
|
||||
std::vector<osg::ref_ptr<osg::Node>> mDebugGeometry;
|
||||
std::vector<osg::ref_ptr<osg::Group>> mFrustumTransforms;
|
||||
std::vector<osg::ref_ptr<osg::Uniform>> mFrustumUniforms;
|
||||
std::vector<osg::ref_ptr<osg::Geometry>> mFrustumGeometries;
|
||||
std::array<std::vector<osg::ref_ptr<osg::Uniform>>, 2> mFrustumUniforms;
|
||||
std::array<osg::ref_ptr<osg::Geometry>, 2> mFrustumGeometries;
|
||||
};
|
||||
|
||||
osg::ref_ptr<DebugHUD> _debugHud;
|
||||
|
Loading…
x
Reference in New Issue
Block a user