1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-26 06:39:43 +00:00

Merge branch 'light_fix' into 'master'

Fix incorrect scene lighting #6952

See merge request OpenMW/openmw!2335

(cherry picked from commit 1d177e2d71)

1f2d9f22 don't recycle statesets for light cullcallback for now
This commit is contained in:
AnyOldName3 2022-08-27 01:03:19 +00:00
parent af14e4d7cd
commit 4bb88a4a75

View file

@ -606,22 +606,22 @@ namespace SceneUtil
if (!lightManager->getUBOManager()) if (!lightManager->getUBOManager())
return; return;
for (size_t i = 0; i < mStateSet.size(); ++i) for (size_t i = 0; i < mUBBs.size(); ++i)
{ {
auto& buffer = lightManager->getUBOManager()->getLightBuffer(i); auto& buffer = lightManager->getUBOManager()->getLightBuffer(i);
osg::ref_ptr<osg::UniformBufferBinding> ubb = new osg::UniformBufferBinding(static_cast<int>(Resource::SceneManager::UBOBinding::LightBuffer), buffer->getData(), 0, buffer->getData()->getTotalDataSize()); mUBBs[i] = new osg::UniformBufferBinding(static_cast<int>(Resource::SceneManager::UBOBinding::LightBuffer), buffer->getData(), 0, buffer->getData()->getTotalDataSize());
mStateSet[i]->setAttributeAndModes(ubb, osg::StateAttribute::ON);
} }
} }
void operator()(LightManager* node, osgUtil::CullVisitor* cv) void operator()(LightManager* node, osgUtil::CullVisitor* cv)
{ {
const size_t frameId = cv->getTraversalNumber() % 2; osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
auto& stateset = mStateSet[frameId];
if (node->getLightingMethod() == LightingMethod::SingleUBO) if (node->getLightingMethod() == LightingMethod::SingleUBO)
{ {
const size_t frameId = cv->getTraversalNumber() % 2;
stateset->setAttributeAndModes(mUBBs[frameId], osg::StateAttribute::ON);
auto& buffer = node->getUBOManager()->getLightBuffer(cv->getTraversalNumber()); auto& buffer = node->getUBOManager()->getLightBuffer(cv->getTraversalNumber());
if (auto sun = node->getSunlight()) if (auto sun = node->getSunlight())
@ -654,7 +654,7 @@ namespace SceneUtil
node->getPPLightsBuffer()->updateCount(cv->getTraversalNumber()); node->getPPLightsBuffer()->updateCount(cv->getTraversalNumber());
} }
std::array<osg::ref_ptr<osg::StateSet>, 2> mStateSet = { new osg::StateSet, new osg::StateSet }; std::array<osg::ref_ptr<osg::UniformBufferBinding>, 2> mUBBs;
}; };
UBOManager::UBOManager(int lightCount) UBOManager::UBOManager(int lightCount)