From 3f5e469de3454aee1d1923045fc713329a32cc18 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 10 Apr 2021 21:17:00 +0300 Subject: [PATCH] Use the new _member utility functions to search and sort things --- source/core/program.cpp | 33 +++++++++++---------------------- source/core/program.h | 3 --- source/render/programdata.cpp | 12 ++++-------- source/render/programdata.h | 1 - 4 files changed, 15 insertions(+), 34 deletions(-) diff --git a/source/core/program.cpp b/source/core/program.cpp index aa2e7849..5b357f39 100644 --- a/source/core/program.cpp +++ b/source/core/program.cpp @@ -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); + 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 &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::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 &uni = *lower_bound_member(uniforms, Tag(*j), &UniformInfo::tag); block.uniforms.push_back(&uni); uni.block = █ } @@ -632,17 +632,6 @@ bool Program::uniform_location_compare(const UniformInfo *uni1, const UniformInf return uni1->locationlocation; } -bool Program::uniform_tag_compare(const UniformInfo &uni1, const UniformInfo &uni2) -{ - return uni1.tag -bool Program::search(const T &item, const A &key) -{ - return item.*member::const_iterator i = lower_bound(uniforms, Tag(name), &search); + vector::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::const_iterator i = lower_bound(uniforms, tag, &search); + vector::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::const_iterator i = lower_bound(uniforms, Tag(name), &search); + vector::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::const_iterator i = lower_bound(uniforms, tag, &search); + vector::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::const_iterator i = lower_bound(attributes, name, &search); + vector::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::const_iterator i = lower_bound(attributes, name, &search); + vector::const_iterator i = lower_bound_member(attributes, name, &AttributeInfo::name); return i!=attributes.end() && i->name==name ? i->location : -1; } diff --git a/source/core/program.h b/source/core/program.h index 939521dc..377c3eee 100644 --- a/source/core/program.h +++ b/source/core/program.h @@ -162,9 +162,6 @@ private: void update_layout_hash(); static LayoutHash compute_layout_hash(const std::vector &); static bool uniform_location_compare(const UniformInfo *, const UniformInfo *); - static bool uniform_tag_compare(const UniformInfo &, const UniformInfo &); - template - static bool search(const T &, const A &); public: bool is_linked() const { return linked; } DEPRECATED std::string get_info_log() const; diff --git a/source/render/programdata.cpp b/source/render/programdata.cpp index 8adde8a2..272489bb 100644 --- a/source/render/programdata.cpp +++ b/source/render/programdata.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -173,7 +174,7 @@ void ProgramData::add_uniform(Tag tag, Uniform *uni) throw too_many_uniforms(tag.str()); } - vector::iterator j = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare); + vector::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::const_iterator i = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare); + vector::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::const_iterator i = lower_bound(uniforms.begin(), uniforms.end(), tag, uniform_tag_compare); + vector::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag); return ((i!=uniforms.end() && i->tag==tag) ? i-uniforms.begin() : -1); } diff --git a/source/render/programdata.h b/source/render/programdata.h index 0ed16d6f..97f29343 100644 --- a/source/render/programdata.h +++ b/source/render/programdata.h @@ -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; -- 2.43.0