From 6916fdac9e0c2d2c99037064f5338ccd9776d375 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 8 Dec 2023 10:33:02 -0800 Subject: [PATCH] TextureComponentMapping: added operator* that combines two swizzles into one --- .../GraphicsEngine/interface/TextureView.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h index 1c86bb58f5..40050a2182 100644 --- a/Graphics/GraphicsEngine/interface/TextureView.h +++ b/Graphics/GraphicsEngine/interface/TextureView.h @@ -175,6 +175,36 @@ 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; + } + } + return CombinedMapping; + } + + TextureComponentMapping& operator*=(const TextureComponentMapping& rhs) + { + *this = *this * rhs; + return *this; + } #endif }; typedef struct TextureComponentMapping TextureComponentMapping;