]> git.tdb.fi Git - libs/gl.git/commitdiff
Generate a hash describing the layout of uniforms in a Program
authorMikko Rasa <tdb@tdb.fi>
Wed, 15 Aug 2012 19:32:28 +0000 (22:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 15 Aug 2012 19:32:28 +0000 (22:32 +0300)
This allows easy recognition of whether two Programs have compatible
uniform layouts and could use shared data.

source/program.cpp
source/program.h

index ea1f30d2aea724cc9e9b10e2bcdf531accc48bb7..587a3fb0fa674c6c2a85689c4abee6a05d7bf2d2 100644 (file)
@@ -1,4 +1,6 @@
 #include <algorithm>
+#include <msp/core/hash.h>
+#include <msp/strings/format.h>
 #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<string, UniformInfo>::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
index b6007073bedd91c706f0d4a8c84706743f1ba904..a1f454e9453272cf14b84a29ce60bc8c6a765b60 100644 (file)
@@ -65,6 +65,7 @@ private:
        std::list<Shader *> owned_data;
        bool linked;
        std::map<std::string, UniformInfo> 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();