From 67e4a7e37bec960219b5a8fa1e1f302cd6c9f136 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 9 Feb 2017 04:50:51 +0100 Subject: [PATCH] Change some osg::clone's to direct copy constructor to avoid dynamic_cast overhead --- apps/openmw/mwrender/animation.cpp | 4 ++-- apps/openmw/mwrender/util.cpp | 2 +- components/sceneutil/lightmanager.cpp | 2 +- components/sceneutil/lightmanager.hpp | 2 +- components/sceneutil/statesetupdater.cpp | 2 +- components/shader/shadervisitor.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 976d83a8f..0865850e2 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -543,7 +543,7 @@ namespace MWRender size_t blendMask = detectBlendMask(node); // clone the controller, because each Animation needs its own ControllerSource - osg::ref_ptr cloned = osg::clone(it->second.get(), osg::CopyOp::DEEP_COPY_ALL); + osg::ref_ptr cloned = new NifOsg::KeyframeController(*it->second, osg::CopyOp::SHALLOW_COPY); cloned->setSource(mAnimationTimePtr[blendMask]); animsrc->mControllerMap[blendMask].insert(std::make_pair(bonename, cloned)); @@ -1272,7 +1272,7 @@ namespace MWRender writableStateSet = node->getOrCreateStateSet(); else { - writableStateSet = osg::clone(node->getStateSet(), osg::CopyOp::SHALLOW_COPY); + writableStateSet = new osg::StateSet(*node->getStateSet(), osg::CopyOp::SHALLOW_COPY); node->setStateSet(writableStateSet); } writableStateSet->setTextureAttributeAndModes(texUnit, textures.front(), osg::StateAttribute::ON); diff --git a/apps/openmw/mwrender/util.cpp b/apps/openmw/mwrender/util.cpp index aa8aaccbc..74047b58b 100644 --- a/apps/openmw/mwrender/util.cpp +++ b/apps/openmw/mwrender/util.cpp @@ -55,7 +55,7 @@ void overrideTexture(const std::string &texture, Resource::ResourceSystem *resou osg::ref_ptr stateset; if (node->getStateSet()) - stateset = osg::clone(node->getStateSet(), osg::CopyOp::SHALLOW_COPY); + stateset = new osg::StateSet(*node->getStateSet(), osg::CopyOp::SHALLOW_COPY); else stateset = new osg::StateSet; diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 3fc15afc0..ee640d6cc 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -368,7 +368,7 @@ namespace SceneUtil mId = sLightId++; for (int i=0; i<2; ++i) - mLight[i] = osg::clone(copy.mLight[i].get(), copyop); + mLight[i] = new osg::Light(*copy.mLight[i].get(), copyop); } diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index c8a057263..2c7a6a3d8 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -64,7 +64,7 @@ namespace SceneUtil void setLight(osg::Light* light) { mLight[0] = light; - mLight[1] = osg::clone(light); + mLight[1] = new osg::Light(*light); } /// Get the unique ID for this light source. diff --git a/components/sceneutil/statesetupdater.cpp b/components/sceneutil/statesetupdater.cpp index 31d42d342..5a5ecaded 100644 --- a/components/sceneutil/statesetupdater.cpp +++ b/components/sceneutil/statesetupdater.cpp @@ -15,7 +15,7 @@ namespace SceneUtil for (int i=0; i<2; ++i) // Using SHALLOW_COPY for StateAttributes, if users want to modify it is their responsibility to set a non-shared one first // This can be done conveniently in user implementations of the setDefaults() method { - mStateSets[i] = osg::clone(src, osg::CopyOp::SHALLOW_COPY); + mStateSets[i] = new osg::StateSet(*src, osg::CopyOp::SHALLOW_COPY); setDefaults(mStateSets[i]); } } diff --git a/components/shader/shadervisitor.cpp b/components/shader/shadervisitor.cpp index e603eabff..33fd9186f 100644 --- a/components/shader/shadervisitor.cpp +++ b/components/shader/shadervisitor.cpp @@ -85,7 +85,7 @@ namespace Shader if (!node.getStateSet()) return node.getOrCreateStateSet(); - osg::ref_ptr newStateSet = osg::clone(node.getStateSet(), osg::CopyOp::SHALLOW_COPY); + osg::ref_ptr newStateSet = new osg::StateSet(*node.getStateSet(), osg::CopyOp::SHALLOW_COPY); node.setStateSet(newStateSet); return newStateSet.get(); }