diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp b/Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp index 9df0b75a1..2c7abf79c 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp +++ b/Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp @@ -431,6 +431,14 @@ struct InputLayoutDescX return Add(Elem); } + InputLayoutDescX& Remove(Uint32 ElemIndex) + { + VERIFY_EXPR(ElemIndex < Desc.NumElements); + Elements.erase(Elements.begin() + ElemIndex); + SyncDesc(); + return *this; + } + void Clear() { InputLayoutDescX EmptyDesc; @@ -442,6 +450,11 @@ struct InputLayoutDescX return Desc; } + Uint32 GetNumElements() const noexcept + { + return Desc.NumElements; + } + operator const InputLayoutDesc&() const noexcept { return Desc; @@ -465,6 +478,16 @@ struct InputLayoutDescX return *this != static_cast(RHS); } + const LayoutElement& operator[](size_t Index) const noexcept + { + return Elements[Index]; + } + + LayoutElement& operator[](size_t Index) noexcept + { + return Elements[Index]; + } + private: void SyncDesc(bool CopyStrings = false) { diff --git a/Tests/DiligentCoreTest/src/GraphicsEngine/GraphicsTypesXTest.cpp b/Tests/DiligentCoreTest/src/GraphicsEngine/GraphicsTypesXTest.cpp index 2dab1dde5..51de9e39a 100644 --- a/Tests/DiligentCoreTest/src/GraphicsEngine/GraphicsTypesXTest.cpp +++ b/Tests/DiligentCoreTest/src/GraphicsEngine/GraphicsTypesXTest.cpp @@ -290,7 +290,8 @@ TEST(GraphicsTypesXTest, InputLayoutDescX) #define ATTRIB1(POOL) POOL("ATTRIB1"), 0u, 0u, 2u, VT_FLOAT32 #define ATTRIB2(POOL) POOL("ATTRIB2"), 1u, 0u, 2u, VT_FLOAT32 -#define ATTRIB3(POOL) POOL("ATTRIB2"), 2u, 0u, 4u, VT_UINT8, True +#define ATTRIB3(POOL) POOL("ATTRIB3"), 2u, 0u, 4u, VT_UINT8, True +#define ATTRIB4(POOL) POOL("ATTRIB4"), 3u, 0u, 3u, VT_INT32 // clang-format on @@ -347,9 +348,35 @@ TEST(GraphicsTypesXTest, InputLayoutDescX) EXPECT_EQ(DescMove2, Ref); EXPECT_EQ(DescCopy2, DescMove2); + { + StringPool Pool; + InputLayoutDescX DescX; + DescX + .Add({ATTRIB1(Pool)}) + .Add({ATTRIB4(Pool)}) + .Add(ATTRIB2(Pool)) + .Add(ATTRIB4(Pool)) + .Add({ATTRIB3(Pool)}) + .Add({ATTRIB4(Pool)}); + Pool.Clear(); + + DescX + .Remove(5) + .Remove(1) + .Remove(2); + EXPECT_EQ(DescX, Ref); + + EXPECT_EQ(DescX.GetNumElements(), 3u); + for (Uint32 i = 0; i < std::min(Ref.NumElements, DescX.GetNumElements()); ++i) + { + EXPECT_EQ(Ref.LayoutElements[i], DescX[i]); + } + } + #undef ATTRIB1 #undef ATTRIB2 #undef ATTRIB3 +#undef ATTRIB4 }