From d89e833db8abc5c27525bdee8894975c9cc107d3 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 20 Aug 2024 23:03:08 +0200 Subject: [PATCH] Main: TextureUnitState - add getProjectiveTexturingFrustum to reduce getEffects() usage --- OgreMain/include/OgreTextureUnitState.h | 4 ++++ OgreMain/src/OgreRenderSystem.cpp | 3 +-- OgreMain/src/OgreSceneManager.cpp | 5 ++--- OgreMain/src/OgreTextureUnitState.cpp | 10 ++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OgreMain/include/OgreTextureUnitState.h b/OgreMain/include/OgreTextureUnitState.h index 8caf0af4935..90f147040eb 100644 --- a/OgreMain/include/OgreTextureUnitState.h +++ b/OgreMain/include/OgreTextureUnitState.h @@ -947,6 +947,10 @@ namespace Ogre { */ void setProjectiveTexturing(bool enabled, const Frustum* projectionSettings = 0); + /** Gets the Frustum which is being used to derive projective texturing parameters. + */ + const Frustum* getProjectiveTexturingFrustum(void) const; + /** Removes all effects applied to this texture layer. */ void removeAllEffects(void); diff --git a/OgreMain/src/OgreRenderSystem.cpp b/OgreMain/src/OgreRenderSystem.cpp index ad0349ff2c4..0dd3148d695 100644 --- a/OgreMain/src/OgreRenderSystem.cpp +++ b/OgreMain/src/OgreRenderSystem.cpp @@ -444,8 +444,7 @@ namespace Ogre { auto calcMode = tl._deriveTexCoordCalcMethod(); if(calcMode == TEXCALC_PROJECTIVE_TEXTURE) { - auto frustum = tl.getEffects().find(TextureUnitState::ET_PROJECTIVE_TEXTURE)->second.frustum; - _setTextureCoordCalculation(texUnit, calcMode, frustum); + _setTextureCoordCalculation(texUnit, calcMode, tl.getProjectiveTexturingFrustum()); } else { diff --git a/OgreMain/src/OgreSceneManager.cpp b/OgreMain/src/OgreSceneManager.cpp index 7b4c0ceb5fd..71fa31da977 100644 --- a/OgreMain/src/OgreSceneManager.cpp +++ b/OgreMain/src/OgreSceneManager.cpp @@ -812,10 +812,9 @@ const Pass* SceneManager::_setPass(const Pass* pass, bool shadowDerivation) { // Manually set texture projector for shaders if present // This won't get set any other way if using manual projection - auto effi = pTex->getEffects().find(TextureUnitState::ET_PROJECTIVE_TEXTURE); - if (effi != pTex->getEffects().end()) + if (auto frustum = pTex->getProjectiveTexturingFrustum()) { - mAutoParamDataSource->setTextureProjector(effi->second.frustum, unit); + mAutoParamDataSource->setTextureProjector(frustum, unit); } } if (pTex->getContentType() == TextureUnitState::CONTENT_COMPOSITOR) diff --git a/OgreMain/src/OgreTextureUnitState.cpp b/OgreMain/src/OgreTextureUnitState.cpp index 55f7abdcab6..f826e27e65c 100644 --- a/OgreMain/src/OgreTextureUnitState.cpp +++ b/OgreMain/src/OgreTextureUnitState.cpp @@ -1170,6 +1170,16 @@ namespace Ogre { } } + const Frustum* TextureUnitState::getProjectiveTexturingFrustum() const + { + EffectMap::const_iterator i = mEffects.find(ET_PROJECTIVE_TEXTURE); + if (i != mEffects.end()) + { + return i->second.frustum; + } + + return 0; + } //----------------------------------------------------------------------- void TextureUnitState::setName(const String& name) {