From 6e780bfa6201f12ac08255bd73e5ae7b8622bee2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 8 Apr 2009 12:32:52 +0000 Subject: [PATCH] From Simon Carmody, "Patches for compare and copy of Programs and related state -Added copying of shaders and attributes in osg::Program copy constructor. -Changed StateSet::compare function to compare Uniforms and their override values. Previously it compared a RefUniformPair." --- src/osg/Program.cpp | 18 +++++++++++++++++- src/osg/StateSet.cpp | 6 ++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index fa95bf15b..0bf89d02c 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -105,7 +105,23 @@ Program::Program() : Program::Program(const Program& rhs, const osg::CopyOp& copyop): osg::StateAttribute(rhs, copyop) { - osg::notify(osg::FATAL) << "how got here?" << std::endl; + for( unsigned int shaderIndex=0; shaderIndex < rhs.getNumShaders(); ++shaderIndex ) + { + addShader( new osg::Shader( *rhs.getShader( shaderIndex ), copyop ) ); + } + + const osg::Program::AttribBindingList &abl = rhs.getAttribBindingList(); + for( osg::Program::AttribBindingList::const_iterator attribute = abl.begin(); attribute != abl.end(); ++attribute ) + { + addBindAttribLocation( attribute->first, attribute->second ); + } + + const osg::Program::FragDataBindingList &fdl = rhs.getFragDataBindingList(); + for( osg::Program::FragDataBindingList::const_iterator fragdata = fdl.begin(); fragdata != fdl.end(); ++fragdata ) + { + addBindFragDataLocation( fragdata->first, fragdata->second ); + } + _geometryVerticesOut = rhs._geometryVerticesOut; _geometryInputType = rhs._geometryInputType; _geometryOutputType = rhs._geometryOutputType; diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 466506fab..2fcaa2dce 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -425,8 +425,10 @@ int StateSet::compare(const StateSet& rhs,bool compareAttributeContents) const { if (lhs_uniform_itr->firstfirst) return -1; else if (rhs_uniform_itr->firstfirst) return 1; - if (lhs_uniform_itr->secondsecond) return -1; - else if (rhs_uniform_itr->secondsecond) return 1; + if (*lhs_uniform_itr->second.first<*rhs_uniform_itr->second.first) return -1; + else if (*rhs_uniform_itr->second.first<*lhs_uniform_itr->second.first) return 1; + if (lhs_uniform_itr->second.secondsecond.second) return -1; + else if (rhs_uniform_itr->second.secondsecond.second) return 1; ++lhs_uniform_itr; ++rhs_uniform_itr; }