Utility/VertexMapper: Add GetVertex[Buffer|Count] functions

This commit is contained in:
Lynix 2017-10-18 00:20:38 +02:00
parent 10a92dcb18
commit 5b4185a4a6
2 changed files with 18 additions and 3 deletions

View File

@ -27,6 +27,9 @@ namespace Nz
~VertexMapper(); ~VertexMapper();
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component); template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component);
inline const VertexBuffer* GetVertexBuffer() const;
inline UInt32 GetVertexCount() const;
template<typename T> bool HasComponentOfType(VertexComponent component) const; template<typename T> bool HasComponentOfType(VertexComponent component) const;
void Unmap(); void Unmap();

View File

@ -2,9 +2,10 @@
// This file is part of the "Nazara Engine - Utility module" // This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/VertexMapper.hpp>
#include <Nazara/Utility/Algorithm.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp> #include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
#include <Nazara/Utility/Algorithm.hpp>
namespace Nz namespace Nz
{ {
@ -20,9 +21,10 @@ namespace Nz
std::size_t offset; std::size_t offset;
declaration->GetComponent(component, &enabled, &type, &offset); declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled && GetComponentTypeOf<T>() == type) if (enabled)
{ {
///TODO: Vérifier le rapport entre le type de l'attribut et le type template ? NazaraAssert(GetComponentTypeOf<T>() == type, "Attribute type does not match template type");
return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + offset, declaration->GetStride()); return SparsePtr<T>(static_cast<UInt8*>(m_mapper.GetPointer()) + offset, declaration->GetStride());
} }
else else
@ -32,6 +34,16 @@ namespace Nz
} }
} }
inline const VertexBuffer* VertexMapper::GetVertexBuffer() const
{
return m_mapper.GetBuffer();
}
inline UInt32 VertexMapper::GetVertexCount() const
{
return GetVertexBuffer()->GetVertexCount();
}
template<typename T> template<typename T>
bool VertexMapper::HasComponentOfType(VertexComponent component) const bool VertexMapper::HasComponentOfType(VertexComponent component) const
{ {