(VertexMapper) Updated interface

Added access parameter
Removed useless GetVertexCount method


Former-commit-id: 670d16ed9668eb5df476a592929ed9c364b1f11a
This commit is contained in:
Lynix 2015-01-26 17:11:00 +01:00
parent ab538e0e2d
commit 5e3fdbca89
4 changed files with 11 additions and 22 deletions

View File

@ -18,18 +18,16 @@ class NzSubMesh;
class NAZARA_API NzVertexMapper class NAZARA_API NzVertexMapper
{ {
public: public:
NzVertexMapper(NzVertexBuffer* vertexBuffer, unsigned int vertexCount); NzVertexMapper(NzSubMesh* subMesh, nzBufferAccess access = nzBufferAccess_ReadWrite);
NzVertexMapper(NzSubMesh* subMesh); NzVertexMapper(NzVertexBuffer* vertexBuffer, nzBufferAccess access = nzBufferAccess_ReadWrite);
~NzVertexMapper(); ~NzVertexMapper();
template<typename T> NzSparsePtr<T> GetComponentPtr(nzVertexComponent component); template<typename T> NzSparsePtr<T> GetComponentPtr(nzVertexComponent component);
unsigned int GetVertexCount() const;
void Unmap(); void Unmap();
private: private:
NzBufferMapper<NzVertexBuffer> m_mapper; NzBufferMapper<NzVertexBuffer> m_mapper;
unsigned int m_vertexCount;
}; };
#include <Nazara/Utility/VertexMapper.inl> #include <Nazara/Utility/VertexMapper.inl>

View File

@ -25,12 +25,12 @@ void NzStaticMesh::Center()
{ {
NzVector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f); NzVector3f offset(m_aabb.x + m_aabb.width/2.f, m_aabb.y + m_aabb.height/2.f, m_aabb.z + m_aabb.depth/2.f);
NzVertexMapper mapper(this); NzVertexMapper mapper(m_vertexBuffer);
NzSparsePtr<NzVector3f> position = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position); NzSparsePtr<NzVector3f> position = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = m_vertexBuffer->GetVertexCount();
for (unsigned int i = 0; i < vertexCount; ++i) for (unsigned int i = 0; i < vertexCount; ++i)
position[i] -= offset; *position++ -= offset;
m_aabb.x -= offset.x; m_aabb.x -= offset.x;
m_aabb.y -= offset.y; m_aabb.y -= offset.y;

View File

@ -25,7 +25,7 @@ NzSubMesh::~NzSubMesh() = default;
void NzSubMesh::GenerateNormals() void NzSubMesh::GenerateNormals()
{ {
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = GetVertexCount();
NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal); NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal);
NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position); NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);
@ -56,7 +56,7 @@ void NzSubMesh::GenerateNormals()
void NzSubMesh::GenerateNormalsAndTangents() void NzSubMesh::GenerateNormalsAndTangents()
{ {
NzVertexMapper mapper(this); NzVertexMapper mapper(this);
unsigned int vertexCount = mapper.GetVertexCount(); unsigned int vertexCount = GetVertexCount();
NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal); NzSparsePtr<NzVector3f> normals = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Normal);
NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position); NzSparsePtr<NzVector3f> positions = mapper.GetComponentPtr<NzVector3f>(nzVertexComponent_Position);

View File

@ -10,7 +10,7 @@
#include <Nazara/Utility/SubMesh.hpp> #include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
NzVertexMapper::NzVertexMapper(NzSubMesh* subMesh) NzVertexMapper::NzVertexMapper(NzSubMesh* subMesh, nzBufferAccess access)
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true); NzErrorFlags flags(nzErrorFlag_ThrowException, true);
@ -37,26 +37,17 @@ NzVertexMapper::NzVertexMapper(NzSubMesh* subMesh)
NazaraInternalError("Animation type not handled (0x" + NzString::Number(subMesh->GetAnimationType(), 16) + ')'); NazaraInternalError("Animation type not handled (0x" + NzString::Number(subMesh->GetAnimationType(), 16) + ')');
} }
m_vertexCount = subMesh->GetVertexCount(); m_mapper.Map(buffer, access);
m_mapper.Map(buffer, nzBufferAccess_ReadWrite);
} }
NzVertexMapper::NzVertexMapper(NzVertexBuffer* vertexBuffer, unsigned int vertexCount) NzVertexMapper::NzVertexMapper(NzVertexBuffer* vertexBuffer, nzBufferAccess access)
{ {
NzErrorFlags flags(nzErrorFlag_ThrowException, true); NzErrorFlags flags(nzErrorFlag_ThrowException, true);
m_mapper.Map(vertexBuffer, access);
m_mapper.Map(vertexBuffer, nzBufferAccess_ReadWrite);
m_vertexCount = vertexCount;
} }
NzVertexMapper::~NzVertexMapper() = default; NzVertexMapper::~NzVertexMapper() = default;
unsigned int NzVertexMapper::GetVertexCount() const
{
return m_vertexCount;
}
void NzVertexMapper::Unmap() void NzVertexMapper::Unmap()
{ {
m_mapper.Unmap(); m_mapper.Unmap();