From 07c3ec482c70d385fde4a17eeb37b5faf1fb6536 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Fri, 23 Aug 2024 22:35:01 +0200 Subject: [PATCH] Main: TUS - split camera based from controller based effects --- OgreMain/include/OgreTextureUnitState.h | 6 ++- OgreMain/src/OgreTextureUnitState.cpp | 65 ++++++++++--------------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/OgreMain/include/OgreTextureUnitState.h b/OgreMain/include/OgreTextureUnitState.h index 93b1b1930d7..7e949c8441b 100644 --- a/OgreMain/include/OgreTextureUnitState.h +++ b/OgreMain/include/OgreTextureUnitState.h @@ -314,7 +314,7 @@ namespace Ogre { */ struct TextureEffect { TextureEffectType type; - float arg1, arg2; + float arg1; int subtype; WaveformType waveType; float base; @@ -322,7 +322,6 @@ namespace Ogre { float phase; float amplitude; ControllerFloat* controller; - const Frustum* frustum; }; /** Texture effects in a multimap paired array. @@ -1098,6 +1097,9 @@ namespace Ogre { /// The index of the referenced texture if referencing an MRT in a compositor. uint32 mCompositorRefMrtIndex; + const Frustum* mProjectiveTexturingFrustum; + TexCoordCalcMethod mTexCoordCalcMethod; + //----------------------------------------------------------------------------- // Complex members (those that can't be copied using memcpy) are at the end to // allow for fast copying of the basic members. diff --git a/OgreMain/src/OgreTextureUnitState.cpp b/OgreMain/src/OgreTextureUnitState.cpp index d7f7613a49a..7dc1a7730cf 100644 --- a/OgreMain/src/OgreTextureUnitState.cpp +++ b/OgreMain/src/OgreTextureUnitState.cpp @@ -132,6 +132,8 @@ namespace Ogre { , mTextureLoadFailed(false) , mRecalcTexMatrix(false) , mTextureCoordSetIndex(0) + , mProjectiveTexturingFrustum(0) + , mTexCoordCalcMethod(TEXCALC_NONE) , mFramePtrs(1) , mSampler(TextureManager::getSingletonPtr() ? TextureManager::getSingleton().getDefaultSampler() : DUMMY_SAMPLER) , mParent(parent) @@ -673,13 +675,25 @@ namespace Ogre { { if (enable) { - TextureEffect eff = {ET_ENVIRONMENT_MAP}; - eff.subtype = envMapType; - addEffect(eff); + switch (envMapType) + { + case ENV_CURVED: + mTexCoordCalcMethod = TEXCALC_ENVIRONMENT_MAP; + break; + case ENV_PLANAR: + mTexCoordCalcMethod = TEXCALC_ENVIRONMENT_MAP_PLANAR; + break; + case ENV_REFLECTION: + mTexCoordCalcMethod = TEXCALC_ENVIRONMENT_MAP_REFLECTION; + break; + case ENV_NORMAL: + mTexCoordCalcMethod = TEXCALC_ENVIRONMENT_MAP_NORMAL; + break; + } } else { - removeEffect(ET_ENVIRONMENT_MAP); + mTexCoordCalcMethod = TEXCALC_NONE; } } //----------------------------------------------------------------------- @@ -1160,25 +1174,19 @@ namespace Ogre { { if (enable) { - TextureEffect eff = {ET_PROJECTIVE_TEXTURE}; - eff.frustum = projectionSettings; - addEffect(eff); + mProjectiveTexturingFrustum = projectionSettings; + mTexCoordCalcMethod = TEXCALC_PROJECTIVE_TEXTURE; } else { - removeEffect(ET_PROJECTIVE_TEXTURE); + mProjectiveTexturingFrustum = 0; + mTexCoordCalcMethod = TEXCALC_NONE; } } const Frustum* TextureUnitState::getProjectiveTexturingFrustum() const { - EffectMap::const_iterator i = mEffects.find(ET_PROJECTIVE_TEXTURE); - if (i != mEffects.end()) - { - return i->second.frustum; - } - - return 0; + return mProjectiveTexturingFrustum; } //----------------------------------------------------------------------- void TextureUnitState::setName(const String& name) @@ -1218,28 +1226,5 @@ namespace Ogre { return mSampler; } - TexCoordCalcMethod TextureUnitState::_deriveTexCoordCalcMethod() const - { - TexCoordCalcMethod texCoordCalcMethod = TEXCALC_NONE; - for (const auto& effi : mEffects) - { - switch (effi.second.type) - { - case ET_ENVIRONMENT_MAP: - texCoordCalcMethod = (TexCoordCalcMethod)effi.second.subtype; - break; - case ET_UVSCROLL: - case ET_USCROLL: - case ET_VSCROLL: - case ET_ROTATE: - case ET_TRANSFORM: - break; - case ET_PROJECTIVE_TEXTURE: - texCoordCalcMethod = TEXCALC_PROJECTIVE_TEXTURE; - break; - } - } - - return texCoordCalcMethod; - } -} + TexCoordCalcMethod TextureUnitState::_deriveTexCoordCalcMethod() const { return mTexCoordCalcMethod; } + } // namespace Ogre