Commit c283639f authored by Philip Trettner's avatar Philip Trettner

Added transparent uniform location cache for shaders.

parent 2f7dca91
......@@ -119,7 +119,13 @@ public:
// ===================================================================================================== \/
public:
//////////// uniform (block) locations:
inline GLint getUniformLocation (const std::string& _nameInShader) const { return glGetUniformLocation (mObjectName, _nameInShader.c_str()); }
inline GLint getUniformLocation(const std::string& _nameInShader) const
{
// Cache uniform location
if ( !mUniformLocationCache.count(_nameInShader) )
mUniformLocationCache[_nameInShader] = glGetUniformLocation(mObjectName, _nameInShader.c_str());
return mUniformLocationCache[_nameInShader];
}
#if (ACGL_OPENGL_VERSION >= 31)
//! if the block name does not exist, GL_INVALID_INDEX will get returned
......@@ -363,6 +369,9 @@ public:
protected:
GLuint mObjectName;
ConstSharedShaderVec mShaders;
/// Cache for uniform locations
mutable std::map<std::string, int> mUniformLocationCache;
};
ACGL_SMARTPOINTER_TYPEDEFS(ShaderProgram)
......
......@@ -15,6 +15,9 @@ using namespace ACGL::Utils;
bool ShaderProgram::link() const
{
// Clear uniform cache
mUniformLocationCache.clear();
glLinkProgram(mObjectName);
// check for program link errors:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment