diff --git a/OgreMain/include/OgreTextureUnitState.h b/OgreMain/include/OgreTextureUnitState.h index 06ea470af2d..651088e30ae 100644 --- a/OgreMain/include/OgreTextureUnitState.h +++ b/OgreMain/include/OgreTextureUnitState.h @@ -313,8 +313,8 @@ namespace Ogre { */ struct TextureEffect { TextureEffectType type; - int subtype; Real arg1, arg2; + int subtype; WaveformType waveType; Real base; Real frequency; @@ -547,6 +547,8 @@ namespace Ogre { void setUnorderedAccessMipLevel(int mipLevel) { mUnorderedAccessMipLevel = mipLevel; } int getUnorderedAccessMipLevel() const { return mUnorderedAccessMipLevel; } + /// @name Texture coordinate transformation + /// @{ /** Sets a matrix used to transform any texture coordinates on this layer. Texture coordinates can be modified on a texture layer to create effects like scrolling @@ -633,6 +635,7 @@ namespace Ogre { void setTextureRotate(const Radian& angle); /// Get texture rotation effects angle value. const Radian& getTextureRotate(void) const; + /// @} /// get the associated sampler const SamplerPtr& getSampler() const { return mSampler; } @@ -847,6 +850,8 @@ namespace Ogre { Real arg2 = 1.0, Real manualBlend = 0.0); + /// @name Dynamic texture coordinate generation + /// @{ /** Generic method for setting up texture effects. Allows you to specify effects directly by using the #TextureEffectType enumeration. The @@ -856,7 +861,7 @@ namespace Ogre { This method is used internally by Ogre but it is better generally for applications to use the more intuitive specialised methods such as #setEnvironmentMap and #setTextureScroll. */ - void addEffect(TextureEffect& effect); + void addEffect(TextureEffect effect); /** Turns on/off texture coordinate effect that makes this layer an environment map. @@ -953,6 +958,10 @@ namespace Ogre { */ void removeEffect( const TextureEffectType type ); + /// Get texture effects in a multimap paired array. + const EffectMap& getEffects(void) const; + /// @} + /** Determines if this texture layer is currently blank. @note This can happen if a texture fails to load or some other non-fatal error. Worth checking after @@ -972,8 +981,6 @@ namespace Ogre { */ void retryTextureLoad() { mTextureLoadFailed = false; } - /// Get texture effects in a multimap paired array. - const EffectMap& getEffects(void) const; /// Get the animated-texture animation duration. Real getAnimationDuration(void) const; diff --git a/OgreMain/src/OgreTextureUnitState.cpp b/OgreMain/src/OgreTextureUnitState.cpp index 5fb71254f91..24f28e87e59 100644 --- a/OgreMain/src/OgreTextureUnitState.cpp +++ b/OgreMain/src/OgreTextureUnitState.cpp @@ -593,17 +593,12 @@ namespace Ogre { mAlphaBlendMode.factor = manualBlend; } //----------------------------------------------------------------------- - void TextureUnitState::addEffect(TextureEffect& effect) + void TextureUnitState::addEffect(TextureEffect effect) { // Ensure controller pointer is null effect.controller = 0; - if (effect.type == ET_ENVIRONMENT_MAP - || effect.type == ET_UVSCROLL - || effect.type == ET_USCROLL - || effect.type == ET_VSCROLL - || effect.type == ET_ROTATE - || effect.type == ET_PROJECTIVE_TEXTURE) + if (effect.type != ET_TRANSFORM) { // Replace - must be unique // Search for existing effect of this type @@ -678,9 +673,7 @@ namespace Ogre { { if (enable) { - TextureEffect eff; - eff.type = ET_ENVIRONMENT_MAP; - + TextureEffect eff = {ET_ENVIRONMENT_MAP}; eff.subtype = envMapType; addEffect(eff); } @@ -824,35 +817,28 @@ namespace Ogre { removeEffect(ET_VSCROLL); // don't create an effect if the speeds are both 0 - if(uSpeed == 0.0f && vSpeed == 0.0f) + if (uSpeed == 0.0f && vSpeed == 0.0f) { - return; + return; } // Create new effect - TextureEffect eff; - if(uSpeed == vSpeed) - { - eff.type = ET_UVSCROLL; - eff.arg1 = uSpeed; - addEffect(eff); - } - else - { - if(uSpeed) + if (uSpeed == vSpeed) { - eff.type = ET_USCROLL; - eff.arg1 = uSpeed; - addEffect(eff); - } - if(vSpeed) + addEffect({ET_UVSCROLL, uSpeed}); + } + else { - eff.type = ET_VSCROLL; - eff.arg1 = vSpeed; - addEffect(eff); + if (uSpeed) + { + addEffect({ET_USCROLL, uSpeed}); + } + if (vSpeed) + { + addEffect({ET_VSCROLL, vSpeed}); + } } } - } //----------------------------------------------------------------------- void TextureUnitState::setRotateAnimation(Real speed) { @@ -864,10 +850,7 @@ namespace Ogre { return; } // Create new effect - TextureEffect eff; - eff.type = ET_ROTATE; - eff.arg1 = speed; - addEffect(eff); + addEffect({ET_ROTATE, speed}); } //----------------------------------------------------------------------- void TextureUnitState::setTransformAnimation(TextureTransformType ttype, @@ -892,14 +875,13 @@ namespace Ogre { } } - // don't create an effect if the given values are all 0 - if(base == 0.0f && phase == 0.0f && frequency == 0.0f && amplitude == 0.0f) - { - return; - } + // don't create an effect if the given values are all 0 + if(base == 0.0f && phase == 0.0f && frequency == 0.0f && amplitude == 0.0f) + { + return; + } // Create new effect - TextureEffect eff; - eff.type = ET_TRANSFORM; + TextureEffect eff = {ET_TRANSFORM}; eff.subtype = ttype; eff.waveType = waveType; eff.base = base; @@ -1086,10 +1068,9 @@ namespace Ogre { effect.controller = cMgr.createTextureWaveTransformer(this, (TextureUnitState::TextureTransformType)effect.subtype, effect.waveType, effect.base, effect.frequency, effect.phase, effect.amplitude); break; + case ET_PROJECTIVE_TEXTURE: case ET_ENVIRONMENT_MAP: break; - default: - break; } } //----------------------------------------------------------------------- @@ -1179,8 +1160,7 @@ namespace Ogre { { if (enable) { - TextureEffect eff; - eff.type = ET_PROJECTIVE_TEXTURE; + TextureEffect eff = {ET_PROJECTIVE_TEXTURE}; eff.frustum = projectionSettings; addEffect(eff); }