From: Mikko Rasa Date: Wed, 15 Aug 2012 19:32:28 +0000 (+0300) Subject: Generate a hash describing the layout of uniforms in a Program X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=cc5e2fb2a0fbb48a9780c9a7c363d1712e459740 Generate a hash describing the layout of uniforms in a Program This allows easy recognition of whether two Programs have compatible uniform layouts and could use shared data. --- diff --git a/source/program.cpp b/source/program.cpp index ea1f30d2..587a3fb0 100644 --- a/source/program.cpp +++ b/source/program.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include "arb_shader_objects.h" #include "arb_vertex_shader.h" #include "error.h" @@ -239,6 +241,16 @@ void Program::link() uniforms[name] = info; } } + + string layout_descriptor; + for(map::const_iterator i = uniforms.begin(); i!=uniforms.end(); ++i) + if(i->second.location>=0) + { + if(!layout_descriptor.empty()) + layout_descriptor += '\n'; + layout_descriptor += format("%d:%s:%x", i->second.location, i->second.name, i->second.type); + } + uniform_layout_hash = hash32(layout_descriptor); } string Program::get_info_log() const diff --git a/source/program.h b/source/program.h index b6007073..a1f454e9 100644 --- a/source/program.h +++ b/source/program.h @@ -65,6 +65,7 @@ private: std::list owned_data; bool linked; std::map uniforms; + unsigned uniform_layout_hash; public: Program(); @@ -88,6 +89,7 @@ public: bool is_linked() const { return linked; } std::string get_info_log() const; void bind() const; + unsigned get_uniform_layout_hash() const { return uniform_layout_hash; } int get_uniform_location(const std::string &) const; static void unbind();