From 93848ef01cefa61a0dd69af29a55319bd611e3bb Mon Sep 17 00:00:00 2001 From: Bo Svensson <90132211+bosvensson1@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:11:59 +0000 Subject: [PATCH] avoids virtual function calls in ComputeLightSpaceBounds (#3167) osg::NodeVisitor is designed to recursively call virtual apply signatures until we find an implemented signature. Encountered nodes that we do not explicitely handle will trigger additional virtual function calls. With this PR we avoid these additional virtual function calls in the particularly costly ComputeLightSpaceBounds by adding some explicit signatures. --- components/sceneutil/mwshadowtechnique.cpp | 14 ++++++++++++++ components/sceneutil/mwshadowtechnique.hpp | 11 ++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/components/sceneutil/mwshadowtechnique.cpp b/components/sceneutil/mwshadowtechnique.cpp index 89d872dbfe..024123b3e1 100644 --- a/components/sceneutil/mwshadowtechnique.cpp +++ b/components/sceneutil/mwshadowtechnique.cpp @@ -378,6 +378,11 @@ void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Node& node) popCurrentMask(); } +void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Group& node) +{ + apply(static_cast(node)); +} + void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Drawable& drawable) { if (isCulled(drawable)) return; @@ -391,6 +396,11 @@ void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Drawable& drawable) popCurrentMask(); } +void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Geometry& drawable) +{ + apply(static_cast(drawable)); +} + void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Billboard&) { OSG_INFO << "Warning Billboards not yet supported" << std::endl; @@ -424,7 +434,11 @@ void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Transform& transform // pop the culling mode. popCurrentMask(); +} +void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::MatrixTransform& transform) +{ + apply(static_cast(transform)); } void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Camera&) diff --git a/components/sceneutil/mwshadowtechnique.hpp b/components/sceneutil/mwshadowtechnique.hpp index fd562184e0..3f6c0fb765 100644 --- a/components/sceneutil/mwshadowtechnique.hpp +++ b/components/sceneutil/mwshadowtechnique.hpp @@ -91,20 +91,21 @@ namespace SceneUtil { public: ComputeLightSpaceBounds(); - void apply(osg::Node& node) override; + void apply(osg::Node& node) override final; + void apply(osg::Group& node) override; - void apply(osg::Drawable& drawable) override; + void apply(osg::Drawable& drawable) override final; + void apply(osg::Geometry& drawable) override; void apply(osg::Billboard&) override; void apply(osg::Projection&) override; - void apply(osg::Transform& transform) override; + void apply(osg::Transform& transform) override final; + void apply(osg::MatrixTransform& transform) override; void apply(osg::Camera&) override; - using osg::NodeVisitor::apply; - void updateBound(const osg::BoundingBox& bb); void update(const osg::Vec3& v);