Skip to content

Commit

Permalink
Added GetTextureComponentMappingString function
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 7, 2023
1 parent 906fc72 commit 828055b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ TEXTURE_FORMAT TexFormatToSRGB(TEXTURE_FORMAT Fmt);

String GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAGS Flags);

String GetTextureComponentMappingString(const TextureComponentMapping& Mapping);

/// Returns the sparse texture properties assuming the standard tile shapes
SparseTextureProperties GetStandardSparseTextureProperties(const TextureDesc& TexDesc);

Expand Down
22 changes: 22 additions & 0 deletions Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,28 @@ String GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAGS Flags)
return Result;
}

String GetTextureComponentMappingString(const TextureComponentMapping& Mapping)
{
static_assert(TEXTURE_COMPONENT_SWIZZLE_IDENTITY == 0, "TEXTURE_COMPONENT_SWIZZLE_IDENTITY == 0 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_ZERO == 1, "TEXTURE_COMPONENT_SWIZZLE_ZERO == 1 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_ONE == 2, "TEXTURE_COMPONENT_SWIZZLE_ONE == 2 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_R == 3, "TEXTURE_COMPONENT_SWIZZLE_R == 3 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_G == 4, "TEXTURE_COMPONENT_SWIZZLE_G == 4 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_B == 5, "TEXTURE_COMPONENT_SWIZZLE_B == 5 is assumed below");
static_assert(TEXTURE_COMPONENT_SWIZZLE_A == 6, "TEXTURE_COMPONENT_SWIZZLE_A == 6 is assumed below");
String Str;
Str.reserve(4);
for (size_t Comp = 0; Comp < 4; ++Comp)
{
TEXTURE_COMPONENT_SWIZZLE ComponentSwizzle = Mapping[Comp];
if (ComponentSwizzle == TEXTURE_COMPONENT_SWIZZLE_IDENTITY)
Str += "rgba"[Comp];
else
Str += "_01rgba"[ComponentSwizzle];
}
return Str;
}

SparseTextureProperties GetStandardSparseTextureProperties(const TextureDesc& TexDesc)
{
constexpr Uint32 SparseBlockSize = 64 << 10;
Expand Down
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngine/interface/TextureView.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ struct TextureComponentMapping
return !(*this == RHS);
}

constexpr TEXTURE_COMPONENT_SWIZZLE operator[](Uint32 Component) const
constexpr TEXTURE_COMPONENT_SWIZZLE operator[](size_t Component) const
{
return (&R)[Component];
}

constexpr TEXTURE_COMPONENT_SWIZZLE& operator[](Uint32 Component)
constexpr TEXTURE_COMPONENT_SWIZZLE& operator[](size_t Component)
{
return (&R)[Component];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,43 @@ TEST(GraphicsAccessories_GraphicsAccessories, GetPipelineShadingRateFlagsString)
EXPECT_STREQ(GetPipelineShadingRateFlagsString(PIPELINE_SHADING_RATE_FLAG_PER_PRIMITIVE | PIPELINE_SHADING_RATE_FLAG_TEXTURE_BASED).c_str(), "PER_PRIMITIVE | TEXTURE_BASED");
}

TEST(GraphicsAccessories_GraphicsAccessories, GetTextureComponentMappingString)
{
EXPECT_STREQ(GetTextureComponentMappingString(TextureComponentMapping::Identity()).c_str(), "rgba");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO, TEXTURE_COMPONENT_SWIZZLE_ZERO))
.c_str(),
"0000");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE, TEXTURE_COMPONENT_SWIZZLE_ONE))
.c_str(),
"1111");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R, TEXTURE_COMPONENT_SWIZZLE_R))
.c_str(),
"rrrr");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_G))
.c_str(),
"gggg");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_B))
.c_str(),
"bbbb");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_A))
.c_str(),
"aaaa");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_A, TEXTURE_COMPONENT_SWIZZLE_B, TEXTURE_COMPONENT_SWIZZLE_G, TEXTURE_COMPONENT_SWIZZLE_R))
.c_str(),
"abgr");
EXPECT_STREQ(GetTextureComponentMappingString(
TextureComponentMapping(TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_IDENTITY, TEXTURE_COMPONENT_SWIZZLE_ONE))
.c_str(),
"rgb1");
}

TEST(GraphicsAccessories_GraphicsAccessories, GetMipLevelProperties)
{
TextureDesc Desc;
Expand Down

0 comments on commit 828055b

Please sign in to comment.