1
0
Fork 0

Honor /sim/rendering/shadows/enabled preference

This commit is contained in:
Frederic Bouvier 2012-04-04 20:43:16 +02:00
parent f7174f5422
commit 44de0e1df4
2 changed files with 32 additions and 2 deletions

View file

@ -453,12 +453,20 @@ public:
}
};
class ShadowEnabledListener : public SGPropertyChangeListener {
public:
virtual void valueChanged(SGPropertyNode* node) {
globals->get_renderer()->enableShadows(node->getBoolValue());
}
};
void
FGRenderer::init( void )
{
_classicalRenderer = !fgGetBool("/sim/rendering/rembrandt", false);
_shadowMapSize = fgGetInt( "/sim/rendering/shadows/map-size", 4096 );
fgAddChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
fgAddChangeListener( new ShadowEnabledListener, "/sim/rendering/shadows/enabled" );
_scenery_loaded = fgGetNode("/sim/sceneryloaded", true);
_scenery_override = fgGetNode("/sim/sceneryloaded-override", true);
_panel_hotspots = fgGetNode("/sim/panel-hotspots", true);
@ -817,7 +825,10 @@ osg::Camera* FGRenderer::buildDeferredShadowCamera( flightgear::CameraInfo* info
shadowSwitch->addChild( cascadeCam );
info->shadowTexGen[i] = new osg::TexGen;
}
shadowSwitch->setAllChildrenOn();
if (fgGetBool("/sim/rendering/shadows/enabled", true))
shadowSwitch->setAllChildrenOn();
else
shadowSwitch->setAllChildrenOff();
return mainShadowCamera;
}
@ -858,7 +869,7 @@ void FGRenderer::updateShadowCamera(const flightgear::CameraInfo* info, const os
up.normalize();
dir.normalize();
// cos(100 deg) == -0.17
if (up * dir < -0.17 ) {
if (up * dir < -0.17 || !fgGetBool("/sim/rendering/shadows/enabled", true)) {
shadowSwitch->setAllChildrenOff();
} else {
double left,right,bottom,top,zNear,zFar;
@ -933,6 +944,24 @@ void FGRenderer::updateShadowMapSize(int mapSize)
}
}
void FGRenderer::enableShadows(bool enabled)
{
for ( CameraGroup::CameraIterator ii = CameraGroup::getDefault()->camerasBegin();
ii != CameraGroup::getDefault()->camerasEnd();
++ii )
{
CameraInfo* info = ii->get();
Camera* camera = info->getCamera(SHADOW_CAMERA);
if (camera == 0) continue;
osg::Switch* shadowSwitch = camera->getChild(0)->asSwitch();
if (enabled)
shadowSwitch->setAllChildrenOn();
else
shadowSwitch->setAllChildrenOff();
}
}
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

View file

@ -106,6 +106,7 @@ public:
void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
void updateShadowMapSize(int mapSize);
void enableShadows(bool enabled);
SGSky* getSky() const { return _sky; }