2.8 branch: Uniform lookup by cached name ID. Trunk revisions r11952, r11998, and r12074.
This commit is contained in:
@@ -142,8 +142,9 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
GLenum _type;
|
||||
GLint _size;
|
||||
};
|
||||
typedef std::map< unsigned int, ActiveVarInfo > ActiveUniformMap;
|
||||
typedef std::map< std::string, ActiveVarInfo > ActiveVarInfoMap;
|
||||
const ActiveVarInfoMap& getActiveUniforms(unsigned int contextID) const;
|
||||
const ActiveUniformMap& getActiveUniforms(unsigned int contextID) const;
|
||||
const ActiveVarInfoMap& getActiveAttribs(unsigned int contextID) const;
|
||||
|
||||
public:
|
||||
@@ -184,7 +185,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
|
||||
inline void apply(const Uniform& uniform) const
|
||||
{
|
||||
GLint location = getUniformLocation(uniform.getName());
|
||||
GLint location = getUniformLocation(uniform.getNameID());
|
||||
if (location>=0)
|
||||
{
|
||||
if ((unsigned int)location>=_lastAppliedUniformList.size()) _lastAppliedUniformList.resize(location+1);
|
||||
@@ -206,10 +207,21 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
}
|
||||
}
|
||||
|
||||
const ActiveVarInfoMap& getActiveUniforms() const {return _uniformInfoMap;}
|
||||
const ActiveUniformMap& getActiveUniforms() const {return _uniformInfoMap;}
|
||||
const ActiveVarInfoMap& getActiveAttribs() const {return _attribInfoMap;}
|
||||
|
||||
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 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)
|
||||
@@ -238,7 +250,7 @@ class OSG_EXPORT Program : public osg::StateAttribute
|
||||
bool _isLinked;
|
||||
const unsigned int _contextID;
|
||||
|
||||
ActiveVarInfoMap _uniformInfoMap;
|
||||
ActiveUniformMap _uniformInfoMap;
|
||||
ActiveVarInfoMap _attribInfoMap;
|
||||
|
||||
typedef std::pair<osg::ref_ptr<const osg::Uniform>, unsigned int> UniformModifiedCountPair;
|
||||
|
||||
@@ -975,7 +975,16 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
}
|
||||
inline const Program::PerContextProgram* getLastAppliedProgramObject() const { return _lastAppliedProgramObject; }
|
||||
|
||||
inline GLint getUniformLocation( const std::string& name ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(name) : -1; }
|
||||
inline GLint getUniformLocation( unsigned int uniformNameID ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformNameID) : -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 _lastAppliedProgramObject ? _lastAppliedProgramObject->getUniformLocation(uniformName) : -1; }
|
||||
inline GLint getAttribLocation( const std::string& name ) const { return _lastAppliedProgramObject ? _lastAppliedProgramObject->getAttribLocation(name) : -1; }
|
||||
|
||||
|
||||
|
||||
@@ -259,6 +259,9 @@ class OSG_EXPORT Uniform : public Object
|
||||
/** Return the internal data array type corresponding to a GLSL type */
|
||||
static GLenum getInternalArrayType( Type t );
|
||||
|
||||
/** Return the number that the name maps to uniquely */
|
||||
static unsigned int getNameID(const std::string& name);
|
||||
|
||||
/** convenient scalar (non-array) constructors w/ assignment */
|
||||
explicit Uniform( const char* name, float f );
|
||||
explicit Uniform( const char* name, int i );
|
||||
@@ -463,6 +466,8 @@ class OSG_EXPORT Uniform : public Object
|
||||
inline void setModifiedCount(unsigned int mc) { _modifiedCount = mc; }
|
||||
inline unsigned int getModifiedCount() const { return _modifiedCount; }
|
||||
|
||||
/** Get the number that the Uniform's name maps to uniquely */
|
||||
unsigned int getNameID() const;
|
||||
|
||||
void apply(const GL2Extensions* ext, GLint location) const;
|
||||
|
||||
@@ -484,6 +489,8 @@ class OSG_EXPORT Uniform : public Object
|
||||
|
||||
Type _type;
|
||||
unsigned int _numElements;
|
||||
unsigned int _nameID;
|
||||
|
||||
|
||||
// The internal data for osg::Uniforms are stored as an array of
|
||||
// getInternalArrayType() of length getInternalArrayNumElements().
|
||||
|
||||
Reference in New Issue
Block a user