Skip to content

Commit

Permalink
TextureComponentMapping: added operator* that combines two swizzles i…
Browse files Browse the repository at this point in the history
…nto one
  • Loading branch information
TheMostDiligent committed Dec 8, 2023
1 parent eadee5c commit 84663a4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Graphics/GraphicsEngine/interface/TextureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,38 @@ struct TextureComponentMapping
TEXTURE_COMPONENT_SWIZZLE_IDENTITY
};
}

// Combines two component mappings into one.
// The resulting mapping is equivalent to first applying the first (lhs) mapping,
// then applying the second (rhs) mapping.
TextureComponentMapping operator*(const TextureComponentMapping& Rhs) const
{
TextureComponentMapping CombinedMapping;
for (size_t c = 0; c < 4; ++c)
{
TEXTURE_COMPONENT_SWIZZLE RhsCompSwizzle = Rhs[c];
TEXTURE_COMPONENT_SWIZZLE& DstCompSwizzle = CombinedMapping[c];
switch(RhsCompSwizzle)
{
case TEXTURE_COMPONENT_SWIZZLE_IDENTITY: DstCompSwizzle = (*this)[c]; break;
case TEXTURE_COMPONENT_SWIZZLE_ZERO: DstCompSwizzle = TEXTURE_COMPONENT_SWIZZLE_ZERO; break;
case TEXTURE_COMPONENT_SWIZZLE_ONE: DstCompSwizzle = TEXTURE_COMPONENT_SWIZZLE_ONE; break;
case TEXTURE_COMPONENT_SWIZZLE_R: DstCompSwizzle = R; break;
case TEXTURE_COMPONENT_SWIZZLE_G: DstCompSwizzle = G; break;
case TEXTURE_COMPONENT_SWIZZLE_B: DstCompSwizzle = B; break;
case TEXTURE_COMPONENT_SWIZZLE_A: DstCompSwizzle = A; break;
default: DstCompSwizzle = (*this)[c]; break;
}
}
static_assert(TEXTURE_COMPONENT_SWIZZLE_COUNT == 7, "Please handle the new component swizzle");
return CombinedMapping;
}

TextureComponentMapping& operator*=(const TextureComponentMapping& rhs)
{
*this = *this * rhs;
return *this;
}
#endif
};
typedef struct TextureComponentMapping TextureComponentMapping;
Expand Down

0 comments on commit 84663a4

Please sign in to comment.