diff --git a/src/osgPlugins/OpenFlight/Document.cpp b/src/osgPlugins/OpenFlight/Document.cpp index 246177971..dc02d9095 100644 --- a/src/osgPlugins/OpenFlight/Document.cpp +++ b/src/osgPlugins/OpenFlight/Document.cpp @@ -45,6 +45,7 @@ Document::Document() : _lightPointAnimationPoolParent(false), _shaderPoolParent(false) { + _subsurfaceDepth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); } Document::~Document() @@ -110,6 +111,22 @@ osg::Node* Document::getInstanceDefinition(int no) return NULL; } +void Document::setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po) +{ + _subsurfacePolygonOffsets[level] = po; +} + +osg::PolygonOffset* Document::getSubSurfacePolygonOffset(int level) +{ + osg::notify(osg::DEBUG_INFO)<<"Document::getSubSurfacePolygonOffset("<& po = _subsurfacePolygonOffsets[level]; + if (!po) + { + po = new osg::PolygonOffset(-1.0f*float(level), -1.0f); + } + return po.get(); +} + double flt::unitsToMeters(CoordUnits unit) { switch (unit) diff --git a/src/osgPlugins/OpenFlight/Document.h b/src/osgPlugins/OpenFlight/Document.h index 3cb4e9abb..60c963b2d 100644 --- a/src/osgPlugins/OpenFlight/Document.h +++ b/src/osgPlugins/OpenFlight/Document.h @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include "Types.h" @@ -166,6 +168,12 @@ class Document ShaderPool* getOrCreateShaderPool(); bool getShaderPoolParent() const { return _shaderPoolParent; } + void setSubSurfacePolygonOffset(int level, osg::PolygonOffset* po); + osg::PolygonOffset* getSubSurfacePolygonOffset(int level); + + void setSubSurfaceDepth(osg::Depth* depth) { _subsurfaceDepth = depth; } + osg::Depth* getSubSurfaceDepth() { return _subsurfaceDepth.get(); } + // Options void setReplaceClampWithClampToEdge(bool flag) { _replaceClampWithClampToEdge = flag; } @@ -184,7 +192,7 @@ class Document bool getDoUnitsConversion() const { return _doUnitsConversion; } void setDesiredUnits(CoordUnits units ) { _desiredUnits=units; } CoordUnits getDesiredUnits() const { return _desiredUnits; } - + void setKeepExternalReferences( bool flag) { _keepExternalReferences=flag; } bool getKeepExternalReferences() const { return _keepExternalReferences; } @@ -225,6 +233,11 @@ class Document osg::ref_ptr _lightPointAppearancePool; osg::ref_ptr _lightPointAnimationPool; osg::ref_ptr _shaderPool; + + typedef std::map > SubSurfacePolygonOffsets; + SubSurfacePolygonOffsets _subsurfacePolygonOffsets; + osg::ref_ptr _subsurfaceDepth; + bool _colorPoolParent; bool _texturePoolParent; bool _materialPoolParent; diff --git a/src/osgPlugins/OpenFlight/GeometryRecords.cpp b/src/osgPlugins/OpenFlight/GeometryRecords.cpp index 055a15f13..7827769dc 100644 --- a/src/osgPlugins/OpenFlight/GeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/GeometryRecords.cpp @@ -23,8 +23,6 @@ #include #include #include -#include -#include #include #include #include "Registry.h" @@ -383,28 +381,12 @@ protected: // Subface if (document.subfaceLevel() > 0) { - static osg::ref_ptr polygonOffset = new osg::PolygonOffset(-10.0f, -40.0f); - stateset->setAttributeAndModes(polygonOffset.get(), osg::StateAttribute::ON); - - static osg::ref_ptr depth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); - stateset->setAttribute(depth.get()); + stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON); + stateset->setAttribute(document.getSubSurfaceDepth()); stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin"); } -#if 0 -// note from Robert Osfield, this "optimization" breaks multi-textured datasets that mix single texture -// and mulit-texture geometries as the Multitexture parsing can come after the below code, and accidentally -// polute the non multi-texture geometries StateSet. - - // A simple share stateset optimization. - static osg::ref_ptr lastStateset; - if (lastStateset.valid() && (stateset->compare(*lastStateset,false)==0)) - stateset = lastStateset; - else - lastStateset = stateset; -#endif - _geode->setStateSet(stateset.get()); // Add to parent. @@ -952,28 +934,12 @@ protected: // Subface if (document.subfaceLevel() > 0) { - static osg::ref_ptr polygonOffset = new osg::PolygonOffset(-10.0f, -40.0f); - stateset->setAttributeAndModes(polygonOffset.get(), osg::StateAttribute::ON); - - static osg::ref_ptr depth = new osg::Depth(osg::Depth::LESS, 0.0, 1.0,false); - stateset->setAttribute(depth.get()); + stateset->setAttributeAndModes(document.getSubSurfacePolygonOffset(document.subfaceLevel()), osg::StateAttribute::ON); + stateset->setAttribute(document.getSubSurfaceDepth()); stateset->setRenderBinDetails(document.subfaceLevel(),"RenderBin"); } -#if 0 -// note from Robert Osfield, this "optimization" breaks multi-textured datasets that mix single texture -// and mulit-texture geometries as the Multitexture parsing can come after the below code, and accidentally -// polute the non multi-texture geometries StateSet. - - // A simple share stateset optimization. - static osg::ref_ptr lastStateset; - if (lastStateset.valid() && (stateset->compare(*lastStateset,false)==0)) - stateset = lastStateset; - else - lastStateset = stateset; -#endif - _geode->setStateSet(stateset.get()); // Add to parent.