Improve pipeline building

This commit is contained in:
Lynix
2020-03-03 22:26:57 +01:00
parent d5c75926c6
commit 7bf734cdd4
16 changed files with 360 additions and 217 deletions

View File

@@ -53,7 +53,7 @@ namespace Nz
VertexDeclaration& operator=(const VertexDeclaration&) = delete;
VertexDeclaration& operator=(VertexDeclaration&&) noexcept = default;
static const VertexDeclarationRef& Get(VertexLayout layout);
static inline const VertexDeclarationRef& Get(VertexLayout layout);
static bool IsTypeSupported(ComponentType type);
template<typename... Args> static VertexDeclarationRef New(Args&&... args);

View File

@@ -67,7 +67,7 @@ namespace Nz
return GetComponentByType<T>(vertexComponent, componentIndex) != nullptr;
}
const VertexDeclarationRef& VertexDeclaration::Get(VertexLayout layout)
inline const VertexDeclarationRef& VertexDeclaration::Get(VertexLayout layout)
{
NazaraAssert(layout <= VertexLayout_Max, "Vertex layout out of enum");
@@ -84,4 +84,19 @@ namespace Nz
}
}
namespace std
{
inline const Nz::VertexDeclaration::Component* begin(const Nz::VertexDeclaration& declaration)
{
assert(declaration.GetComponentCount() != 0);
return &declaration.GetComponent(0);
}
inline const Nz::VertexDeclaration::Component* end(const Nz::VertexDeclaration& declaration)
{
assert(declaration.GetComponentCount() != 0);
return (&declaration.GetComponent(declaration.GetComponentCount() - 1) + 1);
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -26,7 +26,7 @@ namespace Nz
VertexMapper(const VertexBuffer* vertexBuffer, BufferAccess access = BufferAccess_ReadOnly);
~VertexMapper();
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component);
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);
inline const VertexBuffer* GetVertexBuffer() const;
inline std::size_t GetVertexCount() const;

View File

@@ -10,19 +10,13 @@
namespace Nz
{
template <typename T>
SparsePtr<T> VertexMapper::GetComponentPtr(VertexComponent component)
SparsePtr<T> VertexMapper::GetComponentPtr(VertexComponent component, std::size_t componentIndex)
{
// On récupère la déclaration depuis le buffer
const VertexDeclaration* declaration = m_mapper.GetBuffer()->GetVertexDeclaration();
// Ensuite le composant qui nous intéresse
bool enabled;
ComponentType type;
std::size_t offset;
declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled && GetComponentTypeOf<T>() == type)
return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + offset, declaration->GetStride());
if (const auto* componentData = declaration->GetComponentByType<T>(component, componentIndex))
return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + componentData->offset, declaration->GetStride());
else
return SparsePtr<T>();
}