Skip to content

Commit

Permalink
InputLayoutDescX: added operator[] as well as Remove and GetNumElemen…
Browse files Browse the repository at this point in the history
…ts methods
  • Loading branch information
TheMostDiligent committed Oct 5, 2023
1 parent 1422201 commit 7817db2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Graphics/GraphicsEngine/interface/GraphicsTypesX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -442,6 +450,11 @@ struct InputLayoutDescX
return Desc;
}

Uint32 GetNumElements() const noexcept
{
return Desc.NumElements;
}

operator const InputLayoutDesc&() const noexcept
{
return Desc;
Expand All @@ -465,6 +478,16 @@ struct InputLayoutDescX
return *this != static_cast<const InputLayoutDesc&>(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)
{
Expand Down
29 changes: 28 additions & 1 deletion Tests/DiligentCoreTest/src/GraphicsEngine/GraphicsTypesXTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}


Expand Down

0 comments on commit 7817db2

Please sign in to comment.