diff --git a/include/osg/Object b/include/osg/Object index 5f265f9e1..bfd633bd3 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -50,9 +50,9 @@ class OSG_EXPORT Object : public Referenced and therefore cannot be constructed on its own, only derived classes which override the clone and className methods are concrete classes and can be constructed.*/ - inline Object():Referenced(),_dataVariance(DYNAMIC) {} + inline Object():Referenced(),_dataVariance(UNSPECIFIED) {} - inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(DYNAMIC) {} + inline explicit Object(bool threadSafeRefUnref):Referenced(threadSafeRefUnref),_dataVariance(UNSPECIFIED) {} /** Copy constructor, optional CopyOp object can be used to control * shallow vs deep copying of dynamic data.*/ @@ -91,13 +91,15 @@ class OSG_EXPORT Object : public Referenced enum DataVariance { DYNAMIC, - STATIC + STATIC, + UNSPECIFIED }; /** Set the data variance of this object. * Can be set to either STATIC for values that do not change over the lifetime of the object, * or DYNAMIC for values that vary over the lifetime of the object. The DataVariance value - * can be used by routines such as optimzation codes that wish to share static data.*/ + * can be used by routines such as optimzation codes that wish to share static data. + * UNSPECIFIED is used to sepecify that the DataVariance hasn't been set yet. */ inline void setDataVariance(DataVariance dv) { _dataVariance = dv; } /** Get the data variance of this object.*/ diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index f15461291..daa9e424c 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -186,7 +186,7 @@ class OSG_EXPORT StateAttribute : public Object /** Simple pairing between an attribute type and the member within that attribute type group.*/ typedef std::pair TypeMemberPair; - StateAttribute() { setDataVariance(STATIC); } + StateAttribute() {} StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Object(sa,copyop) {} diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 192d6be5e..fd0f62d0f 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -246,8 +246,6 @@ void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*c Drawable::Drawable() { - setDataVariance(osg::Object::STATIC); - _boundingBoxComputed = false; // Note, if your are defining a subclass from drawable which is @@ -296,7 +294,10 @@ Drawable::~Drawable() void Drawable::computeDataVariance() { + if (getDataVariance() != UNSPECIFIED) return; + bool dynamic = false; + if (getUpdateCallback() || getEventCallback() || getCullCallback()) diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index f2369f1ee..c7137b8e8 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -80,8 +80,6 @@ bool osg::isTextureMode(StateAttribute::GLMode mode) StateSet::StateSet() { - setDataVariance(osg::Object::STATIC); - _renderingHint = DEFAULT_BIN; _numChildrenRequiringUpdateTraversal = 0; @@ -180,17 +178,18 @@ void StateSet::computeDataVariance() } // run attribute callbacks + for(AttributeList::iterator itr=_attributeList.begin(); itr!=_attributeList.end(); ++itr) { - if (itr->second.first->getUpdateCallback() || - itr->second.first->getEventCallback() || - itr->second.first->getDataVariance()==DYNAMIC) + if (itr->second.first->getDataVariance()==UNSPECIFIED && + (itr->second.first->getUpdateCallback() || itr->second.first->getEventCallback())) { - dynamic = true; itr->second.first->setDataVariance(DYNAMIC); } + + if (itr->second.first->getDataVariance()==DYNAMIC) dynamic = true; } // run texture attribute callbacks. @@ -201,13 +200,13 @@ void StateSet::computeDataVariance() itr!=attributeList.end(); ++itr) { - if (itr->second.first->getUpdateCallback() || - itr->second.first->getEventCallback() || - itr->second.first->getDataVariance()==DYNAMIC) + if (itr->second.first->getDataVariance()==UNSPECIFIED && + (itr->second.first->getUpdateCallback() || itr->second.first->getEventCallback())) { - itr->second.first->setDataVariance(DYNAMIC); - dynamic = true; + itr->second.first->setDataVariance(DYNAMIC); } + + if (itr->second.first->getDataVariance()==DYNAMIC) dynamic = true; } } @@ -217,16 +216,17 @@ void StateSet::computeDataVariance() uitr != _uniformList.end(); ++uitr) { - if (uitr->second.first->getUpdateCallback() || - uitr->second.first->getEventCallback() || - uitr->second.first->getDataVariance()==DYNAMIC) + if (uitr->second.first->getDataVariance()==UNSPECIFIED && + (uitr->second.first->getUpdateCallback() || uitr->second.first->getEventCallback())) { uitr->second.first->setDataVariance(DYNAMIC); - dynamic = true; } + + if (uitr->second.first->getDataVariance()==DYNAMIC) dynamic = true; } #if 0 + if (dynamic) { osg::notify(osg::NOTICE)<<"StateSet::computeDataVariance setting to DYNAMIC"<writeChar((char)0); break; case(osg::Object::DYNAMIC): out->writeChar((char)1); break; + case(osg::Object::UNSPECIFIED): out->writeChar((char)2); break; } } @@ -55,6 +56,7 @@ void Object::read(DataInputStream* in){ { case 0: setDataVariance(osg::Object::STATIC);break; case 1: setDataVariance(osg::Object::DYNAMIC);break; + case 2: setDataVariance(osg::Object::UNSPECIFIED);break; } } else{ diff --git a/src/osgPlugins/osg/Object.cpp b/src/osgPlugins/osg/Object.cpp index 3caa61d9b..94090e948 100644 --- a/src/osgPlugins/osg/Object.cpp +++ b/src/osgPlugins/osg/Object.cpp @@ -41,6 +41,12 @@ bool Object_readLocalData(Object& obj, Input& fr) fr +=2 ; iteratorAdvanced = true; } + else if (fr[1].matchWord("UNSPECIFIED")) + { + obj.setDataVariance(osg::Object::UNSPECIFIED); + fr +=2 ; + iteratorAdvanced = true; + } } if (fr.matchSequence("name %s")) @@ -74,8 +80,9 @@ bool Object_writeLocalData(const Object& obj, Output& fw) { switch(obj.getDataVariance()) { - case(osg::Object::STATIC): fw.indent() << "DataVariance STATIC" << std::endl;break; - default: fw.indent() << "DataVariance DYNAMIC" << std::endl;break; + case(osg::Object::STATIC): fw.indent() << "DataVariance STATIC" << std::endl;break; + case(osg::Object::UNSPECIFIED): fw.indent() << "DataVariance UNSPECIFIED" << std::endl;break; + default: fw.indent() << "DataVariance DYNAMIC" << std::endl;break; } if (!obj.getName().empty()) fw.indent() << "name "<accept(sodv); + } + if (options & TESSELLATE_GEOMETRY) { osg::notify(osg::INFO)<<"Optimizer::optimize() doing TESSELLATE_GEOMETRY"<accept(sodv); - } - if (osg::getNotifyLevel()>=osg::INFO) { stats.reset(); @@ -789,7 +789,7 @@ class CollectLowestTransformsVisitor : public BaseOptimizerVisitor { if (transform) { - if (transform->getDataVariance()==osg::Transform::DYNAMIC) _moreThanOneMatrixRequired=true; + if (transform->getDataVariance()!=osg::Transform::STATIC) _moreThanOneMatrixRequired=true; else if (transform->getReferenceFrame()!=osg::Transform::RELATIVE_RF) _moreThanOneMatrixRequired=true; else { diff --git a/src/osgWrappers/osg/Object.cpp b/src/osgWrappers/osg/Object.cpp index 099cf0b02..5c41080b2 100644 --- a/src/osgWrappers/osg/Object.cpp +++ b/src/osgWrappers/osg/Object.cpp @@ -26,6 +26,7 @@ BEGIN_ENUM_REFLECTOR(osg::Object::DataVariance) I_EnumLabel(osg::Object::DYNAMIC); I_EnumLabel(osg::Object::STATIC); + I_EnumLabel(osg::Object::UNSPECIFIED); END_REFLECTOR BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Object) @@ -86,7 +87,7 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Object) Properties::NON_VIRTUAL, __void__setDataVariance__DataVariance, "Set the data variance of this object. ", - "Can be set to either STATIC for values that do not change over the lifetime of the object, or DYNAMIC for values that vary over the lifetime of the object. The DataVariance value can be used by routines such as optimzation codes that wish to share static data. "); + "Can be set to either STATIC for values that do not change over the lifetime of the object, or DYNAMIC for values that vary over the lifetime of the object. The DataVariance value can be used by routines such as optimzation codes that wish to share static data. UNSPECIFIED is used to sepecify that the DataVariance hasn't been set yet. "); I_Method0(osg::Object::DataVariance, getDataVariance, Properties::NON_VIRTUAL, __DataVariance__getDataVariance,