]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/programdata.cpp
Use C++11 features with containers
[libs/gl.git] / source / render / programdata.cpp
index 79b559019d116b196502267222e5c37e6985642d..e8e30e6344c8d4ca6c982027bab6f73195376bfd 100644 (file)
@@ -36,8 +36,8 @@ ProgramData::ProgramData(const ProgramData &other):
        buffer(0),
        dirty(0)
 {
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 }
 
 ProgramData::ProgramData(const ProgramData &other, const Program *p):
@@ -48,13 +48,13 @@ ProgramData::ProgramData(const ProgramData &other, const Program *p):
 {
        if(tied_program)
        {
-               for(vector<TaggedUniform>::const_iterator i=other.uniforms.begin(); i!=other.uniforms.end(); ++i)
-                       validate_tag(i->tag);
+               for(const TaggedUniform &u: other.uniforms)
+                       validate_tag(u.tag);
        }
 
        uniforms = other.uniforms;
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 }
 
 ProgramData &ProgramData::operator=(const ProgramData &other)
@@ -62,11 +62,11 @@ ProgramData &ProgramData::operator=(const ProgramData &other)
        tied_program = other.tied_program;
 
        uniforms = other.uniforms;
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               i->value = i->value->clone();
+       for(TaggedUniform &u: uniforms)
+               u.value = u.value->clone();
 
-       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
-               delete i->block;
+       for(SharedBlock &b: blocks)
+               delete b.block;
        programs.clear();
 
        last_buffer_block = 0;
@@ -78,13 +78,13 @@ ProgramData &ProgramData::operator=(const ProgramData &other)
 
 ProgramData::~ProgramData()
 {
-       for(vector<TaggedUniform>::iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               delete i->value;
-       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
+       for(TaggedUniform &u: uniforms)
+               delete u.value;
+       for(SharedBlock &b: blocks)
        {
-               if(i->indices.type_flag==0xFE)
-                       delete[] i->indices.dynamic.values;
-               delete i->block;
+               if(b.indices.type_flag==0xFE)
+                       delete[] b.indices.dynamic.values;
+               delete b.block;
        }
        delete buffer;
 }
@@ -181,7 +181,7 @@ void ProgramData::add_uniform(Tag tag, Uniform *uni)
                throw too_many_uniforms(tag.str());
        }
 
-       vector<TaggedUniform>::iterator j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
+       auto j = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
 
        TaggedUniform nu;
        nu.tag = tag;
@@ -431,7 +431,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_member(uniforms, tag, &TaggedUniform::tag);
+       auto i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        if(i==uniforms.end() || i->tag!=tag)
                return;
 
