Skip to content

Commit

Permalink
Main: TextureUnitState - refactor internal effects mapping
Browse files Browse the repository at this point in the history
and group public API
  • Loading branch information
paroj committed Aug 20, 2024
1 parent d93691c commit 38836c1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 50 deletions.
15 changes: 11 additions & 4 deletions OgreMain/include/OgreTextureUnitState.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ namespace Ogre {
*/
struct TextureEffect {
TextureEffectType type;
int subtype;
Real arg1, arg2;
int subtype;
WaveformType waveType;
Real base;
Real frequency;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
72 changes: 26 additions & 46 deletions OgreMain/src/OgreTextureUnitState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}
//-----------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 38836c1

Please sign in to comment.