]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a find_pass function to Technique
authorMikko Rasa <tdb@tdb.fi>
Sat, 2 May 2020 14:55:37 +0000 (17:55 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 2 May 2020 14:55:44 +0000 (17:55 +0300)
source/instancearray.cpp
source/object.cpp
source/technique.cpp
source/technique.h

index 5c6ab423bb8981326416b718e078cd51cceac12e..91f92084d94a680bde115f938b257bdabe8dbd29 100644 (file)
@@ -113,16 +113,16 @@ void InstanceArray::render(Renderer &renderer, const Tag &tag) const
                const Technique *tech = object.get_technique();
                if(!tech)
                        throw logic_error("no technique");
-               if(!tech->has_pass(tag))
+               const RenderPass *pass = tech->find_pass(tag);
+               if(!pass)
                        return;
-               const RenderPass &pass = tech->get_pass(tag);
 
                const Mesh *mesh = object.get_mesh();
                mesh->get_vertices().refresh();
                instance_data->refresh();
 
                Renderer::Push push(renderer);
-               pass.apply(renderer);
+               pass->apply(renderer);
                mesh->draw_instanced(renderer, *vtx_setup, instances.size());
        }
        else
index 25daf13ec5dd02fba0bdc17ed9fa6511ab360ebd..d4562b86103af8abd34a8dbdcf3c2cf46dd8221e 100644 (file)
@@ -170,9 +170,7 @@ const RenderPass *Object::get_pass(const Tag &tag, unsigned lod) const
        const Technique *tech = lods[lod].technique.get();
        if(!tech)
                throw logic_error("no technique");
-       if(!tech->has_pass(tag))
-               return 0;
-       return &tech->get_pass(tag);
+       return tech->find_pass(tag);
 }
 
 void Object::resource_loaded(Resource &res)
index d6ec7115f6e703a5b215803952a27716f934e468..e3233eff87cc5c6c7ba15550605b709ee4b55ad4 100644 (file)
@@ -28,6 +28,12 @@ const RenderPass &Technique::get_pass(const Tag &tag) const
        return get_item(passes, tag);
 }
 
+const RenderPass *Technique::find_pass(const Tag &tag) const
+{
+       PassMap::const_iterator i = passes.find(tag);
+       return (i!=passes.end() ? &i->second : 0);
+}
+
 bool Technique::replace_texture(const string &slot, const Texture &tex)
 {
        bool replaced = false;
index f80e2f6144e0f59d32bade49829c721df5b15d27..762b98f4f9afe1d977e4c663397617c6d6d2205f 100644 (file)
@@ -50,6 +50,7 @@ public:
        RenderPass &add_pass(const Tag &);
        bool has_pass(const Tag &) const;
        const RenderPass &get_pass(const Tag &) const;
+       const RenderPass *find_pass(const Tag &) const;
        const PassMap &get_passes() const { return passes; }
        bool replace_texture(const std::string &, const Texture &);
        bool replace_material(const std::string &, const Material &);