Introduced new osg::Object::DataVariance type of UNSPECIFIED, and changed the deafult

values of DataVariance to UNSPECIFIED to all types.
This commit is contained in:
Robert Osfield
2007-02-14 13:18:58 +00:00
parent 953899d0e2
commit 07411f3246
9 changed files with 49 additions and 35 deletions

View File

@@ -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.*/

View File

@@ -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<Type,unsigned int> TypeMemberPair;
StateAttribute() { setDataVariance(STATIC); }
StateAttribute() {}
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(sa,copyop) {}

View File

@@ -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())

View File

@@ -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"<<std::endl;
@@ -237,7 +237,10 @@ void StateSet::computeDataVariance()
}
#endif
setDataVariance(dynamic ? DYNAMIC : STATIC);
if (getDataVariance()==UNSPECIFIED)
{
setDataVariance(dynamic ? DYNAMIC : STATIC);
}
}

View File

@@ -30,7 +30,6 @@ using namespace osg;
Uniform::Uniform() :
_type(UNDEFINED), _numElements(0), _modifiedCount(0)
{
setDataVariance(STATIC);
}
@@ -39,7 +38,6 @@ Uniform::Uniform( Type type, const std::string& name, int numElements ) :
{
setName(name);
setNumElements(numElements);
setDataVariance(STATIC);
allocateDataArray();
}

View File

@@ -33,6 +33,7 @@ void Object::write(DataOutputStream* out)
{
case(osg::Object::STATIC): out->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{

View File

@@ -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 "<<fw.wrapString(obj.getName())<< std::endl;

View File

@@ -134,6 +134,12 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
stats.print(osg::notify(osg::NOTICE));
}
if (options & STATIC_OBJECT_DETECTION)
{
StaticObjectDetectionVisitor sodv;
node->accept(sodv);
}
if (options & TESSELLATE_GEOMETRY)
{
osg::notify(osg::INFO)<<"Optimizer::optimize() doing TESSELLATE_GEOMETRY"<<std::endl;
@@ -303,12 +309,6 @@ void Optimizer::optimize(osg::Node* node, unsigned int options)
sv.divide();
}
if (options & STATIC_OBJECT_DETECTION)
{
StaticObjectDetectionVisitor sodv;
node->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
{

View File

@@ -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,