Added next stage of support for osg::Uniform in .osg plugin

This commit is contained in:
Robert Osfield 2005-04-18 12:34:28 +00:00
parent 0a995f8093
commit 648677ce44
5 changed files with 51 additions and 2 deletions

View File

@ -47,6 +47,7 @@ class OSGDB_EXPORT Input : public FieldReaderIterator
virtual osg::Image* readImage();
virtual osg::Drawable* readDrawable();
virtual osg::StateAttribute* readStateAttribute();
virtual osg::Uniform* readUniform();
virtual osg::Node* readNode();
virtual osg::Object* readObject(const std::string& fileName);

View File

@ -111,6 +111,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
osg::Object* readObject(Input& fr);
osg::Image* readImage(Input& fr);
osg::Drawable* readDrawable(Input& fr);
osg::Uniform* readUniform(Input& fr);
osg::StateAttribute* readStateAttribute(Input& fr);
osg::Node* readNode(Input& fr);
@ -449,6 +450,7 @@ class OSGDB_EXPORT Registry : public osg::Referenced
DotOsgWrapperMap _imageWrapperMap;
DotOsgWrapperMap _drawableWrapperMap;
DotOsgWrapperMap _stateAttrWrapperMap;
DotOsgWrapperMap _uniformWrapperMap;
DotOsgWrapperMap _nodeWrapperMap;
DotOsgWrapperMap _classNameWrapperMap;

View File

@ -72,6 +72,10 @@ osg::StateAttribute* Input::readStateAttribute()
{
return Registry::instance()->readStateAttribute(*this);
}
osg::Uniform* Input::readUniform()
{
return Registry::instance()->readUniform(*this);
}
osg::Node* Input::readNode()
{

View File

@ -479,6 +479,11 @@ void Registry::addDotOsgWrapper(DotOsgWrapper* wrapper)
_stateAttrWrapperMap[name] = wrapper;
_stateAttrWrapperMap[compositeName] = wrapper;
}
if (dynamic_cast<const Uniform*>(proto))
{
_uniformWrapperMap[name] = wrapper;
_uniformWrapperMap[compositeName] = wrapper;
}
if (dynamic_cast<const Node*>(proto))
{
_nodeWrapperMap[name] = wrapper;
@ -518,6 +523,7 @@ void Registry::removeDotOsgWrapper(DotOsgWrapper* wrapper)
eraseWrapper(_classNameWrapperMap,wrapper);
eraseWrapper(_imageWrapperMap,wrapper);
eraseWrapper(_drawableWrapperMap,wrapper);
eraseWrapper(_uniformWrapperMap,wrapper);
eraseWrapper(_stateAttrWrapperMap,wrapper);
eraseWrapper(_nodeWrapperMap,wrapper);
}
@ -1075,6 +1081,27 @@ StateAttribute* Registry::readStateAttribute(Input& fr)
return dynamic_cast<StateAttribute*>(readObject(_stateAttrWrapperMap,fr));
}
//
// read drawable from input iterator.
//
Uniform* Registry::readUniform(Input& fr)
{
if (fr[0].matchWord("Use"))
{
if (fr[1].isString())
{
Uniform* attribute = dynamic_cast<Uniform*>(fr.getObjectForUniqueID(fr[1].getStr()));
if (attribute) fr+=2;
return attribute;
}
else return NULL;
}
return dynamic_cast<Uniform*>(readObject(_uniformWrapperMap,fr));
}
//
// read node from input iterator.
//

View File

@ -385,6 +385,13 @@ bool StateSet_readLocalData(Object& obj, Input& fr)
}
}
// new code using osg::Registry's list of prototypes to loaded attributes.
Uniform* uniform = NULL;
while((uniform=fr.readUniform())!=NULL)
{
stateset.addUniform(uniform);
iteratorAdvanced = true;
}
// new code using osg::Registry's list of prototypes to loaded attributes.
@ -515,8 +522,6 @@ bool StateSet_writeLocalData(const Object& obj, Output& fw)
const StateSet::ModeList& ml = stateset.getModeList();
const StateSet::AttributeList& sl = stateset.getAttributeList();
for(StateSet::ModeList::const_iterator mitr=ml.begin();
mitr!=ml.end();
++mitr)
@ -533,12 +538,22 @@ bool StateSet_writeLocalData(const Object& obj, Output& fw)
}
}
const StateSet::UniformList& ul = stateset.getUniformList();
for(StateSet::UniformList::const_iterator uitr=ul.begin();
uitr!=ul.end();
++uitr)
{
fw.writeObject(*(uitr->second.first));
}
const StateSet::AttributeList& sl = stateset.getAttributeList();
for(StateSet::AttributeList::const_iterator sitr=sl.begin();
sitr!=sl.end();
++sitr)
{
fw.writeObject(*(sitr->second.first));
}
const StateSet::TextureModeList& tml = stateset.getTextureModeList();
const StateSet::TextureAttributeList& tal = stateset.getTextureAttributeList();