]> git.tdb.fi Git - libs/gl.git/commitdiff
Use the new _member utility functions to search and sort things
authorMikko Rasa <tdb@tdb.fi>
Sat, 10 Apr 2021 18:17:00 +0000 (21:17 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 10 Apr 2021 18:17:00 +0000 (21:17 +0300)
source/core/program.cpp
source/core/program.h
source/render/programdata.cpp
source/render/programdata.h

index aa2e784939d0345d3e91ef3be842b2d3f781ee64..5b357f3966021dc546807aa99def9a855a9f9a99 100644 (file)
@@ -379,7 +379,7 @@ void Program::query_uniforms()
                }
        }
 
-       sort(uniforms, &uniform_tag_compare);
+       sort_member(uniforms, &UniformInfo::tag);
 
        if(ARB_uniform_buffer_object)
        {
@@ -387,7 +387,7 @@ void Program::query_uniforms()
                for(unsigned i=0; i<count; ++i)
                        if(!uniform_names[i].empty())
                                // The element is already known to be present
-                               uniforms_by_index[i] = &*lower_bound(uniforms, Tag(uniform_names[i]), &search<UniformInfo, Tag, &UniformInfo::tag>);
+                               uniforms_by_index[i] = &*lower_bound_member(uniforms, Tag(uniform_names[i]), &UniformInfo::tag);
                query_uniform_blocks(uniforms_by_index);
        }
 
@@ -470,7 +470,7 @@ void Program::query_uniform_blocks(const vector<UniformInfo *> &uniforms_by_inde
                                uniforms_by_index[query_indices[j]]->matrix_stride = values[j];
                }
 
-               sort(info.uniforms.begin(), info.uniforms.end(), uniform_location_compare);
+               sort(info.uniforms, uniform_location_compare);
                info.layout_hash = compute_layout_hash(info.uniforms);
        }
 }
@@ -539,7 +539,7 @@ void Program::collect_uniforms()
                }
        }
 
-       sort(uniforms, &uniform_tag_compare);
+       sort_member(uniforms, &UniformInfo::tag);
 
        for(unsigned i=0; i<uniform_blocks.size(); ++i)
        {
@@ -548,7 +548,7 @@ void Program::collect_uniforms()
                for(vector<string>::const_iterator j=names.begin(); j!=names.end(); ++j)
                {
                        // The element is already known to be present
-                       UniformInfo &uni = *lower_bound(uniforms, Tag(*j), &search<UniformInfo, Tag, &UniformInfo::tag>);
+                       UniformInfo &uni = *lower_bound_member(uniforms, Tag(*j), &UniformInfo::tag);
                        block.uniforms.push_back(&uni);
                        uni.block = &block;
                }
@@ -632,17 +632,6 @@ bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInf
        return uni1->location<uni2->location;
 }
 
