Removed Keyframe mesh lock system (useless)
Former-commit-id: b7e661274510836cb46eb98b6b9e7135d21a4820
This commit is contained in:
parent
c73d10ab29
commit
c65f0e9f7e
|
|
@ -21,7 +21,7 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
||||||
NzKeyframeMesh(const NzMesh* parent);
|
NzKeyframeMesh(const NzMesh* parent);
|
||||||
virtual ~NzKeyframeMesh();
|
virtual ~NzKeyframeMesh();
|
||||||
|
|
||||||
bool Create(NzVertexBuffer* vertexBuffer, unsigned int frameCount, bool lock = true);
|
bool Create(NzVertexBuffer* vertexBuffer, unsigned int frameCount);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
@ -39,15 +39,11 @@ class NAZARA_API NzKeyframeMesh final : public NzSubMesh
|
||||||
bool IsAnimated() const override;
|
bool IsAnimated() const override;
|
||||||
bool IsValid();
|
bool IsValid();
|
||||||
|
|
||||||
bool Lock(nzBufferAccess access) const;
|
|
||||||
|
|
||||||
void SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb);
|
void SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb);
|
||||||
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
void SetIndexBuffer(const NzIndexBuffer* indexBuffer);
|
||||||
void SetVertex(unsigned int frameIndex, unsigned int vertexIndex, const NzMeshVertex& source);
|
void SetVertex(unsigned int frameIndex, unsigned int vertexIndex, const NzMeshVertex& source);
|
||||||
void SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv);
|
void SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv);
|
||||||
|
|
||||||
void Unlock() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
void InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
struct NzKeyframeMeshImpl
|
struct NzKeyframeMeshImpl
|
||||||
{
|
{
|
||||||
nzBufferAccess lockAccess;
|
|
||||||
NzAxisAlignedBox* aabb;
|
NzAxisAlignedBox* aabb;
|
||||||
NzMeshVertex* lockBuffer;
|
|
||||||
NzVector2f* uv;
|
NzVector2f* uv;
|
||||||
NzVector3f* normals;
|
NzVector3f* normals;
|
||||||
NzVector3f* positions;
|
NzVector3f* positions;
|
||||||
|
|
@ -22,7 +20,6 @@ struct NzKeyframeMeshImpl
|
||||||
const NzIndexBuffer* indexBuffer = nullptr;
|
const NzIndexBuffer* indexBuffer = nullptr;
|
||||||
NzVertexBuffer* vertexBuffer;
|
NzVertexBuffer* vertexBuffer;
|
||||||
unsigned int frameCount;
|
unsigned int frameCount;
|
||||||
unsigned int lockLevel = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NzKeyframeMesh::NzKeyframeMesh(const NzMesh* parent) :
|
NzKeyframeMesh::NzKeyframeMesh(const NzMesh* parent) :
|
||||||
|
|
@ -35,7 +32,7 @@ NzKeyframeMesh::~NzKeyframeMesh()
|
||||||
Destroy();
|
Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzKeyframeMesh::Create(NzVertexBuffer* vertexBuffer, unsigned int frameCount, bool lock)
|
bool NzKeyframeMesh::Create(NzVertexBuffer* vertexBuffer, unsigned int frameCount)
|
||||||
{
|
{
|
||||||
Destroy();
|
Destroy();
|
||||||
|
|
||||||
|
|
@ -73,14 +70,6 @@ bool NzKeyframeMesh::Create(NzVertexBuffer* vertexBuffer, unsigned int frameCoun
|
||||||
m_impl->tangents = new NzVector3f[frameCount*vertexCount];
|
m_impl->tangents = new NzVector3f[frameCount*vertexCount];
|
||||||
m_impl->uv = new NzVector2f[vertexCount];
|
m_impl->uv = new NzVector2f[vertexCount];
|
||||||
|
|
||||||
if (lock && !Lock(nzBufferAccess_DiscardAndWrite))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to lock buffer");
|
|
||||||
Destroy();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
NotifyCreated();
|
NotifyCreated();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -276,47 +265,6 @@ bool NzKeyframeMesh::IsValid()
|
||||||
return m_impl != nullptr;
|
return m_impl != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzKeyframeMesh::Lock(nzBufferAccess access) const
|
|
||||||
{
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Keyframe mesh not created");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (m_impl->lockLevel == 0)
|
|
||||||
{
|
|
||||||
m_impl->lockBuffer = reinterpret_cast<NzMeshVertex*>(m_impl->vertexBuffer->Map(access));
|
|
||||||
if (!m_impl->lockBuffer)
|
|
||||||
{
|
|
||||||
NazaraError("Failed to lock vertex buffer");
|
|
||||||
m_impl->lockLevel = 0;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_impl->lockAccess = access;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
///FIXME: Vérifier cette condition
|
|
||||||
if (m_impl->lockAccess != access &&
|
|
||||||
(m_impl->lockAccess != nzBufferAccess_ReadWrite || access != nzBufferAccess_WriteOnly) &&
|
|
||||||
(m_impl->lockAccess != nzBufferAccess_ReadWrite || access != nzBufferAccess_ReadOnly) &&
|
|
||||||
(m_impl->lockAccess != nzBufferAccess_DiscardAndWrite || access != nzBufferAccess_WriteOnly))
|
|
||||||
{
|
|
||||||
NazaraError("Vertex buffer already locked by an incompatible lock access");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_impl->lockLevel++;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzKeyframeMesh::SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb)
|
void NzKeyframeMesh::SetAABB(unsigned int frameIndex, const NzAxisAlignedBox& aabb)
|
||||||
{
|
{
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
|
|
@ -407,29 +355,6 @@ void NzKeyframeMesh::SetTexCoords(unsigned int vertexIndex, const NzVector2f& uv
|
||||||
m_impl->uv[vertexIndex] = uv;
|
m_impl->uv[vertexIndex] = uv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NzKeyframeMesh::Unlock() const
|
|
||||||
{
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
|
||||||
if (!m_impl)
|
|
||||||
{
|
|
||||||
NazaraError("Keyframe mesh not created");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_impl->lockLevel == 0)
|
|
||||||
{
|
|
||||||
NazaraWarning("Unlock called on non-locked texture");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (--m_impl->lockLevel == 0)
|
|
||||||
{
|
|
||||||
if (!m_impl->vertexBuffer->Unmap())
|
|
||||||
NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const
|
void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, float interpolation) const
|
||||||
{
|
{
|
||||||
#ifdef NAZARA_DEBUG
|
#ifdef NAZARA_DEBUG
|
||||||
|
|
@ -443,7 +368,8 @@ void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, f
|
||||||
// Interpolation de l'AABB
|
// Interpolation de l'AABB
|
||||||
m_impl->aabb[0] = NzAxisAlignedBox::Lerp(m_impl->aabb[frameA+1], m_impl->aabb[frameB+1], interpolation);
|
m_impl->aabb[0] = NzAxisAlignedBox::Lerp(m_impl->aabb[frameA+1], m_impl->aabb[frameB+1], interpolation);
|
||||||
|
|
||||||
if (!Lock(nzBufferAccess_DiscardAndWrite))
|
NzMeshVertex* vertex = reinterpret_cast<NzMeshVertex*>(m_impl->vertexBuffer->Map(nzBufferAccess_DiscardAndWrite));
|
||||||
|
if (!vertex)
|
||||||
{
|
{
|
||||||
NazaraError("Failed to lock vertex buffer");
|
NazaraError("Failed to lock vertex buffer");
|
||||||
return;
|
return;
|
||||||
|
|
@ -455,7 +381,6 @@ void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, f
|
||||||
frameA *= vertexCount;
|
frameA *= vertexCount;
|
||||||
frameB *= vertexCount;
|
frameB *= vertexCount;
|
||||||
|
|
||||||
NzMeshVertex* vertex = m_impl->lockBuffer;
|
|
||||||
for (unsigned int i = 0; i < vertexCount; ++i)
|
for (unsigned int i = 0; i < vertexCount; ++i)
|
||||||
{
|
{
|
||||||
vertex->normal = NzVector3f::Lerp(m_impl->positions[frameA+i], m_impl->positions[frameB+i], interpolation);
|
vertex->normal = NzVector3f::Lerp(m_impl->positions[frameA+i], m_impl->positions[frameB+i], interpolation);
|
||||||
|
|
@ -466,5 +391,5 @@ void NzKeyframeMesh::InterpolateImpl(unsigned int frameA, unsigned int frameB, f
|
||||||
vertex++;
|
vertex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unlock();
|
m_impl->vertexBuffer->Unmap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -209,8 +209,6 @@ namespace
|
||||||
subMesh->SetAABB(f, aabb);
|
subMesh->SetAABB(f, aabb);
|
||||||
}
|
}
|
||||||
|
|
||||||
subMesh->Unlock();
|
|
||||||
|
|
||||||
subMesh->SetMaterialIndex(0);
|
subMesh->SetMaterialIndex(0);
|
||||||
mesh->AddSubMesh(subMesh.release());
|
mesh->AddSubMesh(subMesh.release());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue