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;