forked from mirror/openmw-tes3mp
Refactor LightListCallback to allow for integration in custom Drawables.
This commit is contained in:
parent
ccfebdd2c3
commit
b78a9f89af
2 changed files with 25 additions and 19 deletions
|
@ -381,21 +381,23 @@ namespace SceneUtil
|
||||||
{
|
{
|
||||||
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
|
osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
|
||||||
|
|
||||||
|
bool pushedState = pushLightState(node, cv);
|
||||||
|
traverse(node, nv);
|
||||||
|
if (pushedState)
|
||||||
|
cv->popStateSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LightListCallback::pushLightState(osg::Node *node, osgUtil::CullVisitor *cv)
|
||||||
|
{
|
||||||
if (!mLightManager)
|
if (!mLightManager)
|
||||||
{
|
{
|
||||||
mLightManager = findLightManager(nv->getNodePath());
|
mLightManager = findLightManager(cv->getNodePath());
|
||||||
if (!mLightManager)
|
if (!mLightManager)
|
||||||
{
|
return false;
|
||||||
traverse(node, nv);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cv->getCurrentCamera()->getCullMask() & mLightManager->getLightingMask()))
|
if (!(cv->getCurrentCamera()->getCullMask() & mLightManager->getLightingMask()))
|
||||||
{
|
return false;
|
||||||
traverse(node, nv);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Possible optimizations:
|
// Possible optimizations:
|
||||||
// - cull list of lights by the camera frustum
|
// - cull list of lights by the camera frustum
|
||||||
|
@ -404,9 +406,9 @@ namespace SceneUtil
|
||||||
|
|
||||||
// update light list if necessary
|
// update light list if necessary
|
||||||
// makes sure we don't update it more than once per frame when rendering with multiple cameras
|
// makes sure we don't update it more than once per frame when rendering with multiple cameras
|
||||||
if (mLastFrameNumber != nv->getTraversalNumber())
|
if (mLastFrameNumber != cv->getTraversalNumber())
|
||||||
{
|
{
|
||||||
mLastFrameNumber = nv->getTraversalNumber();
|
mLastFrameNumber = cv->getTraversalNumber();
|
||||||
|
|
||||||
// Don't use Camera::getViewMatrix, that one might be relative to another camera!
|
// Don't use Camera::getViewMatrix, that one might be relative to another camera!
|
||||||
const osg::RefMatrix* viewMatrix = cv->getCurrentRenderStage()->getInitialViewMatrix();
|
const osg::RefMatrix* viewMatrix = cv->getCurrentRenderStage()->getInitialViewMatrix();
|
||||||
|
@ -469,20 +471,16 @@ namespace SceneUtil
|
||||||
while (lightList.size() > maxLights)
|
while (lightList.size() > maxLights)
|
||||||
lightList.pop_back();
|
lightList.pop_back();
|
||||||
}
|
}
|
||||||
stateset = mLightManager->getLightListStateSet(lightList, nv->getTraversalNumber());
|
stateset = mLightManager->getLightListStateSet(lightList, cv->getTraversalNumber());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
stateset = mLightManager->getLightListStateSet(mLightList, nv->getTraversalNumber());
|
stateset = mLightManager->getLightListStateSet(mLightList, cv->getTraversalNumber());
|
||||||
|
|
||||||
|
|
||||||
cv->pushStateSet(stateset);
|
cv->pushStateSet(stateset);
|
||||||
|
return true;
|
||||||
traverse(node, nv);
|
|
||||||
|
|
||||||
cv->popStateSet();
|
|
||||||
}
|
}
|
||||||
else
|
return false;
|
||||||
traverse(node, nv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
#include <osg/NodeVisitor>
|
#include <osg/NodeVisitor>
|
||||||
#include <osg/observer_ptr>
|
#include <osg/observer_ptr>
|
||||||
|
|
||||||
|
namespace osgUtil
|
||||||
|
{
|
||||||
|
class CullVisitor;
|
||||||
|
}
|
||||||
|
|
||||||
namespace SceneUtil
|
namespace SceneUtil
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -148,6 +153,7 @@ namespace SceneUtil
|
||||||
/// rendering when the size of a light list exceeds the OpenGL limit on the number of concurrent lights (8). A good
|
/// rendering when the size of a light list exceeds the OpenGL limit on the number of concurrent lights (8). A good
|
||||||
/// starting point is to attach a LightListCallback to each game object's base node.
|
/// starting point is to attach a LightListCallback to each game object's base node.
|
||||||
/// @note Not thread safe for CullThreadPerCamera threading mode.
|
/// @note Not thread safe for CullThreadPerCamera threading mode.
|
||||||
|
/// @note Due to lack of OSG support, the callback does not work on Drawables.
|
||||||
class LightListCallback : public osg::NodeCallback
|
class LightListCallback : public osg::NodeCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -166,6 +172,8 @@ namespace SceneUtil
|
||||||
|
|
||||||
void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
||||||
|
|
||||||
|
bool pushLightState(osg::Node* node, osgUtil::CullVisitor* nv);
|
||||||
|
|
||||||
std::set<SceneUtil::LightSource*>& getIgnoredLightSources() { return mIgnoredLightSources; }
|
std::set<SceneUtil::LightSource*>& getIgnoredLightSources() { return mIgnoredLightSources; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue