]> git.tdb.fi Git - libs/gl.git/commitdiff
Deal with hash collisions in assigning uniform block bind points
authorMikko Rasa <tdb@tdb.fi>
Fri, 26 Sep 2014 10:06:52 +0000 (13:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 26 Sep 2014 10:24:21 +0000 (13:24 +0300)
source/program.cpp

index 66ca36b1c5210a3ec0e0e29ff1b61a0336bcbe9e..e16776f8f53f078a2ae53c39b482326a9e8b16cc 100644 (file)
@@ -1,5 +1,6 @@
 #include <algorithm>
 #include <cstring>
+#include <set>
 #include <msp/core/hash.h>
 #include <msp/core/maputils.h>
 #include <msp/gl/extensions/arb_shader_objects.h>
@@ -156,6 +157,7 @@ void Program::link()
 
        if(ARB_uniform_buffer_object)
        {
+               std::set<unsigned> used_bind_points;
                count = get_program_i(id, GL_ACTIVE_UNIFORM_BLOCKS);
                for(unsigned i=0; i<count; ++i)
                {
@@ -215,8 +217,12 @@ void Program::link()
 
                        sort(info.uniforms.begin(), info.uniforms.end(), uniform_location_compare);
                        info.layout_hash = compute_layout_hash(info.uniforms);
-                       info.bind_point = info.layout_hash%BufferRange::get_n_uniform_buffer_bindings();
+                       unsigned n_bindings = BufferRange::get_n_uniform_buffer_bindings();
+                       info.bind_point = info.layout_hash%n_bindings;
+                       while(used_bind_points.count(info.bind_point))
+                               info.bind_point = (info.bind_point+1)%n_bindings;
                        glUniformBlockBinding(id, i, info.bind_point);
+                       used_bind_points.insert(info.bind_point);
                }
        }