@@ -445,8 +445,8 @@ vector<Tag> ProgramData::get_uniform_tags() const
 {
        vector<Tag> tags;
        tags.reserve(uniforms.size());
-       for(vector<TaggedUniform>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               tags.push_back(i->tag);
+       for(const TaggedUniform &u: uniforms)
+               tags.push_back(u.tag);
        return tags;
 }
 
@@ -466,14 +466,14 @@ const Uniform *ProgramData::find_uniform(Tag tag) const
 
 int ProgramData::find_uniform_index(Tag tag) const
 {
-       vector<TaggedUniform>::const_iterator i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
+       auto i = lower_bound_member(uniforms, tag, &TaggedUniform::tag);
        return ((i!=uniforms.end() && i->tag==tag) ? i-uniforms.begin() : -1);
 }
 
 vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Program &prog) const
 {
        Program::LayoutHash prog_hash = prog.get_uniform_layout_hash();
-       vector<ProgramBlock>::iterator i = lower_bound_member(programs, prog_hash, &ProgramBlock::prog_hash);
+       auto i = lower_bound_member(programs, prog_hash, &ProgramBlock::prog_hash);
        if(i!=programs.end() && i->prog_hash==prog_hash)
                return i;
 
@@ -485,8 +485,8 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
        the hashes so they can be matched up later. */
        vector<Program::LayoutHash> block_hashes;
        block_hashes.reserve(programs.size());
-       for(vector<ProgramBlock>::iterator j=programs.begin(); j!=programs.end(); ++j)
-               block_hashes.push_back(j->block_index>=0 ? blocks[j->block_index].block_hash : 0);
+       for(const ProgramBlock &b: programs)
+               block_hashes.push_back(b.block_index>=0 ? blocks[b.block_index].block_hash : 0);
 
        for(unsigned j=0; j<block_infos.size(); ++j)
        {
@@ -494,7 +494,7 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
                block_hashes[index+1+j] = info.layout_hash;
                programs[index+1+j].bind_point = info.bind_point;
 
-               vector<SharedBlock>::iterator k = lower_bound_member(blocks, info.layout_hash, &SharedBlock::block_hash);
+               auto k = lower_bound_member(blocks, info.layout_hash, &SharedBlock::block_hash);
                if(k==blocks.end() || k->block_hash!=info.layout_hash)
                {
                        k = blocks.insert(k, SharedBlock(info.layout_hash));
@@ -508,7 +508,7 @@ vector<ProgramData::ProgramBlock>::iterator ProgramData::get_program(const Progr
                unsigned hash = block_hashes[j];
                if(hash)
                {
-                       vector<SharedBlock>::const_iterator k = lower_bound_member(blocks, hash, &SharedBlock::block_hash);
+                       auto k = lower_bound_member(blocks, hash, &SharedBlock::block_hash);
                        programs[j].block_index = k-blocks.begin();
                }
                else
@@ -600,7 +600,7 @@ void ProgramData::update_block(SharedBlock &block, const Program::UniformBlockIn
 vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(const Program &prog) const
 {
        BufferBackedUniformBlock *old_last_block = last_buffer_block;
-       vector<ProgramBlock>::iterator prog_begin = get_program(prog);
+       auto prog_begin = get_program(prog);
 
        Mask force_dirty = (dirty==ALL_ONES ? ALL_ONES : 0U);
        Mask affected = (dirty&prog_begin->masks.used) | force_dirty;
@@ -611,11 +611,11 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
                program will cause this to happen if there's any dirty uniforms. */
                if(affected)
                {
-                       for(vector<SharedBlock>::iterator i=blocks.begin(); i!=blocks.end(); ++i)
-                               i->dirty |= (dirty&i->used) | force_dirty;
-                       for(vector<ProgramBlock>::iterator i=programs.begin(); i!=programs.end(); ++i)
-                               if(i->block_index<0)
-                                       i->masks.dirty |= (dirty&i->masks.used) | force_dirty;
+                       for(SharedBlock &b: blocks)
+                               b.dirty |= (dirty&b.used) | force_dirty;
+                       for(ProgramBlock &b: programs)
+                               if(b.block_index<0)
+                                       b.masks.dirty |= (dirty&b.masks.used) | force_dirty;
                        dirty = 0;
                }
 
@@ -626,29 +626,31 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
                        /* The set of uniforms has changed since this program was last used.
                        Refresh uniform indices within the program's blocks. */
                        prog_begin->masks.used = 0;
-                       vector<ProgramBlock>::iterator j = prog_begin+1;
-                       for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
+                       auto j = prog_begin+1;
+                       for(const Program::UniformBlockInfo &b: block_infos)
                        {
                                SharedBlock &shared = blocks[j->block_index];
                                if(shared.dirty==ALL_ONES)
-                                       update_block_uniform_indices(shared, *i);
+                                       update_block_uniform_indices(shared, b);
                                prog_begin->masks.used |= shared.used;
                                j->block = (shared.used ? shared.block : 0);
+                               ++j;
                        }
                }
 
                // Update the contents of all dirty blocks.
                bool buffered_blocks_updated = false;
-               vector<ProgramBlock>::iterator j = prog_begin+1;
-               for(vector<Program::UniformBlockInfo>::const_iterator i=block_infos.begin(); i!=block_infos.end(); ++i, ++j)
+               auto j = prog_begin+1;
+               for(const Program::UniformBlockInfo &b: block_infos)
                {
                        SharedBlock &shared = blocks[j->block_index];
                        if(shared.dirty)
                        {
-                               update_block(shared, *i);
+                               update_block(shared, b);
                                shared.dirty = 0;
                                buffered_blocks_updated |= (j->bind_point>=0);
                        }
+                       ++j;
                }
 
                prog_begin->masks.dirty = 0;
@@ -680,9 +682,9 @@ vector<ProgramData::ProgramBlock>::const_iterator ProgramData::prepare_program(c
 
 void ProgramData::apply(const Program &prog, PipelineState &state) const
 {
-       vector<ProgramBlock>::const_iterator prog_begin = prepare_program(prog);
+       auto prog_begin = prepare_program(prog);
        Program::LayoutHash prog_hash = prog_begin->prog_hash;
-       for(vector<ProgramBlock>::const_iterator i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i)
+       for(auto i=prog_begin+1; (i!=programs.end() && i->prog_hash==prog_hash); ++i)
                if(i->block)
                {
                        if(i->bind_point<0)