From 648677ce44345c064640445a2c368952dc443de0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Apr 2005 12:34:28 +0000 Subject: [PATCH] Added next stage of support for osg::Uniform in .osg plugin --- include/osgDB/Input | 1 + include/osgDB/Registry | 2 ++ src/osgDB/Input.cpp | 4 ++++ src/osgDB/Registry.cpp | 27 +++++++++++++++++++++++++++ src/osgPlugins/osg/StateSet.cpp | 19 +++++++++++++++++-- 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/osgDB/Input b/include/osgDB/Input index 3733ced1c..ef2579f6d 100644 --- a/include/osgDB/Input +++ b/include/osgDB/Input @@ -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); diff --git a/include/osgDB/Registry b/include/osgDB/Registry index e1a8cbc86..0abbd06f2 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -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; diff --git a/src/osgDB/Input.cpp b/src/osgDB/Input.cpp index 2b5f6bd7a..0c4f837fb 100644 --- a/src/osgDB/Input.cpp +++ b/src/osgDB/Input.cpp @@ -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() { diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index ac845d131..4c4e0d57d 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -479,6 +479,11 @@ void Registry::addDotOsgWrapper(DotOsgWrapper* wrapper) _stateAttrWrapperMap[name] = wrapper; _stateAttrWrapperMap[compositeName] = wrapper; } + if (dynamic_cast(proto)) + { + _uniformWrapperMap[name] = wrapper; + _uniformWrapperMap[compositeName] = wrapper; + } if (dynamic_cast(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(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(fr.getObjectForUniqueID(fr[1].getStr())); + if (attribute) fr+=2; + return attribute; + } + else return NULL; + + } + + return dynamic_cast(readObject(_uniformWrapperMap,fr)); +} + // // read node from input iterator. // diff --git a/src/osgPlugins/osg/StateSet.cpp b/src/osgPlugins/osg/StateSet.cpp index d3da6fd77..ace2e774a 100644 --- a/src/osgPlugins/osg/StateSet.cpp +++ b/src/osgPlugins/osg/StateSet.cpp @@ -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();