]> git.tdb.fi Git - libs/gl.git/blobdiff - source/materials/renderpass.cpp
Use C++11 features with containers
[libs/gl.git] / source / materials / renderpass.cpp
index 9a7ceef782075ee38821aa5ae9b45f1b6e13c425..f144a5dd5230927f683d3c0e781d8fb0a0fe799f 100644 (file)
@@ -61,7 +61,7 @@ void RenderPass::set_shader_program(const Program *prog, const ProgramData *data
 
 Tag RenderPass::get_slotted_uniform_tag(Tag slot) const
 {
-       map<Tag, Tag>::const_iterator i = uniform_slots.find(slot);
+       auto i = uniform_slots.find(slot);
        if(i==uniform_slots.end())
                return Tag();
        return i->second;
@@ -76,7 +76,7 @@ void RenderPass::set_material(const Material *mat)
 
 void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
 {
-       vector<TextureSlot>::iterator i = find_member(textures, tag, &TextureSlot::tag);
+       auto i = find_member(textures, tag, &TextureSlot::tag);
        if(i==textures.end())
        {
                textures.push_back(TextureSlot(tag));
@@ -89,7 +89,7 @@ void RenderPass::set_texture(Tag tag, const Texture *tex, const Sampler *samp)
 
 Tag RenderPass::get_texture_tag(const string &slot) const
 {
-       vector<TextureSlot>::const_iterator i = find_member(textures, slot, &TextureSlot::slot_name);
+       auto i = find_member(textures, slot, &TextureSlot::slot_name);
        return (i!=textures.end() ? i->tag : Tag());
 }
 
@@ -99,28 +99,27 @@ void RenderPass::set_texture(unsigned index, const Texture *tex, const Sampler *
                throw invalid_operation("RenderPass::set_texture");
 
        const vector<Program::UniformInfo> &uniforms = shprog->get_uniforms();
-       for(vector<Program::UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-               if(is_image(i->type) && i->binding==static_cast<int>(index))
-                       return set_texture(i->tag, tex, samp);
+       for(const Program::UniformInfo &u: uniforms)
+               if(is_image(u.type) && u.binding==static_cast<int>(index))
+                       return set_texture(u.tag, tex, samp);
 
        if(shdata)
        {
-               const vector<Tag> &tags = shdata->get_uniform_tags();
-               for(vector<Tag>::const_iterator i=tags.begin(); i!=tags.end(); ++i)
+               for(Tag t: shdata->get_uniform_tags())
                {
-                       vector<Program::UniformInfo>::const_iterator j = find_member(uniforms, *i, &Program::UniformInfo::tag);
+                       auto j = find_member(uniforms, t, &Program::UniformInfo::tag);
                        if(j==uniforms.end() || !is_image(j->type))
                                continue;
-                       if(const Uniform1i *uni1i = dynamic_cast<const Uniform1i *>(shdata->find_uniform(*i)))
+                       if(const Uniform1i *uni1i = dynamic_cast<const Uniform1i *>(shdata->find_uniform(t)))
                                if(uni1i->get()==static_cast<int>(index))
-                                       return set_texture(*i, tex, samp);
+                                       return set_texture(t, tex, samp);
                }
        }
 }
 
 int RenderPass::get_texture_index(const string &n) const
 {
-       vector<TextureSlot>::const_iterator i = find_member(textures, n, &TextureSlot::slot_name);
+       auto i = find_member(textures, n, &TextureSlot::slot_name);
        return (shprog && i!=textures.end() ? shprog->get_uniform_binding(i->tag) : -1);
 }
 
@@ -136,8 +135,8 @@ void RenderPass::set_receive_shadows(bool rs)
 
 void RenderPass::apply(Renderer &renderer) const
 {
-       for(vector<TextureSlot>::const_iterator i=textures.begin(); i!=textures.end(); ++i)
-               renderer.set_texture(i->tag, i->texture, i->sampler);
+       for(const TextureSlot &t: textures)
+               renderer.set_texture(t.tag, t.texture, t.sampler);
        renderer.set_shader_program(shprog, shdata.get());
        if(material)
                renderer.add_shader_data(material->get_shader_data());
@@ -237,7 +236,7 @@ void RenderPass::Loader::shader(const string &n)
 
 void RenderPass::Loader::texture(const string &n)
 {
-       vector<TextureSlot>::iterator i = find_member(obj.textures, Tag(n), &TextureSlot::tag);
+       auto i = find_member(obj.textures, Tag(n), &TextureSlot::tag);
        if(i==obj.textures.end())
        {
                obj.textures.push_back(TextureSlot(n));
@@ -253,16 +252,15 @@ void RenderPass::Loader::texunit(unsigned)
        string name;
        if(obj.shprog)
        {
-               const vector<Program::UniformInfo> &uniforms = obj.shprog->get_uniforms();
-               for(vector<Program::UniformInfo>::const_iterator i=uniforms.begin(); i!=uniforms.end(); ++i)
-                       if(is_image(i->type) && i->binding>=0)
+               for(const Program::UniformInfo &u: obj.shprog->get_uniforms())
+                       if(is_image(u.type) && u.binding>=0)
                        {
                                if(!name.empty())
                                {
                                        name.clear();
                                        break;
                                }
-                               name = i->name;
+                               name = u.name;
                        }
        }