diff --git a/OgreMain/include/OgreTextureUnitState.h b/OgreMain/include/OgreTextureUnitState.h index 06ea470af2d..90f147040eb 100644 --- a/OgreMain/include/OgreTextureUnitState.h +++ b/OgreMain/include/OgreTextureUnitState.h @@ -313,13 +313,13 @@ namespace Ogre { */ struct TextureEffect { TextureEffectType type; + float arg1, arg2; int subtype; - Real arg1, arg2; WaveformType waveType; - Real base; - Real frequency; - Real phase; - Real amplitude; + float base; + float frequency; + float phase; + float amplitude; ControllerFloat* controller; const Frustum* frustum; }; @@ -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 @@ -585,31 +587,31 @@ namespace Ogre { @param v The amount the texture should be moved vertically (v direction). */ - void setTextureScroll(Real u, Real v); + void setTextureScroll(float u, float v); /** As setTextureScroll, but sets only U value. */ - void setTextureUScroll(Real value); + void setTextureUScroll(float value); /// Get texture uscroll value. - Real getTextureUScroll(void) const; + float getTextureUScroll(void) const; /** As setTextureScroll, but sets only V value. */ - void setTextureVScroll(Real value); + void setTextureVScroll(float value); /// Get texture vscroll value. - Real getTextureVScroll(void) const; + float getTextureVScroll(void) const; /** As setTextureScale, but sets only U value. */ - void setTextureUScale(Real value); + void setTextureUScale(float value); /// Get texture uscale value. - Real getTextureUScale(void) const; + float getTextureUScale(void) const; /** As setTextureScale, but sets only V value. */ - void setTextureVScale(Real value); + void setTextureVScale(float value); /// Get texture vscale value. - Real getTextureVScale(void) const; + float getTextureVScale(void) const; /** Sets the scaling factor applied to texture coordinates. @@ -622,7 +624,7 @@ namespace Ogre { @param vScale The value by which the texture is to be scaled vertically. */ - void setTextureScale(Real uScale, Real vScale); + void setTextureScale(float uScale, float vScale); /** Sets the anticlockwise rotation factor applied to texture coordinates. @@ -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. @@ -889,7 +894,7 @@ namespace Ogre { @param vSpeed The number of vertical loops per second (+ve=moving up, -ve= moving down). */ - void setScrollAnimation(Real uSpeed, Real vSpeed); + void setScrollAnimation(float uSpeed, float vSpeed); /** Sets up an animated texture rotation for this layer. @@ -897,7 +902,7 @@ namespace Ogre { @param speed The number of complete anticlockwise revolutions per second (use -ve for clockwise) */ - void setRotateAnimation(Real speed); + void setRotateAnimation(float speed); /** Sets up a general time-relative texture modification effect. @@ -917,7 +922,7 @@ namespace Ogre { Scales the output so that instead of lying within 0..1 it lies within 0..1*amplitude for exaggerated effects. */ void setTransformAnimation( const TextureTransformType ttype, - const WaveformType waveType, Real base = 0, Real frequency = 1, Real phase = 0, Real amplitude = 1 ); + const WaveformType waveType, float base = 0, float frequency = 1, float phase = 0, float amplitude = 1 ); /** Enables or disables projective texturing on this texture unit. @@ -942,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); @@ -953,6 +962,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 +985,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; @@ -1070,8 +1081,8 @@ namespace Ogre { LayerBlendModeEx mAlphaBlendMode; Real mGamma; - Real mUMod, mVMod; - Real mUScale, mVScale; + float mUMod, mVMod; + float mUScale, mVScale; Radian mRotate; mutable Matrix4 mTexModMatrix; 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 a5f13216f74..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) @@ -2055,6 +2054,7 @@ Animation* SceneManager::createAnimation(const String& name, Real length) } Animation* pAnim = OGRE_NEW Animation(name, length); + pAnim->_notifyContainer(this); mAnimationsList[name] = pAnim; return pAnim; } diff --git a/OgreMain/src/OgreTextureUnitState.cpp b/OgreMain/src/OgreTextureUnitState.cpp index 5fb71254f91..c7981e552e7 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); } @@ -719,14 +712,14 @@ namespace Ogre { mRecalcTexMatrix = false; } //----------------------------------------------------------------------- - void TextureUnitState::setTextureScroll(Real u, Real v) + void TextureUnitState::setTextureScroll(float u, float v) { mUMod = u; mVMod = v; mRecalcTexMatrix = true; } //----------------------------------------------------------------------- - void TextureUnitState::setTextureScale(Real uScale, Real vScale) + void TextureUnitState::setTextureScale(float uScale, float vScale) { mUScale = uScale; mVScale = vScale; @@ -792,31 +785,31 @@ namespace Ogre { } //----------------------------------------------------------------------- - void TextureUnitState::setTextureUScroll(Real value) + void TextureUnitState::setTextureUScroll(float value) { mUMod = value; mRecalcTexMatrix = true; } //----------------------------------------------------------------------- - void TextureUnitState::setTextureVScroll(Real value) + void TextureUnitState::setTextureVScroll(float value) { mVMod = value; mRecalcTexMatrix = true; } //----------------------------------------------------------------------- - void TextureUnitState::setTextureUScale(Real value) + void TextureUnitState::setTextureUScale(float value) { mUScale = value; mRecalcTexMatrix = true; } //----------------------------------------------------------------------- - void TextureUnitState::setTextureVScale(Real value) + void TextureUnitState::setTextureVScale(float value) { mVScale = value; mRecalcTexMatrix = true; } //----------------------------------------------------------------------- - void TextureUnitState::setScrollAnimation(Real uSpeed, Real vSpeed) + void TextureUnitState::setScrollAnimation(float uSpeed, float vSpeed) { // Remove existing effects removeEffect(ET_UVSCROLL); @@ -824,37 +817,30 @@ 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) + void TextureUnitState::setRotateAnimation(float speed) { // Remove existing effect removeEffect(ET_ROTATE); @@ -864,14 +850,11 @@ 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, - WaveformType waveType, Real base, Real frequency, Real phase, Real amplitude) + WaveformType waveType, float base, float frequency, float phase, float amplitude) { // Remove existing effect // note, only remove for subtype, not entire ET_TRANSFORM @@ -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,32 +1068,31 @@ 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; } } //----------------------------------------------------------------------- - Real TextureUnitState::getTextureUScroll(void) const + float TextureUnitState::getTextureUScroll(void) const { return mUMod; } //----------------------------------------------------------------------- - Real TextureUnitState::getTextureVScroll(void) const + float TextureUnitState::getTextureVScroll(void) const { return mVMod; } //----------------------------------------------------------------------- - Real TextureUnitState::getTextureUScale(void) const + float TextureUnitState::getTextureUScale(void) const { return mUScale; } //----------------------------------------------------------------------- - Real TextureUnitState::getTextureVScale(void) const + float TextureUnitState::getTextureVScale(void) const { return mVScale; } @@ -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); } @@ -1190,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) {