diff --git a/include/osg/Program b/include/osg/Program index 8a32ce060..6bed61aec 100644 --- a/include/osg/Program +++ b/include/osg/Program @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2004-2005 Nathan Cournia * @@ -12,7 +12,7 @@ */ /* file: include/osg/Program - * author: Mike Weiblen 2005-07-01 + * author: Mike Weiblen 2006-03-25 */ #ifndef OSG_PROGRAM @@ -109,9 +109,16 @@ class OSG_EXPORT Program : public osg::StateAttribute * in the OpenGL context related to contextID.*/ static void flushDeletedGlPrograms(unsigned int contextID,double currentTime, double& availableTime); - typedef std::map< std::string, std::pair > NameInfoMap; - const NameInfoMap& getActiveUniforms(unsigned int contextID) const; - const NameInfoMap& getActiveAttribs(unsigned int contextID) const; + struct ActiveVarInfo { + ActiveVarInfo() : _location(-1), _type(Uniform::UNDEFINED), _size(-1) {} + ActiveVarInfo( GLint loc, GLenum type, GLint size ) : _location(loc), _type(type), _size(size) {} + GLint _location; + GLenum _type; + GLint _size; + }; + typedef std::map< std::string, ActiveVarInfo > ActiveVarInfoMap; + const ActiveVarInfoMap& getActiveUniforms(unsigned int contextID) const; + const ActiveVarInfoMap& getActiveAttribs(unsigned int contextID) const; public: @@ -175,11 +182,11 @@ class OSG_EXPORT Program : public osg::StateAttribute } } - const NameInfoMap& getActiveUniforms() const {return _uniformInfoMap;} - const NameInfoMap& getActiveAttribs() const {return _attribInfoMap;} + const ActiveVarInfoMap& getActiveUniforms() const {return _uniformInfoMap;} + const ActiveVarInfoMap& getActiveAttribs() const {return _attribInfoMap;} - inline GLint getUniformLocation( const std::string& name ) const { NameInfoMap::const_iterator itr = _uniformInfoMap.find(name); return (itr!=_uniformInfoMap.end()) ? itr->second.first : -1; } - inline GLint getAttribLocation( const std::string& name ) const { NameInfoMap::const_iterator itr = _attribInfoMap.find(name); return (itr!=_attribInfoMap.end()) ? itr->second.first : -1; } + inline GLint getUniformLocation( const std::string& name ) const { ActiveVarInfoMap::const_iterator itr = _uniformInfoMap.find(name); return (itr!=_uniformInfoMap.end()) ? itr->second._location : -1; } + inline GLint getAttribLocation( const std::string& name ) const { ActiveVarInfoMap::const_iterator itr = _attribInfoMap.find(name); return (itr!=_attribInfoMap.end()) ? itr->second._location : -1; } protected: /*methods*/ ~PerContextProgram(); @@ -197,8 +204,8 @@ class OSG_EXPORT Program : public osg::StateAttribute bool _isLinked; const unsigned int _contextID; - NameInfoMap _uniformInfoMap; - NameInfoMap _attribInfoMap; + ActiveVarInfoMap _uniformInfoMap; + ActiveVarInfoMap _attribInfoMap; typedef std::pair UniformModifiedCountPair; typedef std::vector LastAppliedUniformList; diff --git a/include/osg/Uniform b/include/osg/Uniform index 6a52cf82a..0d5401601 100644 --- a/include/osg/Uniform +++ b/include/osg/Uniform @@ -164,7 +164,7 @@ class OSG_EXPORT Uniform : public Object SAMPLER_CUBE = GL_SAMPLER_CUBE, SAMPLER_1D_SHADOW = GL_SAMPLER_1D_SHADOW, SAMPLER_2D_SHADOW = GL_SAMPLER_2D_SHADOW, - UNDEFINED = -1 + UNDEFINED = 0x0 }; public: diff --git a/src/osg/Program.cpp b/src/osg/Program.cpp index 8ab42ad73..1b64c8f50 100644 --- a/src/osg/Program.cpp +++ b/src/osg/Program.cpp @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * Copyright (C) 2003-2005 3Dlabs Inc. Ltd. * Copyright (C) 2004-2005 Nathan Cournia * @@ -13,7 +13,7 @@ */ /* file: src/osg/Program.cpp - * author: Mike Weiblen 2005-07-01 + * author: Mike Weiblen 2006-03-25 */ #include @@ -2131,12 +2131,12 @@ bool Program::getGlProgramInfoLog(unsigned int contextID, std::string& log) cons return getPCP( contextID )->getInfoLog( log ); } -const Program::NameInfoMap& Program::getActiveUniforms(unsigned int contextID) const +const Program::ActiveVarInfoMap& Program::getActiveUniforms(unsigned int contextID) const { return getPCP( contextID )->getActiveUniforms(); } -const Program::NameInfoMap& Program::getActiveAttribs(unsigned int contextID) const +const Program::ActiveVarInfoMap& Program::getActiveAttribs(unsigned int contextID) const { return getPCP( contextID )->getActiveAttribs(); } @@ -2240,11 +2240,12 @@ void Program::PerContextProgram::linkProgram() if( loc != -1 ) { - _uniformInfoMap[name] = std::pair(loc,type); + _uniformInfoMap[name] = ActiveVarInfo(loc,type,size); osg::notify(osg::INFO) << "\tUniform \"" << name << "\"" << " loc="<< loc + << " size="<< size << " type=" << Uniform::getTypename((Uniform::Type)type) << std::endl; } @@ -2271,11 +2272,12 @@ void Program::PerContextProgram::linkProgram() if( loc != -1 ) { - _attribInfoMap[name] = std::pair(loc,type); + _attribInfoMap[name] = ActiveVarInfo(loc,type,size); osg::notify(osg::INFO) << "\tAttrib \"" << name << "\"" << " loc=" << loc + << " size=" << size << std::endl; } }