Utility/Buffer: Refactor Buffer classes
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <Nazara/Core/CallOnExit.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||
@@ -17,26 +16,18 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace
|
||||
{
|
||||
AbstractBuffer* SoftwareBufferFactory(Buffer* parent, BufferType type)
|
||||
{
|
||||
return new SoftwareBuffer(parent, type);
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::Buffer(BufferType type) :
|
||||
m_type(type),
|
||||
m_impl(nullptr),
|
||||
m_usage(0),
|
||||
m_size(0)
|
||||
{
|
||||
}
|
||||
|
||||
Buffer::Buffer(BufferType type, unsigned int size, UInt32 storage, BufferUsage usage) :
|
||||
m_type(type),
|
||||
m_impl(nullptr)
|
||||
Buffer::Buffer(BufferType type, UInt32 size, DataStorage storage, BufferUsageFlags usage) :
|
||||
Buffer(type)
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
|
||||
Create(size, storage, usage);
|
||||
}
|
||||
|
||||
@@ -47,27 +38,16 @@ namespace Nz
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool Buffer::CopyContent(const Buffer& buffer)
|
||||
bool Buffer::CopyContent(const BufferRef& buffer)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer must be valid");
|
||||
return false;
|
||||
}
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
NazaraAssert(!buffer && !buffer->IsValid(), "Invalid source buffer");
|
||||
|
||||
if (!buffer.IsValid())
|
||||
{
|
||||
NazaraError("Source buffer must be valid");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
BufferMapper<Buffer> mapper(buffer, BufferAccess_ReadOnly);
|
||||
return Fill(mapper.GetPointer(), 0, buffer.GetSize());
|
||||
BufferMapper<Buffer> mapper(*buffer, BufferAccess_ReadOnly);
|
||||
return Fill(mapper.GetPointer(), 0, buffer->GetSize());
|
||||
}
|
||||
|
||||
bool Buffer::Create(unsigned int size, UInt32 storage, BufferUsage usage)
|
||||
bool Buffer::Create(UInt32 size, DataStorage storage, BufferUsageFlags usage)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
@@ -79,15 +59,14 @@ namespace Nz
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[storage](this, m_type));
|
||||
if (!impl->Create(size, usage))
|
||||
if (!impl->Initialize(size, usage))
|
||||
{
|
||||
NazaraError("Failed to create buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_impl = impl.release();
|
||||
m_impl = std::move(impl);
|
||||
m_size = size;
|
||||
m_storage = storage;
|
||||
m_usage = usage;
|
||||
|
||||
return true; // Si on arrive ici c'est que tout s'est bien passé.
|
||||
@@ -95,125 +74,44 @@ namespace Nz
|
||||
|
||||
void Buffer::Destroy()
|
||||
{
|
||||
if (m_impl)
|
||||
if (!m_impl)
|
||||
{
|
||||
OnBufferDestroy(this);
|
||||
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
m_impl.reset();
|
||||
}
|
||||
}
|
||||
|
||||
bool Buffer::Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard)
|
||||
bool Buffer::Fill(const void* data, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return false;
|
||||
}
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
||||
|
||||
if (offset+size > m_size)
|
||||
{
|
||||
NazaraError("Exceeding buffer size (" + String::Number(offset+size) + " > " + String::Number(m_size) + ')');
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Fill(data, offset, (size == 0) ? m_size-offset : size, forceDiscard);
|
||||
return m_impl->Fill(data, offset, (size == 0) ? m_size - offset : size);
|
||||
}
|
||||
|
||||
AbstractBuffer* Buffer::GetImpl() const
|
||||
void* Buffer::Map(BufferAccess access, UInt32 offset, UInt32 size)
|
||||
{
|
||||
return m_impl;
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
||||
|
||||
return m_impl->Map(access, offset, (size == 0) ? m_size - offset : size);
|
||||
}
|
||||
|
||||
unsigned int Buffer::GetSize() const
|
||||
void* Buffer::Map(BufferAccess access, UInt32 offset, UInt32 size) const
|
||||
{
|
||||
return m_size;
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
NazaraAssert(access == BufferAccess_ReadOnly, "Buffer access must be read-only when used const");
|
||||
NazaraAssert(offset + size <= m_size, "Exceeding buffer size");
|
||||
|
||||
return m_impl->Map(access, offset, (size == 0) ? m_size - offset : size);
|
||||
}
|
||||
|
||||
UInt32 Buffer::GetStorage() const
|
||||
bool Buffer::SetStorage(DataStorage storage)
|
||||
{
|
||||
return m_storage;
|
||||
}
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
|
||||
BufferType Buffer::GetType() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
BufferUsage Buffer::GetUsage() const
|
||||
{
|
||||
return m_usage;
|
||||
}
|
||||
|
||||
bool Buffer::IsHardware() const
|
||||
{
|
||||
return m_storage & DataStorage_Hardware;
|
||||
}
|
||||
|
||||
bool Buffer::IsValid() const
|
||||
{
|
||||
return m_impl != nullptr;
|
||||
}
|
||||
|
||||
void* Buffer::Map(BufferAccess access, unsigned int offset, unsigned int size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+size > m_size)
|
||||
{
|
||||
NazaraError("Exceeding buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Map(access, offset, (size == 0) ? m_size-offset : size);
|
||||
}
|
||||
|
||||
void* Buffer::Map(BufferAccess access, unsigned int offset, unsigned int size) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (access != BufferAccess_ReadOnly)
|
||||
{
|
||||
NazaraError("Buffer access must be read-only when used const");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (offset+size > m_size)
|
||||
{
|
||||
NazaraError("Exceeding buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_impl->Map(access, offset, (size == 0) ? m_size-offset : size);
|
||||
}
|
||||
|
||||
bool Buffer::SetStorage(UInt32 storage)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (m_storage == storage)
|
||||
if (HasStorage(storage))
|
||||
return true;
|
||||
|
||||
if (!IsStorageSupported(storage))
|
||||
@@ -235,70 +133,57 @@ namespace Nz
|
||||
});
|
||||
|
||||
std::unique_ptr<AbstractBuffer> impl(s_bufferFactories[storage](this, m_type));
|
||||
if (!impl->Create(m_size, m_usage))
|
||||
if (!impl->Initialize(m_size, m_usage))
|
||||
{
|
||||
NazaraError("Failed to create buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
CallOnExit destroyImpl([&impl]()
|
||||
{
|
||||
impl->Destroy();
|
||||
});
|
||||
|
||||
if (!impl->Fill(ptr, 0, m_size))
|
||||
{
|
||||
NazaraError("Failed to fill buffer");
|
||||
return false;
|
||||
}
|
||||
|
||||
destroyImpl.Reset();
|
||||
|
||||
unmapMyImpl.CallAndReset();
|
||||
m_impl->Destroy();
|
||||
delete m_impl;
|
||||
|
||||
m_impl = impl.release();
|
||||
m_storage = storage;
|
||||
m_impl = std::move(impl);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Buffer::Unmap() const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_impl)
|
||||
{
|
||||
NazaraError("Buffer not valid");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_impl, "Invalid buffer");
|
||||
|
||||
if (!m_impl->Unmap())
|
||||
NazaraWarning("Failed to unmap buffer (it's content may be undefined)"); ///TODO: Unexpected ?
|
||||
}
|
||||
|
||||
bool Buffer::IsStorageSupported(UInt32 storage)
|
||||
bool Buffer::IsStorageSupported(DataStorage storage)
|
||||
{
|
||||
return s_bufferFactories[storage] != nullptr;
|
||||
}
|
||||
|
||||
void Buffer::SetBufferFactory(UInt32 storage, BufferFactory func)
|
||||
void Buffer::SetBufferFactory(DataStorage storage, BufferFactory func)
|
||||
{
|
||||
s_bufferFactories[storage] = func;
|
||||
}
|
||||
|
||||
bool Buffer::Initialize()
|
||||
{
|
||||
s_bufferFactories[DataStorage_Software] = SoftwareBufferFactory;
|
||||
SetBufferFactory(DataStorage_Software, [](Buffer* parent, BufferType type) -> AbstractBuffer*
|
||||
{
|
||||
return new SoftwareBuffer(parent, type);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Buffer::Uninitialize()
|
||||
{
|
||||
std::memset(s_bufferFactories, 0, (DataStorage_Max+1)*sizeof(Buffer::BufferFactory));
|
||||
std::fill(s_bufferFactories.begin(), s_bufferFactories.end(), nullptr);
|
||||
}
|
||||
|
||||
Buffer::BufferFactory Buffer::s_bufferFactories[DataStorage_Max+1] = {nullptr};
|
||||
std::array<Buffer::BufferFactory, DataStorage_Max + 1> Buffer::s_bufferFactories;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, BufferUsage_Static);
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(false, header.num_tris*3, parameters.storage, 0);
|
||||
|
||||
// Extract triangles data
|
||||
std::vector<MD2_Triangle> triangles(header.num_tris);
|
||||
@@ -159,7 +159,7 @@ namespace Nz
|
||||
}
|
||||
#endif
|
||||
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), header.num_vertices, parameters.storage, BufferUsage_Static);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), header.num_vertices, parameters.storage, 0);
|
||||
StaticMeshRef subMesh = StaticMesh::New(mesh);
|
||||
if (!subMesh->Create(vertexBuffer))
|
||||
{
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace Nz
|
||||
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, BufferUsage_Static);
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage, 0);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent_Skinning), vertexCount, parameters.storage, 0);
|
||||
|
||||
// Index buffer
|
||||
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
|
||||
@@ -236,7 +236,7 @@ namespace Nz
|
||||
// Index buffer
|
||||
bool largeIndices = (vertexCount > std::numeric_limits<UInt16>::max());
|
||||
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage);
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(largeIndices, indexCount, parameters.storage, 0);
|
||||
|
||||
IndexMapper indexMapper(indexBuffer, BufferAccess_DiscardAndWrite);
|
||||
IndexIterator index = indexMapper.begin();
|
||||
@@ -251,7 +251,7 @@ namespace Nz
|
||||
indexMapper.Unmap();
|
||||
|
||||
// Vertex buffer
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage, 0);
|
||||
BufferMapper<VertexBuffer> vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
MeshVertex* vertices = static_cast<MeshVertex*>(vertexMapper.GetPointer());
|
||||
|
||||
@@ -233,8 +233,8 @@ namespace Nz
|
||||
}
|
||||
|
||||
// Création des buffers
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indices.size(), parameters.storage, BufferUsage_Static);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage, BufferUsage_Static);
|
||||
IndexBufferRef indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indices.size(), parameters.storage, 0);
|
||||
VertexBufferRef vertexBuffer = VertexBuffer::New(VertexDeclaration::Get(VertexLayout_XYZ_Normal_UV_Tangent), vertexCount, parameters.storage, 0);
|
||||
|
||||
// Remplissage des indices
|
||||
IndexMapper indexMapper(indexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
@@ -14,19 +14,19 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, Buffer* buffer)
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, BufferRef buffer)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(largeIndices, buffer);
|
||||
Reset(largeIndices, std::move(buffer));
|
||||
}
|
||||
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, Buffer* buffer, unsigned int startOffset, unsigned int endOffset)
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, BufferRef buffer, UInt32 offset, UInt32 size)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(largeIndices, buffer, startOffset, endOffset);
|
||||
Reset(largeIndices, std::move(buffer), offset, size);
|
||||
}
|
||||
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, unsigned int length, UInt32 storage, BufferUsage usage)
|
||||
IndexBuffer::IndexBuffer(bool largeIndices, UInt32 length, DataStorage storage, BufferUsageFlags usage)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(largeIndices, length, storage, usage);
|
||||
@@ -54,105 +54,33 @@ namespace Nz
|
||||
return Nz::ComputeCacheMissCount(mapper.begin(), m_indexCount);
|
||||
}
|
||||
|
||||
bool IndexBuffer::Fill(const void* data, unsigned int startIndex, unsigned int length, bool forceDiscard)
|
||||
bool IndexBuffer::Fill(const void* data, UInt32 startIndex, UInt32 length)
|
||||
{
|
||||
unsigned int stride = GetStride();
|
||||
return FillRaw(data, startIndex*stride, length*stride, forceDiscard);
|
||||
UInt32 stride = GetStride();
|
||||
|
||||
return FillRaw(data, startIndex*stride, length*stride);
|
||||
}
|
||||
|
||||
bool IndexBuffer::FillRaw(const void* data, unsigned int offset, unsigned int size, bool forceDiscard)
|
||||
bool IndexBuffer::FillRaw(const void* data, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
return m_buffer->Fill(data, m_startOffset+offset, size, forceDiscard);
|
||||
return m_buffer->Fill(data, m_startOffset+offset, size);
|
||||
}
|
||||
|
||||
Buffer* IndexBuffer::GetBuffer() const
|
||||
void* IndexBuffer::MapRaw(BufferAccess access, UInt32 offset, UInt32 size)
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
unsigned int IndexBuffer::GetEndOffset() const
|
||||
{
|
||||
return m_endOffset;
|
||||
}
|
||||
|
||||
unsigned int IndexBuffer::GetIndexCount() const
|
||||
{
|
||||
return m_indexCount;
|
||||
}
|
||||
|
||||
unsigned int IndexBuffer::GetStride() const
|
||||
{
|
||||
return (m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
|
||||
}
|
||||
|
||||
unsigned int IndexBuffer::GetStartOffset() const
|
||||
{
|
||||
return m_startOffset;
|
||||
}
|
||||
|
||||
bool IndexBuffer::HasLargeIndices() const
|
||||
{
|
||||
return m_largeIndices;
|
||||
}
|
||||
|
||||
bool IndexBuffer::IsHardware() const
|
||||
{
|
||||
return m_buffer->IsHardware();
|
||||
}
|
||||
|
||||
bool IndexBuffer::IsValid() const
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
void* IndexBuffer::Map(BufferAccess access, unsigned int startIndex, unsigned int length)
|
||||
{
|
||||
unsigned int stride = GetStride();
|
||||
return MapRaw(access, startIndex*stride, length*stride);
|
||||
}
|
||||
|
||||
void* IndexBuffer::Map(BufferAccess access, unsigned int startIndex, unsigned int length) const
|
||||
{
|
||||
unsigned int stride = GetStride();
|
||||
return MapRaw(access, startIndex*stride, length*stride);
|
||||
}
|
||||
|
||||
void* IndexBuffer::MapRaw(BufferAccess access, unsigned int offset, unsigned int size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("No buffer");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
return m_buffer->Map(access, offset, size);
|
||||
}
|
||||
|
||||
void* IndexBuffer::MapRaw(BufferAccess access, unsigned int offset, unsigned int size) const
|
||||
void* IndexBuffer::MapRaw(BufferAccess access, UInt32 offset, UInt32 size) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
return m_buffer->Map(access, offset, size);
|
||||
}
|
||||
@@ -169,52 +97,31 @@ namespace Nz
|
||||
m_buffer.Reset();
|
||||
}
|
||||
|
||||
void IndexBuffer::Reset(bool largeIndices, Buffer* buffer)
|
||||
void IndexBuffer::Reset(bool largeIndices, BufferRef buffer)
|
||||
{
|
||||
Reset(largeIndices, buffer, 0, buffer->GetSize()-1);
|
||||
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
|
||||
|
||||
Reset(largeIndices, buffer, 0, buffer->GetSize());
|
||||
}
|
||||
|
||||
void IndexBuffer::Reset(bool largeIndices, Buffer* buffer, unsigned int startOffset, unsigned int endOffset)
|
||||
void IndexBuffer::Reset(bool largeIndices, BufferRef buffer, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!buffer || !buffer->IsValid())
|
||||
{
|
||||
NazaraError("Buffer is invalid");
|
||||
return;
|
||||
}
|
||||
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(size > 0, "Invalid size");
|
||||
NazaraAssert(offset + size > buffer->GetSize(), "Virtual buffer exceed buffer bounds");
|
||||
|
||||
if (startOffset > endOffset)
|
||||
{
|
||||
NazaraError("Start offset cannot be over end offset");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int bufferSize = buffer->GetSize();
|
||||
if (startOffset >= bufferSize)
|
||||
{
|
||||
NazaraError("Start offset is over buffer size");
|
||||
return;
|
||||
}
|
||||
|
||||
if (endOffset >= bufferSize)
|
||||
{
|
||||
NazaraError("End offset is over buffer size");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int stride = (largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
|
||||
UInt32 stride = static_cast<UInt32>((largeIndices) ? sizeof(UInt32) : sizeof(UInt16));
|
||||
|
||||
m_buffer = buffer;
|
||||
m_endOffset = endOffset;
|
||||
m_indexCount = (endOffset - startOffset) / stride;
|
||||
m_endOffset = offset + size;
|
||||
m_indexCount = size / stride;
|
||||
m_largeIndices = largeIndices;
|
||||
m_startOffset = startOffset;
|
||||
m_startOffset = offset;
|
||||
}
|
||||
|
||||
void IndexBuffer::Reset(bool largeIndices, unsigned int length, UInt32 storage, BufferUsage usage)
|
||||
void IndexBuffer::Reset(bool largeIndices, UInt32 length, DataStorage storage, BufferUsageFlags usage)
|
||||
{
|
||||
unsigned int stride = (largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
|
||||
UInt32 stride = static_cast<UInt32>((largeIndices) ? sizeof(UInt32) : sizeof(UInt16));
|
||||
|
||||
m_endOffset = length * stride;
|
||||
m_indexCount = length;
|
||||
@@ -233,11 +140,6 @@ namespace Nz
|
||||
m_startOffset = indexBuffer.m_startOffset;
|
||||
}
|
||||
|
||||
bool IndexBuffer::SetStorage(UInt32 storage)
|
||||
{
|
||||
return m_buffer->SetStorage(storage);
|
||||
}
|
||||
|
||||
void IndexBuffer::Unmap() const
|
||||
{
|
||||
m_buffer->Unmap();
|
||||
|
||||
@@ -123,8 +123,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputeBoxIndexVertexCount(primitive.box.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
@@ -145,8 +145,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputeConeIndexVertexCount(primitive.cone.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
@@ -167,8 +167,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputePlaneIndexVertexCount(primitive.plane.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
@@ -193,8 +193,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputeCubicSphereIndexVertexCount(primitive.sphere.cubic.subdivision, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_ReadWrite);
|
||||
|
||||
@@ -215,8 +215,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputeIcoSphereIndexVertexCount(primitive.sphere.ico.recursionLevel, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
@@ -237,8 +237,8 @@ namespace Nz
|
||||
unsigned int vertexCount;
|
||||
ComputeUvSphereIndexVertexCount(primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, &indexCount, &vertexCount);
|
||||
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, BufferUsage_Static);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, BufferUsage_Static);
|
||||
indexBuffer = IndexBuffer::New(vertexCount > std::numeric_limits<UInt16>::max(), indexCount, params.storage, 0);
|
||||
vertexBuffer = VertexBuffer::New(declaration, vertexCount, params.storage, 0);
|
||||
|
||||
VertexMapper vertexMapper(vertexBuffer, BufferAccess_WriteOnly);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include <Nazara/Utility/SoftwareBuffer.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
@@ -19,14 +18,20 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
bool SoftwareBuffer::Create(unsigned int size, BufferUsage usage)
|
||||
bool SoftwareBuffer::Fill(const void* data, UInt32 offset, UInt32 size)
|
||||
{
|
||||
NazaraUnused(usage);
|
||||
NazaraAssert(!m_mapped, "Buffer is already mapped");
|
||||
|
||||
std::memcpy(&m_buffer[offset], data, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftwareBuffer::Initialize(UInt32 size, BufferUsageFlags /*usage*/)
|
||||
{
|
||||
// Protect the allocation to prevent a memory exception to escape the function
|
||||
try
|
||||
{
|
||||
m_buffer = new UInt8[size];
|
||||
m_buffer.resize(size);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
@@ -39,25 +44,12 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
void SoftwareBuffer::Destroy()
|
||||
DataStorage SoftwareBuffer::GetStorage() const
|
||||
{
|
||||
delete[] m_buffer;
|
||||
return DataStorage_Software;
|
||||
}
|
||||
|
||||
bool SoftwareBuffer::Fill(const void* data, unsigned int offset, unsigned int size, bool /*forceDiscard*/)
|
||||
{
|
||||
NazaraAssert(!m_mapped, "Buffer is already mapped");
|
||||
|
||||
std::memcpy(&m_buffer[offset], data, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoftwareBuffer::IsHardware() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void* SoftwareBuffer::Map(BufferAccess /*access*/, unsigned int offset, unsigned int /*size*/)
|
||||
void* SoftwareBuffer::Map(BufferAccess /*access*/, UInt32 offset, UInt32 /*size*/)
|
||||
{
|
||||
NazaraAssert(!m_mapped, "Buffer is already mapped");
|
||||
|
||||
|
||||
@@ -9,27 +9,29 @@
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Utility/AbstractBuffer.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class Buffer;
|
||||
|
||||
class SoftwareBuffer : public AbstractBuffer
|
||||
{
|
||||
public:
|
||||
SoftwareBuffer(Buffer* parent, BufferType type);
|
||||
~SoftwareBuffer();
|
||||
|
||||
bool Create(unsigned int size, BufferUsage usage = BufferUsage_Static);
|
||||
void Destroy();
|
||||
bool Fill(const void* data, UInt32 offset, UInt32 size) override;
|
||||
|
||||
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard);
|
||||
bool Initialize(UInt32 size, BufferUsageFlags usage) override;
|
||||
|
||||
bool IsHardware() const;
|
||||
DataStorage GetStorage() const override;
|
||||
|
||||
void* Map(BufferAccess access, unsigned int offset = 0, unsigned int size = 0);
|
||||
bool Unmap();
|
||||
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) override;
|
||||
bool Unmap() override;
|
||||
|
||||
private:
|
||||
UInt8* m_buffer;
|
||||
std::vector<UInt8> m_buffer;
|
||||
bool m_mapped;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,22 +10,22 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
VertexBuffer::VertexBuffer(const VertexDeclaration* vertexDeclaration, Buffer* buffer)
|
||||
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(vertexDeclaration, buffer);
|
||||
Reset(std::move(vertexDeclaration), std::move(buffer));
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(const VertexDeclaration* vertexDeclaration, Buffer* buffer, unsigned int startOffset, unsigned int endOffset)
|
||||
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, UInt32 offset, UInt32 size)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(vertexDeclaration, buffer, startOffset, endOffset);
|
||||
Reset(std::move(vertexDeclaration), std::move(buffer), offset, size);
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(const VertexDeclaration* vertexDeclaration, unsigned int length, UInt32 storage, BufferUsage usage)
|
||||
VertexBuffer::VertexBuffer(VertexDeclarationConstRef vertexDeclaration, UInt32 length, DataStorage storage, BufferUsageFlags usage)
|
||||
{
|
||||
ErrorFlags(ErrorFlag_ThrowException, true);
|
||||
Reset(vertexDeclaration, length, storage, usage);
|
||||
Reset(std::move(vertexDeclaration), length, storage, usage);
|
||||
}
|
||||
|
||||
VertexBuffer::VertexBuffer(const VertexBuffer& vertexBuffer) :
|
||||
@@ -43,135 +43,49 @@ namespace Nz
|
||||
OnVertexBufferRelease(this);
|
||||
}
|
||||
|
||||
bool VertexBuffer::Fill(const void* data, unsigned int startVertex, unsigned int length, bool forceDiscard)
|
||||
bool VertexBuffer::Fill(const void* data, UInt32 startVertex, UInt32 length)
|
||||
{
|
||||
std::size_t stride = m_vertexDeclaration->GetStride();
|
||||
return FillRaw(data, startVertex*stride, length*stride, forceDiscard);
|
||||
UInt32 stride = static_cast<UInt32>(m_vertexDeclaration->GetStride());
|
||||
return FillRaw(data, startVertex*stride, length*stride);
|
||||
}
|
||||
|
||||
bool VertexBuffer::FillRaw(const void* data, unsigned int offset, unsigned int size, bool forceDiscard)
|
||||
bool VertexBuffer::FillRaw(const void* data, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("No buffer");
|
||||
return false;
|
||||
}
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_buffer->Fill(data, m_startOffset+offset, size, forceDiscard);
|
||||
return m_buffer->Fill(data, m_startOffset + offset, size);
|
||||
}
|
||||
|
||||
Buffer* VertexBuffer::GetBuffer() const
|
||||
void* VertexBuffer::Map(BufferAccess access, UInt32 startVertex, UInt32 length)
|
||||
{
|
||||
return m_buffer;
|
||||
}
|
||||
|
||||
unsigned int VertexBuffer::GetEndOffset() const
|
||||
{
|
||||
return m_endOffset;
|
||||
}
|
||||
|
||||
unsigned int VertexBuffer::GetStartOffset() const
|
||||
{
|
||||
return m_startOffset;
|
||||
}
|
||||
|
||||
unsigned int VertexBuffer::GetStride() const
|
||||
{
|
||||
return m_vertexDeclaration->GetStride();
|
||||
}
|
||||
|
||||
unsigned int VertexBuffer::GetVertexCount() const
|
||||
{
|
||||
return m_vertexCount;
|
||||
}
|
||||
|
||||
const VertexDeclaration* VertexBuffer::GetVertexDeclaration() const
|
||||
{
|
||||
return m_vertexDeclaration;
|
||||
}
|
||||
|
||||
bool VertexBuffer::IsHardware() const
|
||||
{
|
||||
return m_buffer->IsHardware();
|
||||
}
|
||||
|
||||
bool VertexBuffer::IsValid() const
|
||||
{
|
||||
return m_buffer && m_vertexDeclaration;
|
||||
}
|
||||
|
||||
void* VertexBuffer::Map(BufferAccess access, unsigned int startVertex, unsigned int length)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_vertexDeclaration)
|
||||
{
|
||||
NazaraError("No vertex declaration");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int stride = m_vertexDeclaration->GetStride();
|
||||
UInt32 stride = static_cast<UInt32>(m_vertexDeclaration->GetStride());
|
||||
|
||||
return MapRaw(access, startVertex*stride, length*stride);
|
||||
}
|
||||
|
||||
void* VertexBuffer::Map(BufferAccess access, unsigned int startVertex, unsigned int length) const
|
||||
void* VertexBuffer::Map(BufferAccess access, UInt32 startVertex, UInt32 length) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("No buffer");
|
||||
return nullptr;
|
||||
}
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_vertexDeclaration, "Invalid vertex declaration");
|
||||
|
||||
if (!m_vertexDeclaration)
|
||||
{
|
||||
NazaraError("No vertex declaration");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int stride = m_vertexDeclaration->GetStride();
|
||||
UInt32 stride = static_cast<UInt32>(m_vertexDeclaration->GetStride());
|
||||
|
||||
return MapRaw(access, startVertex*stride, length*stride);
|
||||
}
|
||||
|
||||
void* VertexBuffer::MapRaw(BufferAccess access, unsigned int offset, unsigned int size)
|
||||
void* VertexBuffer::MapRaw(BufferAccess access, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!m_buffer)
|
||||
{
|
||||
NazaraError("No buffer");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
return m_buffer->Map(access, offset, size);
|
||||
}
|
||||
|
||||
void* VertexBuffer::MapRaw(BufferAccess access, unsigned int offset, unsigned int size) const
|
||||
void* VertexBuffer::MapRaw(BufferAccess access, UInt32 offset, UInt32 size) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (m_startOffset + offset + size > m_endOffset)
|
||||
{
|
||||
NazaraError("Exceeding virtual buffer size");
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(m_buffer && m_buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(m_startOffset + offset + size <= m_endOffset, "Exceeding virtual buffer size");
|
||||
|
||||
return m_buffer->Map(access, offset, size);
|
||||
}
|
||||
@@ -182,55 +96,35 @@ namespace Nz
|
||||
m_vertexDeclaration.Reset();
|
||||
}
|
||||
|
||||
void VertexBuffer::Reset(const VertexDeclaration* vertexDeclaration, Buffer* buffer)
|
||||
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer)
|
||||
{
|
||||
Reset(vertexDeclaration, buffer, 0, buffer->GetSize()-1);
|
||||
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
|
||||
|
||||
UInt32 size = buffer->GetSize();
|
||||
Reset(std::move(vertexDeclaration), std::move(buffer), 0, size);
|
||||
}
|
||||
|
||||
void VertexBuffer::Reset(const VertexDeclaration* vertexDeclaration, Buffer* buffer, unsigned int startOffset, unsigned int endOffset)
|
||||
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, BufferRef buffer, UInt32 offset, UInt32 size)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!buffer || !buffer->IsValid())
|
||||
{
|
||||
NazaraError("Invalid buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
if (startOffset > endOffset)
|
||||
{
|
||||
NazaraError("Start offset cannot be over end offset");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int bufferSize = buffer->GetSize();
|
||||
if (startOffset >= bufferSize)
|
||||
{
|
||||
NazaraError("Start offset is over buffer size");
|
||||
return;
|
||||
}
|
||||
|
||||
if (endOffset >= bufferSize)
|
||||
{
|
||||
NazaraError("End offset is over buffer size");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(buffer && buffer->IsValid(), "Invalid buffer");
|
||||
NazaraAssert(size > 0, "Invalid size");
|
||||
NazaraAssert(offset + size <= buffer->GetSize(), "Virtual buffer exceed buffer bounds");
|
||||
|
||||
m_buffer = buffer;
|
||||
m_endOffset = endOffset;
|
||||
m_startOffset = startOffset;
|
||||
m_vertexCount = (vertexDeclaration) ? ((endOffset - startOffset) / vertexDeclaration->GetStride()) : 0;
|
||||
m_endOffset = offset + size;
|
||||
m_startOffset = offset;
|
||||
m_vertexCount = (vertexDeclaration) ? (size / static_cast<UInt32>(vertexDeclaration->GetStride())) : 0;
|
||||
m_vertexDeclaration = vertexDeclaration;
|
||||
}
|
||||
|
||||
void VertexBuffer::Reset(const VertexDeclaration* vertexDeclaration, unsigned int length, UInt32 storage, BufferUsage usage)
|
||||
void VertexBuffer::Reset(VertexDeclarationConstRef vertexDeclaration, UInt32 length, DataStorage storage, BufferUsageFlags usage)
|
||||
{
|
||||
m_endOffset = length * ((vertexDeclaration) ? vertexDeclaration->GetStride() : 1);
|
||||
m_endOffset = length * ((vertexDeclaration) ? static_cast<UInt32>(vertexDeclaration->GetStride()) : 1);
|
||||
m_startOffset = 0;
|
||||
m_vertexCount = length;
|
||||
m_vertexDeclaration = std::move(vertexDeclaration);
|
||||
|
||||
m_buffer = Buffer::New(BufferType_Vertex, m_endOffset, storage, usage);
|
||||
m_vertexDeclaration = vertexDeclaration;
|
||||
}
|
||||
|
||||
void VertexBuffer::Reset(const VertexBuffer& vertexBuffer)
|
||||
@@ -242,23 +136,12 @@ namespace Nz
|
||||
m_vertexDeclaration = vertexBuffer.m_vertexDeclaration;
|
||||
}
|
||||
|
||||
bool VertexBuffer::SetStorage(UInt32 storage)
|
||||
void VertexBuffer::SetVertexDeclaration(VertexDeclarationConstRef vertexDeclaration)
|
||||
{
|
||||
return m_buffer->SetStorage(storage);
|
||||
}
|
||||
NazaraAssert(vertexDeclaration, "Invalid vertex declaration");
|
||||
|
||||
void VertexBuffer::SetVertexDeclaration(const VertexDeclaration* vertexDeclaration)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!vertexDeclaration)
|
||||
{
|
||||
NazaraError("Vertex declaration is invalid");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_vertexCount = (m_endOffset - m_startOffset)/vertexDeclaration->GetStride();
|
||||
m_vertexDeclaration = vertexDeclaration;
|
||||
m_vertexCount = (m_endOffset - m_startOffset) / static_cast<UInt32>(vertexDeclaration->GetStride());
|
||||
m_vertexDeclaration = std::move(vertexDeclaration);
|
||||
}
|
||||
|
||||
void VertexBuffer::Unmap() const
|
||||
|
||||
Reference in New Issue
Block a user