From 072adde9a6fb39a683b3bbe1427d0b49c3519b13 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 23 Feb 2014 14:28:54 -0800 Subject: [PATCH] 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. --- src/Viewer/WindowBuilder.cxx | 3 - src/Viewer/renderer.cxx | 122 +++++++++++++++++------------------ src/Viewer/renderer.hxx | 2 + 3 files changed, 63 insertions(+), 64 deletions(-) diff --git a/src/Viewer/WindowBuilder.cxx b/src/Viewer/WindowBuilder.cxx index d7113d17d..586cdbce0 100644 --- a/src/Viewer/WindowBuilder.cxx +++ b/src/Viewer/WindowBuilder.cxx @@ -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; diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index 944d598b5..9728f0f72 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -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,59 +1392,29 @@ 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 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); 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); - + stateSet->setMode(GL_FOG, osg::StateAttribute::OFF); // this will be set below stateSet->setMode(GL_NORMALIZE, osg::StateAttribute::OFF); - + osg::Material* material = new osg::Material; stateSet->setAttribute(material); stateSet->setTextureAttribute(0, new osg::TexEnv); stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF); - + osg::Hint* hint = new osg::Hint(GL_FOG_HINT, GL_DONT_CARE); hint->setUpdateCallback(new FGHintUpdateCallback("/sim/rendering/fog")); stateSet->setAttribute(hint); @@ -1457,17 +1430,41 @@ 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); +} + +void +FGRenderer::setupView( void ) +{ + osgViewer::Viewer* viewer = globals->get_renderer()->getViewer(); + osg::initNotifyLevel(); - osg::Group* sceneGroup = new osg::Group; - sceneGroup->setName("rendererScene"); - sceneGroup->addChild(globals->get_scenery()->get_scene_graph()); - sceneGroup->setNodeMask(~simgear::BACKGROUND_BIT); - - //sceneGroup->addChild(thesky->getCloudRoot()); - - stateSet = sceneGroup->getOrCreateStateSet(); - stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); + // 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 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); + + // need to update the light on every frame // OSG LightSource objects are rather confusing. OSG only supports // the 10 lights specified by OpenGL itself; if more than one @@ -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 = 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 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(); diff --git a/src/Viewer/renderer.hxx b/src/Viewer/renderer.hxx index 0e9152067..6f5606724 100644 --- a/src/Viewer/renderer.hxx +++ b/src/Viewer/renderer.hxx @@ -184,6 +184,8 @@ protected: void addChangeListener(SGPropertyChangeListener* l, const char* path); void updateSky(); + + void setupRoot(); }; bool fgDumpSceneGraphToFile(const char* filename); -- 2.39.5