-bool Program::uniform_tag_compare(const UniformInfo &uni1, const UniformInfo &uni2)
-{
-       return uni1.tag<uni2.tag;
-}
-
-template<typename T, typename A, A T::*member>
-bool Program::search(const T &item, const A &key)
-{
-       return item.*member<key;
-}
-
 string Program::get_info_log() const
 {
        GLsizei len = get_program_i(id, GL_INFO_LOG_LENGTH);
@@ -662,7 +651,7 @@ const Program::UniformBlockInfo &Program::get_uniform_block_info(const string &n
 
 const Program::UniformInfo &Program::get_uniform_info(const string &name) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound(uniforms, Tag(name), &search<UniformInfo, Tag, &UniformInfo::tag>);
+       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
        if(i==uniforms.end() || i->name!=name)
                throw key_error(name);
        return *i;
@@ -670,7 +659,7 @@ const Program::UniformInfo &Program::get_uniform_info(const string &name) const
 
 const Program::UniformInfo &Program::get_uniform_info(Tag tag) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound(uniforms, tag, &search<UniformInfo, Tag, &UniformInfo::tag>);
+       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
        if(i==uniforms.end() || i->tag!=tag)
                throw key_error(tag);
        return *i;
@@ -681,19 +670,19 @@ int Program::get_uniform_location(const string &name) const
        if(name[name.size()-1]==']')
                throw invalid_argument("Program::get_uniform_location");
 
-       vector<UniformInfo>::const_iterator i = lower_bound(uniforms, Tag(name), &search<UniformInfo, Tag, &UniformInfo::tag>);
+       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, Tag(name), &UniformInfo::tag);
        return i!=uniforms.end() && i->name==name && i->block->bind_point<0 ? i->location : -1;
 }
 
 int Program::get_uniform_location(Tag tag) const
 {
-       vector<UniformInfo>::const_iterator i = lower_bound(uniforms, tag, &search<UniformInfo, Tag, &UniformInfo::tag>);
+       vector<UniformInfo>::const_iterator i = lower_bound_member(uniforms, tag, &UniformInfo::tag);
        return i!=uniforms.end() && i->tag==tag && i->block->bind_point<0 ? i->location : -1;
 }
 
 const Program::AttributeInfo &Program::get_attribute_info(const string &name) const
 {
-       vector<AttributeInfo>::const_iterator i = lower_bound(attributes, name, &search<AttributeInfo, string, &AttributeInfo::name>);
+       vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
        if(i==attributes.end() || i->name!=name)
                throw key_error(name);
        return *i;
@@ -704,7 +693,7 @@ int Program::get_attribute_location(const string &name) const
        if(name[name.size()-1]==']')
                throw invalid_argument("Program::get_attribute_location");
 
-       vector<AttributeInfo>::const_iterator i = lower_bound(attributes, name, &search<AttributeInfo, string, &AttributeInfo::name>);
+       vector<AttributeInfo>::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name);
        return i!=attributes.end() && i->name==name ? i->location : -1;
 }
 
index 939521dcd804866a65f52d544b6aa722e773c798..377c3eee0f1fcfa3349af8efd4754a0aaa43b042 100644 (file)
@@ -162,9 +162,6 @@ private:
        void update_layout_hash();
        static LayoutHash compute_layout_hash(const std::vector<const UniformInfo *> &);
        static bool uniform_location_compare(const UniformInfo *, const UniformInfo *);
-       static bool uniform_tag_compare(const UniformInfo &, const UniformInfo &);
-       template<typename T, typename A, A T::*>
-       static bool search(const T &, const A &);
 public:
        bool is_linked() const { return linked; }
        DEPRECATED std::string get_info_log() const;
index 8adde8a26f5b71705ea92929d0fc19cee5403907..272489bb585f0d9536dd94653b0b8fb039b42fea 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/debug/demangle.h>
 #include <msp/gl/extensions/arb_direct_state_access.h>
@@ -173,7 +174,7 @@ void ProgramData::add_uniform(Tag tag, Uniform *uni)
                throw too_many_uniforms(tag.str());
        }
 
-       vector<TaggedUniform>::iterator j = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare);
+       vector<TaggedUniform>::iterator j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
 
        TaggedUniform nu;
        nu.tag = tag;
@@ -456,7 +457,7 @@ void ProgramData::uniform_matrix4_array(Tag tag, unsigned n, const float *v)
 
 void ProgramData::remove_uniform(Tag tag)
 {
-       vector<TaggedUniform>::const_iterator i = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare);
+       vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        if(i==uniforms.end() || i->tag!=tag)
                return;
 
@@ -489,14 +490,9 @@ const Uniform *ProgramData::find_uniform(Tag tag) const
        return (i>=0 ? uniforms[i].value : 0);
 }
 
-bool ProgramData::uniform_tag_compare(const TaggedUniform &tu, Tag tag)
-{
-       return tu.tag<tag;
-}
-
 int ProgramData::find_uniform_index(Tag tag) const
 {
-       vector<TaggedUniform>::const_iterator i = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare);
+       vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        return ((i!=uniforms.end() && i->tag==tag) ? i-uniforms.begin() : -1);
 }
 
index 0ed16d6f0d4c2bd7babf08e834e9ee61628e1399..97f293430c1c718e06f594d84ddf0d2de1a84263 100644 (file)
@@ -236,7 +236,6 @@ public:
        const Uniform *find_uniform(Tag) const;
 
 private:
-       static bool uniform_tag_compare(const TaggedUniform &, Tag);
        int find_uniform_index(Tag) const;
        void update_block_uniform_indices(SharedBlock &, const Program::UniformBlockInfo &) const;
        void update_block(SharedBlock &, const Program::UniformBlockInfo &) const;