mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-06 21:45:33 +00:00
fix race condition with sun uniform
This commit is contained in:
parent
b7adb9d088
commit
8ce65232ff
2 changed files with 37 additions and 1 deletions
|
@ -644,7 +644,7 @@ namespace SceneUtil
|
||||||
configureAmbient(lightMat, sun->getAmbient());
|
configureAmbient(lightMat, sun->getAmbient());
|
||||||
configureDiffuse(lightMat, sun->getDiffuse());
|
configureDiffuse(lightMat, sun->getDiffuse());
|
||||||
configureSpecular(lightMat, sun->getSpecular());
|
configureSpecular(lightMat, sun->getSpecular());
|
||||||
mLightManager->getStateSet()->getUniform("LightBuffer")->setElement(0, lightMat);
|
mLightManager->setSunlightBuffer(lightMat, mLastFrameNumber);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -767,6 +767,36 @@ namespace SceneUtil
|
||||||
osg::ref_ptr<osg::Program> mDummyProgram;
|
osg::ref_ptr<osg::Program> mDummyProgram;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LightManagerStateAttributePerObjectUniform : public osg::StateAttribute
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LightManagerStateAttributePerObjectUniform()
|
||||||
|
: mLightManager(nullptr) {}
|
||||||
|
|
||||||
|
LightManagerStateAttributePerObjectUniform(LightManager* lightManager)
|
||||||
|
: mLightManager(lightManager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
LightManagerStateAttributePerObjectUniform(const LightManagerStateAttributePerObjectUniform& copy, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY)
|
||||||
|
: osg::StateAttribute(copy,copyop), mLightManager(copy.mLightManager) {}
|
||||||
|
|
||||||
|
int compare(const StateAttribute &sa) const override
|
||||||
|
{
|
||||||
|
throw std::runtime_error("LightManagerStateAttributePerObjectUniform::compare: unimplemented");
|
||||||
|
}
|
||||||
|
|
||||||
|
META_StateAttribute(NifOsg, LightManagerStateAttributePerObjectUniform, osg::StateAttribute::LIGHT)
|
||||||
|
|
||||||
|
void apply(osg::State& state) const override
|
||||||
|
{
|
||||||
|
mLightManager->getStateSet()->getUniform("LightBuffer")->setElement(0, mLightManager->getSunlightBuffer(state.getFrameStamp()->getFrameNumber()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
LightManager* mLightManager;
|
||||||
|
};
|
||||||
|
|
||||||
const std::unordered_map<std::string, LightingMethod> LightManager::mLightingMethodSettingMap = {
|
const std::unordered_map<std::string, LightingMethod> LightManager::mLightingMethodSettingMap = {
|
||||||
{"legacy", LightingMethod::FFP}
|
{"legacy", LightingMethod::FFP}
|
||||||
,{"shaders compatibility", LightingMethod::PerObjectUniform}
|
,{"shaders compatibility", LightingMethod::PerObjectUniform}
|
||||||
|
@ -845,6 +875,7 @@ namespace SceneUtil
|
||||||
initSingleUBO(targetLights);
|
initSingleUBO(targetLights);
|
||||||
|
|
||||||
getOrCreateStateSet()->addUniform(new osg::Uniform("PointLightCount", 0));
|
getOrCreateStateSet()->addUniform(new osg::Uniform("PointLightCount", 0));
|
||||||
|
getOrCreateStateSet()->setAttributeAndModes(new LightManagerStateAttributePerObjectUniform(this), osg::StateAttribute::ON);
|
||||||
|
|
||||||
addCullCallback(new LightManagerCullCallback(this));
|
addCullCallback(new LightManagerCullCallback(this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,6 +179,9 @@ namespace SceneUtil
|
||||||
|
|
||||||
auto& getLightBuffer(size_t frameNum) { return mLightBuffers[frameNum%2]; }
|
auto& getLightBuffer(size_t frameNum) { return mLightBuffers[frameNum%2]; }
|
||||||
|
|
||||||
|
osg::Matrixf getSunlightBuffer(size_t frameNum) const { return mSunlightBuffers[frameNum%2]; }
|
||||||
|
void setSunlightBuffer(const osg::Matrixf& buffer, size_t frameNum) { mSunlightBuffers[frameNum%2] = buffer; }
|
||||||
|
|
||||||
std::map<std::string, std::string> getLightDefines() const;
|
std::map<std::string, std::string> getLightDefines() const;
|
||||||
|
|
||||||
void processChangedSettings(const Settings::CategorySettingVector& changed);
|
void processChangedSettings(const Settings::CategorySettingVector& changed);
|
||||||
|
@ -217,6 +220,8 @@ namespace SceneUtil
|
||||||
|
|
||||||
osg::ref_ptr<LightBuffer> mLightBuffers[2];
|
osg::ref_ptr<LightBuffer> mLightBuffers[2];
|
||||||
|
|
||||||
|
osg::Matrixf mSunlightBuffers[2];
|
||||||
|
|
||||||
// < Light ID , Buffer Index >
|
// < Light ID , Buffer Index >
|
||||||
using LightIndexMap = std::unordered_map<int, int>;
|
using LightIndexMap = std::unordered_map<int, int>;
|
||||||
LightIndexMap mLightIndexMaps[2];
|
LightIndexMap mLightIndexMaps[2];
|
||||||
|
|
Loading…
Reference in a new issue