Changeset 10086

Show
Ignore:
Timestamp:
04/23/09 13:08:36 (5 years ago)
Author:
robert
Message:

Fix to handling of subsurface layers so that more appropriate PolygonOffset? values are chosen. Merged from svn/trunk using:

svn merge -r 10083:10084 http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/

Location:
OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight

    • Property svn:mergeinfo set to /OpenSceneGraph/trunk/src/osgPlugins/OpenFlight:10084
  • OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight/Document.cpp

    r8563 r10086  
    4646    _shaderPoolParent(false) 
    4747{ 
     48    _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); 
    4849} 
    4950 
     
    111112} 
    112113 
     114void Document::setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po) 
     115{ 
     116    _subsurfacePolygonOffsets[level] = po; 
     117} 
     118 
     119osg::PolygonOffset* Document::getSubSurfacePolygonOffset(int level) 
     120{ 
     121    osg::notify(osg::DEBUG_INFO)<<"Document::getSubSurfacePolygonOffset("<<level<<")"<<std::endl; 
     122    osg::ref_ptr<osg::PolygonOffset>& po = _subsurfacePolygonOffsets[level]; 
     123    if (!po) 
     124    { 
     125        po = new osg::PolygonOffset(-1.0f*float(level), -1.0f); 
     126    } 
     127    return po.get(); 
     128} 
     129 
    113130double flt::unitsToMeters(CoordUnits unit) 
    114131{ 
  • OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight/Document.h

    r8563 r10086  
    2525#include <osg/Transform> 
    2626#include <osg/Geometry> 
     27#include <osg/PolygonOffset> 
     28#include <osg/Depth> 
    2729#include <osgDB/ReaderWriter> 
    2830 
     
    166168        ShaderPool* getOrCreateShaderPool(); 
    167169        bool getShaderPoolParent() const { return _shaderPoolParent; } 
     170 
     171        void setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po); 
     172        osg::PolygonOffset* getSubSurfacePolygonOffset(int level); 
     173 
     174        void setSubSurfaceDepth(osg::Depth* depth) { _subsurfaceDepth = depth; } 
     175        osg::Depth* getSubSurfaceDepth() { return _subsurfaceDepth.get(); } 
    168176 
    169177 
     
    185193        void setDesiredUnits(CoordUnits units ) { _desiredUnits=units; } 
    186194        CoordUnits getDesiredUnits() const { return _desiredUnits; } 
    187          
     195 
    188196        void setKeepExternalReferences( bool flag) { _keepExternalReferences=flag; } 
    189197        bool getKeepExternalReferences() const { return _keepExternalReferences; } 
     
    226234        osg::ref_ptr<LightPointAnimationPool> _lightPointAnimationPool; 
    227235        osg::ref_ptr<ShaderPool> _shaderPool; 
     236 
     237        typedef std::map<int, osg::ref_ptr<osg::PolygonOffset> > SubSurfacePolygonOffsets; 
     238        SubSurfacePolygonOffsets _subsurfacePolygonOffsets; 
     239        osg::ref_ptr<osg::Depth> _subsurfaceDepth; 
     240 
    228241        bool _colorPoolParent; 
    229242        bool _texturePoolParent; 
  • OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/OpenFlight/GeometryRecords.cpp

    r9041 r10086  
    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());