From: Mikko Rasa Date: Sat, 2 May 2020 14:55:37 +0000 (+0300) Subject: Add a find_pass function to Technique X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cf17331b8ddc0e00c3ba452e0f4dfa183dc8e019;p=libs%2Fgl.git Add a find_pass function to Technique --- diff --git a/source/instancearray.cpp b/source/instancearray.cpp index 5c6ab423..91f92084 100644 --- a/source/instancearray.cpp +++ b/source/instancearray.cpp @@ -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 diff --git a/source/object.cpp b/source/object.cpp index 25daf13e..d4562b86 100644 --- a/source/object.cpp +++ b/source/object.cpp @@ -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) diff --git a/source/technique.cpp b/source/technique.cpp index d6ec7115..e3233eff 100644 --- a/source/technique.cpp +++ b/source/technique.cpp @@ -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; diff --git a/source/technique.h b/source/technique.h index f80e2f61..762b98f4 100644 --- a/source/technique.h +++ b/source/technique.h @@ -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 &);