From 57138b416e4816b3b982e081b5b653e8ac0eac47 Mon Sep 17 00:00:00 2001 From: Allofich Date: Tue, 2 Aug 2016 22:15:48 +0900 Subject: [PATCH] Fix spell glows to only run one at a time --- apps/openmw/mwrender/animation.cpp | 35 ++++++++++++++++++++---------- apps/openmw/mwrender/animation.hpp | 3 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 85c94e37d..736ba8956 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -1126,12 +1126,13 @@ namespace MWRender }; void Animation::addSpellCastGlow(osg::Vec4f glowColor){ - addGlow(mObjectRoot, glowColor, true); + if (mSpellGlowUpdater == NULL) // only start a new spell glow if there isn't one already + addGlow(mObjectRoot, glowColor, true); MWBase::Environment::get().getMechanicsManager()->add(mPtr); } void Animation::updateSpellGlow(float duration){ - if (mGlowUpdater != NULL && (mGlowUpdater->getHasDuration())) + if (mSpellGlowUpdater != NULL) mSpellGlowDuration += duration; if (mSpellGlowDuration >= 1.5f) // length of spell glow effect was measured from original game as around 1.5 seconds removeSpellGlow(); @@ -1145,10 +1146,10 @@ namespace MWRender else writableStateSet = osg::clone(mObjectRoot->getStateSet(), osg::CopyOp::SHALLOW_COPY); - std::vector > Textures = mGlowUpdater->getTextures(); - int TexUnit = mGlowUpdater->getTexUnit(); - mObjectRoot->removeUpdateCallback(mGlowUpdater); - mGlowUpdater = NULL; + std::vector > Textures = mSpellGlowUpdater->getTextures(); + int TexUnit = mSpellGlowUpdater->getTexUnit(); + mObjectRoot->removeUpdateCallback(mSpellGlowUpdater); + mSpellGlowUpdater = NULL; for (size_t index = 0; index < Textures.size(); index++) { @@ -1157,7 +1158,10 @@ namespace MWRender } mObjectRoot->setStateSet(writableStateSet); - writableStateSet->removeUniform(mUniform); + if (writableStateSet->getUniform("envMapColor2")) // if we added a second uniform, remove that one instead of the original + writableStateSet->removeUniform("envMapColor2"); + else + writableStateSet->removeUniform("envMapColor"); mResourceSystem->getSceneManager()->recreateShaders(mObjectRoot); mSpellGlowDuration = 0.f; } @@ -1186,9 +1190,13 @@ namespace MWRender FindLowestUnusedTexUnitVisitor findLowestUnusedTexUnitVisitor; node->accept(findLowestUnusedTexUnitVisitor); int texUnit = findLowestUnusedTexUnitVisitor.mLowestUnusedTexUnit; - mGlowUpdater = new GlowUpdater(texUnit, glowColor, textures, hasDuration); - //osg::ref_ptr glowupdater (new GlowUpdater(texUnit, glowColor, textures)); - node->addUpdateCallback(mGlowUpdater); + + osg::ref_ptr glowUpdater = new GlowUpdater(texUnit, glowColor, textures, hasDuration); + + if (hasDuration) // store the glowUpdater for later removal and checking if this is a spell glow + mSpellGlowUpdater = glowUpdater; + + node->addUpdateCallback(glowUpdater); // set a texture now so that the ShaderVisitor can find it osg::ref_ptr writableStateSet = NULL; @@ -1200,8 +1208,11 @@ namespace MWRender node->setStateSet(writableStateSet); } writableStateSet->setTextureAttributeAndModes(texUnit, textures.front(), osg::StateAttribute::ON); - mUniform = new osg::Uniform("envMapColor", glowColor); - writableStateSet->addUniform(mUniform); + + if (hasDuration && writableStateSet->getUniform("envMapColor")) // if we are adding a spell glow to something with an enchantment glow + writableStateSet->addUniform(new osg::Uniform("envMapColor2", glowColor)); + else + writableStateSet->addUniform(new osg::Uniform("envMapColor", glowColor)); mResourceSystem->getSceneManager()->recreateShaders(node); } diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 9ca9d9552..30e2de601 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -270,8 +270,7 @@ protected: float mAlpha; float mSpellGlowDuration; - osg::ref_ptr mGlowUpdater; - osg::Uniform* mUniform; + osg::ref_ptr mSpellGlowUpdater; const NodeMap& getNodeMap() const;