From: Mikko Rasa Date: Fri, 9 Apr 2021 21:40:39 +0000 (+0300) Subject: Pass Tag by value, not by reference X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=233dff2a6c552e08da832496aecd88ef4f8948f1;p=libs%2Fgl.git Pass Tag by value, not by reference Since the tag object is small, it can be passed in a register. Keeping a deprecated version would make it hard to tell which version is being called. --- diff --git a/source/animation/animatedobject.cpp b/source/animation/animatedobject.cpp index 390b90b8..71680623 100644 --- a/source/animation/animatedobject.cpp +++ b/source/animation/animatedobject.cpp @@ -68,7 +68,7 @@ void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUni throw invalid_argument("AnimatedObject::set_uniform"); } -void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const +void AnimatedObject::setup_render(Renderer &renderer, Tag) const { renderer.transform(matrix); if(shdata) diff --git a/source/animation/animatedobject.h b/source/animation/animatedobject.h index f9b8824e..faa9325c 100644 --- a/source/animation/animatedobject.h +++ b/source/animation/animatedobject.h @@ -45,7 +45,7 @@ public: virtual const Matrix *get_matrix() const { return &matrix; } - virtual void setup_render(Renderer &, const Tag &) const; + virtual void setup_render(Renderer &, Tag) const; }; } // namespace GL diff --git a/source/effects/effect.cpp b/source/effects/effect.cpp index 46a0f236..e335b46a 100644 --- a/source/effects/effect.cpp +++ b/source/effects/effect.cpp @@ -10,12 +10,12 @@ Effect::Effect(Renderable &r): enabled_passes.insert(Tag()); } -void Effect::enable_for_pass(const Tag &tag) +void Effect::enable_for_pass(Tag tag) { enabled_passes.insert(tag); } -void Effect::disable_for_pass(const Tag &tag) +void Effect::disable_for_pass(Tag tag) { enabled_passes.erase(tag); } diff --git a/source/effects/effect.h b/source/effects/effect.h index c68bc944..c43cda3a 100644 --- a/source/effects/effect.h +++ b/source/effects/effect.h @@ -26,8 +26,8 @@ protected: public: virtual ~Effect() { } - void enable_for_pass(const Tag &); - void disable_for_pass(const Tag &); + void enable_for_pass(Tag); + void disable_for_pass(Tag); virtual const Matrix *get_matrix() const { return renderable.get_matrix(); } virtual const Geometry::BoundingSphere *get_bounding_sphere() const { return renderable.get_bounding_sphere(); } diff --git a/source/effects/environmentmap.cpp b/source/effects/environmentmap.cpp index a20f73bb..977822ac 100644 --- a/source/effects/environmentmap.cpp +++ b/source/effects/environmentmap.cpp @@ -99,7 +99,7 @@ void EnvironmentMap::finish_frame() } } -void EnvironmentMap::render(Renderer &renderer, const Tag &tag) const +void EnvironmentMap::render(Renderer &renderer, Tag tag) const { if(!enabled_passes.count(tag)) return renderer.render(renderable, tag); diff --git a/source/effects/environmentmap.h b/source/effects/environmentmap.h index db97d1d8..bd6800a6 100644 --- a/source/effects/environmentmap.h +++ b/source/effects/environmentmap.h @@ -49,7 +49,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL diff --git a/source/effects/shadowmap.cpp b/source/effects/shadowmap.cpp index c2e1f295..e43e9bde 100644 --- a/source/effects/shadowmap.cpp +++ b/source/effects/shadowmap.cpp @@ -88,7 +88,7 @@ void ShadowMap::finish_frame() rendered = false; } -void ShadowMap::render(Renderer &renderer, const Tag &tag) const +void ShadowMap::render(Renderer &renderer, Tag tag) const { if(!enabled_passes.count(tag)) return renderer.render(renderable, tag); diff --git a/source/effects/shadowmap.h b/source/effects/shadowmap.h index 5f6c5c15..9fc0f449 100644 --- a/source/effects/shadowmap.h +++ b/source/effects/shadowmap.h @@ -59,7 +59,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL diff --git a/source/materials/technique.cpp b/source/materials/technique.cpp index 09799ace..22f8f3b6 100644 --- a/source/materials/technique.cpp +++ b/source/materials/technique.cpp @@ -13,22 +13,22 @@ using namespace std; namespace Msp { namespace GL { -RenderPass &Technique::add_pass(const Tag &tag) +RenderPass &Technique::add_pass(Tag tag) { return insert_unique(passes, tag, RenderPass())->second; } -bool Technique::has_pass(const Tag &tag) const +bool Technique::has_pass(Tag tag) const { return passes.count(tag); } -const RenderPass &Technique::get_pass(const Tag &tag) const +const RenderPass &Technique::get_pass(Tag tag) const { return get_item(passes, tag); } -const RenderPass *Technique::find_pass(const Tag &tag) const +const RenderPass *Technique::find_pass(Tag tag) const { PassMap::const_iterator i = passes.find(tag); return (i!=passes.end() ? &i->second : 0); diff --git a/source/materials/technique.h b/source/materials/technique.h index 762b98f4..c3b52453 100644 --- a/source/materials/technique.h +++ b/source/materials/technique.h @@ -47,10 +47,10 @@ private: PassMap passes; 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; + RenderPass &add_pass(Tag); + bool has_pass(Tag) const; + const RenderPass &get_pass(Tag) const; + const RenderPass *find_pass(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 &); diff --git a/source/render/instancearray.cpp b/source/render/instancearray.cpp index bef6ec17..4287700f 100644 --- a/source/render/instancearray.cpp +++ b/source/render/instancearray.cpp @@ -112,7 +112,7 @@ void InstanceArray::update_instance_matrix(unsigned index) d[matrix_offset+i] = m(i/4, i%4); } -void InstanceArray::render(Renderer &renderer, const Tag &tag) const +void InstanceArray::render(Renderer &renderer, Tag tag) const { if(instances.empty()) return; diff --git a/source/render/instancearray.h b/source/render/instancearray.h index 627051f7..6a598b58 100644 --- a/source/render/instancearray.h +++ b/source/render/instancearray.h @@ -59,7 +59,7 @@ private: public: void remove(ObjectInstance &); - virtual void render(Renderer &, const Tag &) const; + virtual void render(Renderer &, Tag) const; }; template diff --git a/source/render/instancescene.cpp b/source/render/instancescene.cpp index b533bae5..20ac0f68 100644 --- a/source/render/instancescene.cpp +++ b/source/render/instancescene.cpp @@ -36,7 +36,7 @@ void InstanceScene::finish_frame() (*j)->finish_frame(); } -void InstanceScene::render(Renderer &renderer, const Tag &tag) const +void InstanceScene::render(Renderer &renderer, Tag tag) const { if(setup_frustum(renderer)) { diff --git a/source/render/instancescene.h b/source/render/instancescene.h index a5ac2cd1..85ec3794 100644 --- a/source/render/instancescene.h +++ b/source/render/instancescene.h @@ -29,7 +29,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag &tag = Tag()) const; + virtual void render(Renderer &, Tag tag = Tag()) const; }; } // namespace GL diff --git a/source/render/object.cpp b/source/render/object.cpp index dc1f4f3f..afd51498 100644 --- a/source/render/object.cpp +++ b/source/render/object.cpp @@ -134,7 +134,7 @@ const Technique *Object::get_technique(unsigned i) const return lods[i].technique.get(); } -void Object::render(Renderer &renderer, const Tag &tag) const +void Object::render(Renderer &renderer, Tag tag) const { const RenderPass *pass = get_pass(tag, 0); if(!pass) @@ -152,7 +152,7 @@ void Object::render(Renderer &renderer, const Tag &tag) const finish_render(renderer, tag); } -void Object::render(Renderer &renderer, const ObjectInstance &inst, const Tag &tag) const +void Object::render(Renderer &renderer, const ObjectInstance &inst, Tag tag) const { unsigned lod = min(inst.get_level_of_detail(renderer), lods.size()-1); const RenderPass *pass = get_pass(tag, lod); @@ -173,7 +173,7 @@ void Object::render(Renderer &renderer, const ObjectInstance &inst, const Tag &t finish_render(renderer, tag); } -const RenderPass *Object::get_pass(const Tag &tag, unsigned lod) const +const RenderPass *Object::get_pass(Tag tag, unsigned lod) const { const Technique *tech = lods[lod].technique.get(); if(!tech) diff --git a/source/render/object.h b/source/render/object.h index 48e30459..c97e951c 100644 --- a/source/render/object.h +++ b/source/render/object.h @@ -110,18 +110,18 @@ public: virtual const Matrix *get_matrix() const { return &identity_matrix; } virtual const Geometry::BoundingSphere *get_bounding_sphere() const { return &bounding_sphere; } - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; /** Renders an instance of the object. The instance's hook functions are called before and after drawing the mesh. */ - virtual void render(Renderer &, const ObjectInstance &, const Tag & = Tag()) const; + virtual void render(Renderer &, const ObjectInstance &, Tag = Tag()) const; protected: - virtual void setup_render(Renderer &, const Tag &) const { } - virtual void finish_render(Renderer &, const Tag &) const { } + virtual void setup_render(Renderer &, Tag) const { } + virtual void finish_render(Renderer &, Tag) const { } private: - const RenderPass *get_pass(const Tag &, unsigned) const; + const RenderPass *get_pass(Tag, unsigned) const; virtual void resource_loaded(Resource &); virtual void resource_removed(Resource &); diff --git a/source/render/objectinstance.cpp b/source/render/objectinstance.cpp index dbbb85bf..bdbdffd1 100644 --- a/source/render/objectinstance.cpp +++ b/source/render/objectinstance.cpp @@ -11,12 +11,12 @@ ObjectInstance::ObjectInstance(const Object &obj): object(obj) { } -void ObjectInstance::render(Renderer &renderer, const Tag &tag) const +void ObjectInstance::render(Renderer &renderer, Tag tag) const { object.render(renderer, *this, tag); } -void ObjectInstance::setup_render(Renderer &renderer, const Tag &) const +void ObjectInstance::setup_render(Renderer &renderer, Tag) const { renderer.transform(matrix); } diff --git a/source/render/objectinstance.h b/source/render/objectinstance.h index 4d3e858b..c3128877 100644 --- a/source/render/objectinstance.h +++ b/source/render/objectinstance.h @@ -36,16 +36,16 @@ public: virtual const Geometry::BoundingSphere *get_bounding_sphere() const { return object.get_bounding_sphere(); } - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; /** Hook function, called from Object just before rendering the mesh. Renderer state will have been pushed before this is called. */ - virtual void setup_render(Renderer &, const Tag &) const; + virtual void setup_render(Renderer &, Tag) const; /** Hook function, called from Object right after rendering the mesh. Since Object takes care of pushing Renderer state, this rarely needs to do anything. */ - virtual void finish_render(Renderer &, const Tag &) const { } + virtual void finish_render(Renderer &, Tag) const { } virtual unsigned get_level_of_detail(const Renderer &) const; }; diff --git a/source/render/occludedscene.cpp b/source/render/occludedscene.cpp index b3346385..b2e7ab32 100644 --- a/source/render/occludedscene.cpp +++ b/source/render/occludedscene.cpp @@ -83,7 +83,7 @@ void OccludedScene::finish_frame() i->renderable->finish_frame(); } -void OccludedScene::render(Renderer &renderer, const Tag &tag) const +void OccludedScene::render(Renderer &renderer, Tag tag) const { if(renderables.empty()) return; diff --git a/source/render/occludedscene.h b/source/render/occludedscene.h index 000673dd..78e3d3ca 100644 --- a/source/render/occludedscene.h +++ b/source/render/occludedscene.h @@ -52,7 +52,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL diff --git a/source/render/orderedscene.cpp b/source/render/orderedscene.cpp index ab1ba454..4386d3e7 100644 --- a/source/render/orderedscene.cpp +++ b/source/render/orderedscene.cpp @@ -47,7 +47,7 @@ void OrderedScene::finish_frame() (*i)->finish_frame(); } -void OrderedScene::render(Renderer &renderer, const Tag &tag) const +void OrderedScene::render(Renderer &renderer, Tag tag) const { if(setup_frustum(renderer)) { diff --git a/source/render/orderedscene.h b/source/render/orderedscene.h index 53f7b008..c41282b4 100644 --- a/source/render/orderedscene.h +++ b/source/render/orderedscene.h @@ -29,7 +29,7 @@ public: virtual void finish_frame(); using Scene::render; - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL diff --git a/source/render/pipeline.cpp b/source/render/pipeline.cpp index a7f4130b..21f9e85e 100644 --- a/source/render/pipeline.cpp +++ b/source/render/pipeline.cpp @@ -106,7 +106,7 @@ void Pipeline::set_multisample(unsigned s) } } -Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r) +Pipeline::Pass &Pipeline::add_pass(Tag tag, Renderable &r) { passes.push_back(Pass(tag, &r)); return passes.back(); @@ -156,7 +156,7 @@ void Pipeline::finish_frame() i->renderable->finish_frame(); } -void Pipeline::render(Renderer &renderer, const Tag &tag) const +void Pipeline::render(Renderer &renderer, Tag tag) const { if(tag.id) return; @@ -249,7 +249,7 @@ void Pipeline::create_targets(unsigned recreate) } -Pipeline::Pass::Pass(const Tag &t, Renderable *r): +Pipeline::Pass::Pass(Tag t, Renderable *r): tag(t), lighting(0), depth_test(0), diff --git a/source/render/pipeline.h b/source/render/pipeline.h index dd80ef3b..91996186 100644 --- a/source/render/pipeline.h +++ b/source/render/pipeline.h @@ -47,9 +47,9 @@ public: Renderable *renderable; public: - Pass(const Tag &, Renderable *); + Pass(Tag, Renderable *); - const Tag &get_tag() const { return tag; } + Tag get_tag() const { return tag; } void set_lighting(const Lighting *); void set_depth_test(const DepthTest *); @@ -111,7 +111,7 @@ public: /** Adds a pass to the pipeline. It's permissible to add the same Renderable multiple times. */ - Pass &add_pass(const Tag &, Renderable &); + Pass &add_pass(Tag, Renderable &); /** Adds a postprocessor to the pipeline. */ void add_postprocessor(PostProcessor &); @@ -128,7 +128,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag &tag = Tag()) const; + virtual void render(Renderer &, Tag tag = Tag()) const; private: void create_targets(unsigned); diff --git a/source/render/renderable.h b/source/render/renderable.h index 80fe172e..8af524fd 100644 --- a/source/render/renderable.h +++ b/source/render/renderable.h @@ -55,7 +55,7 @@ public: /** Renders the Renderable. Implementors should take care to return the renderer to the state it was in, for example by using Renderer::Push. */ - virtual void render(Renderer &, const Tag & = Tag()) const = 0; + virtual void render(Renderer &, Tag = Tag()) const = 0; }; } // namespace Msp diff --git a/source/render/renderer.cpp b/source/render/renderer.cpp index 416a0fc8..ad7ba5a7 100644 --- a/source/render/renderer.cpp +++ b/source/render/renderer.cpp @@ -252,7 +252,7 @@ void Renderer::include(const Renderable &renderable) excluded.erase(&renderable); } -void Renderer::render(const Renderable &renderable, const Tag &tag) +void Renderer::render(const Renderable &renderable, Tag tag) { if(!excluded.count(&renderable)) renderable.render(*this, tag); diff --git a/source/render/renderer.h b/source/render/renderer.h index 2854bc8f..f8d29728 100644 --- a/source/render/renderer.h +++ b/source/render/renderer.h @@ -167,7 +167,7 @@ public: void exclude(const Renderable &); void include(const Renderable &); - void render(const Renderable &, const Tag & = Tag()); + void render(const Renderable &, Tag = Tag()); void draw(const Batch &); void draw_instanced(const Batch &, unsigned); diff --git a/source/render/simplescene.cpp b/source/render/simplescene.cpp index d1fd3c1c..af2b366f 100644 --- a/source/render/simplescene.cpp +++ b/source/render/simplescene.cpp @@ -39,7 +39,7 @@ void SimpleScene::finish_frame() (*i)->finish_frame(); } -void SimpleScene::render(Renderer &renderer, const Tag &tag) const +void SimpleScene::render(Renderer &renderer, Tag tag) const { populate_cache(); if(setup_frustum(renderer)) diff --git a/source/render/simplescene.h b/source/render/simplescene.h index e56aeb0c..04d466d7 100644 --- a/source/render/simplescene.h +++ b/source/render/simplescene.h @@ -30,7 +30,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL diff --git a/source/render/slot.cpp b/source/render/slot.cpp index 07dabf07..6e811bde 100644 --- a/source/render/slot.cpp +++ b/source/render/slot.cpp @@ -35,7 +35,7 @@ void Slot::finish_frame() renderable->finish_frame(); } -void Slot::render(Renderer &renderer, const Tag &tag) const +void Slot::render(Renderer &renderer, Tag tag) const { if(renderable) renderer.render(*renderable, tag); diff --git a/source/render/slot.h b/source/render/slot.h index ad863017..9129869e 100644 --- a/source/render/slot.h +++ b/source/render/slot.h @@ -25,7 +25,7 @@ public: virtual const Geometry::BoundingSphere *get_bounding_sphere() const; virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag &) const; + virtual void render(Renderer &, Tag) const; }; } // namespace GL diff --git a/source/render/tag.h b/source/render/tag.h index 28b4fa01..93808989 100644 --- a/source/render/tag.h +++ b/source/render/tag.h @@ -18,8 +18,8 @@ struct Tag Tag(const char *); Tag(const std::string &s); - bool operator<(const Tag &t) const { return idrenderable->finish_frame(); } -void ZSortedScene::render(Renderer &renderer, const Tag &tag) const +void ZSortedScene::render(Renderer &renderer, Tag tag) const { if(renderables.empty()) return; diff --git a/source/render/zsortedscene.h b/source/render/zsortedscene.h index cb21061b..24e06a6b 100644 --- a/source/render/zsortedscene.h +++ b/source/render/zsortedscene.h @@ -66,7 +66,7 @@ public: virtual void setup_frame(Renderer &); virtual void finish_frame(); - virtual void render(Renderer &, const Tag & = Tag()) const; + virtual void render(Renderer &, Tag = Tag()) const; }; } // namespace GL