1
0
Fork 0

Remove all references to an alpha-buffer

- Current 3D clouds rendering does not use the alpha buffer,
so don't request one at launch, since it consumes valuable GPU memory.

- Remove any references to alpha testing or alpha func in the renderer setup.
This commit is contained in:
James Turner 2014-02-23 14:28:54 -08:00
parent a6219dab76
commit 072adde9a6
3 changed files with 67 additions and 68 deletions

View file

@ -65,13 +65,10 @@ WindowBuilder::makeDefaultTraits(bool stencil)
traits->screenNum = 0;
int bpp = fgGetInt("/sim/rendering/bits-per-pixel");
bool alpha = fgGetBool("/sim/rendering/clouds3d-enable");
int cbits = (bpp <= 16) ? 5 : 8;
int zbits = (bpp <= 16) ? 16 : 24;
traits->red = traits->green = traits->blue = cbits;
traits->depth = zbits;
if (alpha)
traits->alpha = 8;
if (stencil)
traits->stencil = 8;

View file

@ -401,7 +401,10 @@ FGRenderer::FGRenderer() :
_root->setName("fakeRoot");
_updateVisitor = new SGUpdateVisitor;
_root = new osg::Group;
// when Rembrandt is enabled, we use this group to access the whole
// scene. Since the only child is the _viewerSceneRoot, we could
// simply copy the reference, we don't need the additional group.
_deferredRealRoot = new osg::Group;
_numCascades = 4;
@ -1389,36 +1392,8 @@ CameraInfo* FGRenderer::buildCameraFromRenderingPipeline(FGRenderingPipeline* rp
return info;
}
void
FGRenderer::setupView( void )
void FGRenderer::setupRoot()
{
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
osg::initNotifyLevel();
// The number of polygon-offset "units" to place between layers. In
// principle, one is supposed to be enough. In practice, I find that
// my hardware/driver requires many more.
osg::PolygonOffset::setUnitsMultiplier(1);
osg::PolygonOffset::setFactorMultiplier(1);
// build the sky
// The sun and moon diameters are scaled down numbers of the
// actual diameters. This was needed to fit both the sun and the
// moon within the distance to the far clip plane.
// Moon diameter: 3,476 kilometers
// Sun diameter: 1,390,000 kilometers
osg::ref_ptr<SGReaderWriterOptions> opt;
opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
opt->setPropertyNode(globals->get_props());
_sky->build( 80000.0, 80000.0,
463.3, 361.8,
*globals->get_ephem(),
fgGetNode("/environment", true),
opt.get());
viewer->getCamera()
->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
osg::StateSet* stateSet = _root->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
@ -1426,8 +1401,6 @@ FGRenderer::setupView( void )
stateSet->setAttribute(new osg::Depth(osg::Depth::LESS));
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
stateSet->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.01));
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
stateSet->setAttribute(new osg::BlendFunc);
stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF);
@ -1457,16 +1430,40 @@ FGRenderer::setupView( void )
hint = new osg::Hint(GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);
hint->setUpdateCallback(new FGHintUpdateCallback("/sim/rendering/perspective-correction"));
stateSet->setAttribute(hint);
}
osg::Group* sceneGroup = new osg::Group;
sceneGroup->setName("rendererScene");
sceneGroup->addChild(globals->get_scenery()->get_scene_graph());
sceneGroup->setNodeMask(~simgear::BACKGROUND_BIT);
void
FGRenderer::setupView( void )
{
osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
osg::initNotifyLevel();
//sceneGroup->addChild(thesky->getCloudRoot());
// The number of polygon-offset "units" to place between layers. In
// principle, one is supposed to be enough. In practice, I find that
// my hardware/driver requires many more.
osg::PolygonOffset::setUnitsMultiplier(1);
osg::PolygonOffset::setFactorMultiplier(1);
setupRoot();
// build the sky
// The sun and moon diameters are scaled down numbers of the
// actual diameters. This was needed to fit both the sun and the
// moon within the distance to the far clip plane.
// Moon diameter: 3,476 kilometers
// Sun diameter: 1,390,000 kilometers
osg::ref_ptr<SGReaderWriterOptions> opt;
opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
opt->setPropertyNode(globals->get_props());
_sky->build( 80000.0, 80000.0,
463.3, 361.8,
*globals->get_ephem(),
fgGetNode("/environment", true),
opt.get());
viewer->getCamera()
->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
stateSet = sceneGroup->getOrCreateStateSet();
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
// need to update the light on every frame
// OSG LightSource objects are rather confusing. OSG only supports
@ -1478,7 +1475,7 @@ FGRenderer::setupView( void )
// has the corresponding OpenGL light enabled: a LightSource will
// affect geometry anywhere in the scene graph that has its light
// number enabled in a state set.
LightSource* lightSource = new LightSource;
osg::ref_ptr<LightSource> lightSource = new LightSource;
lightSource->setName("FGLightSource");
lightSource->getLight()->setDataVariance(Object::DYNAMIC);
// relative because of CameraView being just a clever transform node
@ -1488,7 +1485,7 @@ FGRenderer::setupView( void )
_viewerSceneRoot->addChild(lightSource);
// we need a white diffuse light for the phase of the moon
osg::LightSource* sunLight = new osg::LightSource;
osg::ref_ptr<LightSource> sunLight = new osg::LightSource;
sunLight->setName("sunLightSource");
sunLight->getLight()->setDataVariance(Object::DYNAMIC);
sunLight->getLight()->setLightNum(1);
@ -1498,20 +1495,22 @@ FGRenderer::setupView( void )
// Hang a StateSet above the sky subgraph in order to turn off
// light 0
Group* skyGroup = new Group;
skyGroup->setName("rendererSkyParent");
Group* skyGroup = _sky->getPreRoot();
StateSet* skySS = skyGroup->getOrCreateStateSet();
skySS->setMode(GL_LIGHT0, StateAttribute::OFF);
skyGroup->addChild(_sky->getPreRoot());
sunLight->addChild(skyGroup);
_root->addChild(sceneGroup);
if ( _classicalRenderer )
if ( _classicalRenderer ) {
_root->addChild(sunLight);
}
// Clouds are added to the scene graph later
stateSet = globals->get_scenery()->get_scene_graph()->getOrCreateStateSet();
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
osg::Group* sceneGroup = globals->get_scenery()->get_scene_graph();
sceneGroup->setName("rendererScene");
sceneGroup->setNodeMask(~simgear::BACKGROUND_BIT);
_root->addChild(sceneGroup);
// setup state-set for main scenery (including models and aircraft)
osg::StateSet* stateSet = sceneGroup->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
@ -1553,10 +1552,11 @@ FGRenderer::setupView( void )
// The clouds are attached directly to the scene graph root
// because, in theory, they don't want the same default state set
// as the rest of the scene. This may not be true in practice.
if ( _classicalRenderer ) {
_viewerSceneRoot->addChild(_sky->getCloudRoot());
_viewerSceneRoot->addChild(FGCreateRedoutNode());
}
if ( _classicalRenderer ) {
_viewerSceneRoot->addChild(_sky->getCloudRoot());
_viewerSceneRoot->addChild(FGCreateRedoutNode());
}
// Attach empty program to the scene root so that shader programs
// don't leak into state sets (effects) that shouldn't have one.
stateSet = _viewerSceneRoot->getOrCreateStateSet();

View file

@ -184,6 +184,8 @@ protected:
void addChangeListener(SGPropertyChangeListener* l, const char* path);
void updateSky();
void setupRoot();
};
bool fgDumpSceneGraphToFile(const char* filename);