]> git.tdb.fi Git - libs/gl.git/commitdiff
Store block pointer in uniform info
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 Aug 2012 21:46:24 +0000 (00:46 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 24 Aug 2012 21:46:24 +0000 (00:46 +0300)
It greatly simplifies figuring out which uniforms are not in blocks.

source/program.cpp
source/program.h

index 40a388191e650ef83cb71bc7f3d976027b6b7e80..8892bcf1ed7861b632c7c0bc5089ed53e61b4756 100644 (file)
@@ -251,6 +251,7 @@ void Program::link()
                if(len && strncmp(name, "gl_", 3))
                {
                        UniformInfo &info = uniforms[name];
+                       info.block = 0;
                        info.name = name;
                        info.size = size;
                        info.type = type;
@@ -258,13 +259,10 @@ void Program::link()
                }
        }
 
-       vector<const UniformInfo *> blockless_uniforms;
-
        if(is_supported("GL_ARB_uniform_buffer_object"))
        {
                glGetObjectParameterivARB(id, GL_ACTIVE_UNIFORM_BLOCKS, &value);
                count = value;
-               vector<bool> uniforms_in_blocks(uniforms_by_index.size());
                for(unsigned i=0; i<count; ++i)
                {
                        char name[128];
@@ -284,7 +282,7 @@ void Program::link()
                                if(!uniforms_by_index[*j])
                                        throw logic_error("Program::link");
                                info.uniforms.push_back(uniforms_by_index[*j]);
-                               uniforms_in_blocks[*j] = true;
+                               uniforms_by_index[*j]->block = &info;
                        }
 
                        vector<unsigned> indices2(indices.begin(), indices.end());
@@ -318,23 +316,15 @@ void Program::link()
                        info.bind_point = info.layout_hash%BufferRange::get_n_uniform_buffer_bindings();
                        glUniformBlockBinding(id, i, info.bind_point);
                }
-
-               for(unsigned i=0; i<uniforms_by_index.size(); ++i)
-                       if(uniforms_by_index[i] && !uniforms_in_blocks[i])
-                       {
-                               UniformInfo *info = uniforms_by_index[i];
-                               info->location = glGetUniformLocationARB(id, info->name.c_str());
-                               blockless_uniforms.push_back(info);
-                       }
        }
-       else
-       {
-               for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+
+       vector<const UniformInfo *> blockless_uniforms;
+       for(UniformMap::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
+               if(!i->second.block)
                {
                        i->second.location = glGetUniformLocationARB(id, i->second.name.c_str());
                        blockless_uniforms.push_back(&i->second);
                }
-       }
 
        uniform_layout_hash = compute_layout_hash(blockless_uniforms);
 }
index 40a7a33b143a39aa98f779b6e1d68a8285d54a7c..132c21d5b126ec7d1dc3d2d9bb94ec1814747fb0 100644 (file)
@@ -51,9 +51,12 @@ public:
                std::string create_flags() const;
        };
 
+       struct UniformBlockInfo;
+
        struct UniformInfo
        {
                std::string name;
+               const UniformBlockInfo *block;
                unsigned location;
                unsigned size;
                unsigned array_stride;