From 541bf02f18ad27e8c8101e4255586ddbfef40916 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 10 May 2011 07:37:55 +0000 Subject: [PATCH] Store uniform information inside Program to reduce glGetUniformLocation calls --- source/program.cpp | 23 ++++++++++++++++++++++- source/program.h | 9 +++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/source/program.cpp b/source/program.cpp index 77fe7e75..1343c00f 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -215,11 +215,28 @@ void Program::link() if(!(*i)->is_compiled()) (*i)->compile(); + uniforms.clear(); + glLinkProgramARB(id); int value; glGetObjectParameterivARB(id, GL_OBJECT_LINK_STATUS_ARB, &value); if(!(linked = value)) throw CompileError(get_info_log()); + + glGetObjectParameterivARB(id, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &value); + for(int i=0; i::const_iterator i = uniforms.find(n); + if(i==uniforms.end()) + return -1; + + return i->second.location; } void Program::unbind() diff --git a/source/program.h b/source/program.h index 4ff3f53a..80ddf15c 100644 --- a/source/program.h +++ b/source/program.h @@ -56,11 +56,20 @@ public: std::string create_flags() const; }; + struct UniformInfo + { + std::string name; + int location; + int size; + GLenum type; + }; + private: unsigned id; std::list shaders; bool del_shaders; bool linked; + std::map uniforms; public: Program(); -- 2.45.2