Show
Ignore:
Timestamp:
04/23/09 12:24:27 (4 years ago)
Author:
robert
Message:

Refactored the subsurface PolygonOffset? code so that it uses sensible values and also moves management of the PolygonOffset? and Depth attribute objects into the Document object rather than using static vars.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/GeometryRecords.cpp

    r9041 r10084  
    2424#include <osg/Texture2D> 
    2525#include <osg/CullFace> 
    26 #include <osg/PolygonOffset> 
    27 #include <osg/Depth> 
    2826#include <osg/BlendFunc> 
    2927#include <osgUtil/TransformAttributeFunctor> 
     
    384382        if (document.subfaceLevel() > 0) 
    385383        { 
    386             static osg::ref_ptr<osg::PolygonOffset> polygonOffset = new osg::PolygonOffset(-10.0f, -40.0f); 
    387             stateset->setAttributeAndModes(polygonOffset.get(), osg::StateAttribute::ON); 
    388  
    389             static osg::ref_ptr<osg::Depth> depth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); 
    390             stateset->setAttribute(depth.get()); 
     384            stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON); 
     385            stateset->setAttribute(document.getSubSurfaceDepth()); 
    391386 
    392387            stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin"); 
    393388        } 
    394  
    395 #if 0 
    396 // note from Robert Osfield, this "optimization" breaks multi-textured datasets that mix single texture  
    397 // and mulit-texture geometries as the Multitexture parsing can come after the below code, and accidentally  
    398 // polute the non multi-texture geometries StateSet. 
    399  
    400         // A simple share stateset optimization. 
    401         static osg::ref_ptr<osg::StateSet> lastStateset; 
    402         if (lastStateset.valid() && (stateset->compare(*lastStateset,false)==0)) 
    403             stateset = lastStateset; 
    404         else 
    405             lastStateset = stateset; 
    406 #endif 
    407389 
    408390        _geode->setStateSet(stateset.get()); 
     
    953935        if (document.subfaceLevel() > 0) 
    954936        { 
    955             static osg::ref_ptr<osg::PolygonOffset> polygonOffset = new osg::PolygonOffset(-10.0f, -40.0f); 
    956             stateset->setAttributeAndModes(polygonOffset.get(), osg::StateAttribute::ON); 
    957  
    958             static osg::ref_ptr<osg::Depth> depth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); 
    959             stateset->setAttribute(depth.get()); 
     937            stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON); 
     938            stateset->setAttribute(document.getSubSurfaceDepth()); 
    960939 
    961940            stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin"); 
    962941        } 
    963  
    964 #if 0 
    965 // note from Robert Osfield, this "optimization" breaks multi-textured datasets that mix single texture  
    966 // and mulit-texture geometries as the Multitexture parsing can come after the below code, and accidentally  
    967 // polute the non multi-texture geometries StateSet. 
    968  
    969         // A simple share stateset optimization. 
    970         static osg::ref_ptr<osg::StateSet> lastStateset; 
    971         if (lastStateset.valid() && (stateset->compare(*lastStateset,false)==0)) 
    972             stateset = lastStateset; 
    973         else 
    974             lastStateset = stateset; 
    975 #endif 
    976942 
    977943        _geode->setStateSet(stateset.get());