From cc5e2fb2a0fbb48a9780c9a7c363d1712e459740 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 15 Aug 2012 22:32:28 +0300 Subject: [PATCH] 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. --- source/program.cpp | 12 ++++++++++++ source/program.h | 2 ++ 2 files changed, 14 insertions(+) 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(); -- 2.45.2