Add VertexDeclaration::Find to return type from ptr

This commit is contained in:
SweetId 2024-03-10 16:39:42 -04:00
parent 8c3e8956ca
commit 4d15cbcc2b
2 changed files with 11 additions and 0 deletions

View File

@ -53,6 +53,7 @@ namespace Nz
VertexDeclaration& operator=(VertexDeclaration&&) = delete;
static inline const std::shared_ptr<VertexDeclaration>& Get(VertexLayout layout);
static inline const VertexLayout Find(const std::shared_ptr<VertexDeclaration>& declaration);
static bool IsTypeSupported(ComponentType type);
struct Component

View File

@ -75,5 +75,15 @@ namespace Nz
NazaraAssert(layout <= VertexLayout::Max, "Vertex layout out of enum");
return s_declarations[layout];
}
inline const VertexLayout VertexDeclaration::Find(const std::shared_ptr<VertexDeclaration>& declaration)
{
for (size_t i = 0; i < (size_t)VertexLayout::Max; ++i)
if (s_declarations[(VertexLayout)i].get() == declaration.get())
return (VertexLayout)i;
NazaraAssert(declaration, "Invalid declaration");
return VertexLayout::Max;
}
}