From c959bab0a64aa9ad9d85707e204baa45f64a4420 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 12 Dec 2010 09:22:09 +0000 Subject: [PATCH] From Wojciech Lewandowski, "As suggested I have added missing method to PerContextProgram. Tested with our programs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I see that we should expect some performance penalty for using this method. It won’t be painful in my current case because I have only a few animated characters. But I suspect some day I will have to fix osgCal to use int UniformIds natively for larger crowds." --- include/osg/Program | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/osg/Program b/include/osg/Program index b4979f477..75be77a2b 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -238,6 +238,17 @@ class OSG_EXPORT Program : public osg::StateAttribute const ActiveVarInfoMap& getActiveAttribs() const {return _attribInfoMap;} const UniformBlockMap& getUniformBlocks() const {return _uniformBlockMap; } inline GLint getUniformLocation( unsigned int uniformNameID ) const { ActiveUniformMap::const_iterator itr = _uniformInfoMap.find(uniformNameID); return (itr!=_uniformInfoMap.end()) ? itr->second._location : -1; } + + /** + * Alternative version of getUniformLocation( unsigned int uniformNameID ) + * retrofited into OSG for backward compatibility with osgCal, + * after uniform ids were refactored from std::strings to GLints in OSG version 2.9.10. + * + * Drawbacks: This method is not particularly fast. It has to access mutexed static + * map of uniform ids. So don't overuse it or your app performance will suffer. + */ + inline GLint getUniformLocation( const std::string & uniformName ) const { return getUniformLocation( Uniform::getNameID( uniformName ) ); } + inline GLint getAttribLocation( const std::string& name ) const { ActiveVarInfoMap::const_iterator itr = _attribInfoMap.find(name); return (itr!=_attribInfoMap.end()) ? itr->second._location : -1; } inline void addShaderToAttach(Shader *shader)