Big buffer refactor

Replaced RenderBuffer class, replaced AbstractBuffer by Buffer
This commit is contained in:
Jérôme Leclercq
2022-01-23 00:05:08 +01:00
parent 754a0016c7
commit 29786765c6
98 changed files with 699 additions and 1427 deletions

View File

@@ -1,33 +0,0 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_UTILITY_ABSTRACTBUFFER_HPP
#define NAZARA_UTILITY_ABSTRACTBUFFER_HPP
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
namespace Nz
{
class NAZARA_UTILITY_API AbstractBuffer
{
public:
AbstractBuffer() = default;
virtual ~AbstractBuffer();
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
virtual bool Initialize(UInt64 size, BufferUsageFlags usage) = 0;
virtual UInt64 GetSize() const = 0;
virtual DataStorage GetStorage() const = 0;
virtual void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) = 0;
virtual bool Unmap() = 0;
};
}
#endif // NAZARA_UTILITY_ABSTRACTBUFFER_HPP

View File

@@ -44,7 +44,7 @@ namespace Nz
NAZARA_UTILITY_API Boxf ComputeAABB(SparsePtr<const Vector3f> positionPtr, std::size_t vertexCount);
NAZARA_UTILITY_API void ComputeBoxIndexVertexCount(const Vector3ui& subdivision, std::size_t* indexCount, std::size_t* vertexCount);
NAZARA_UTILITY_API unsigned int ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount);
NAZARA_UTILITY_API UInt64 ComputeCacheMissCount(IndexIterator indices, std::size_t indexCount);
NAZARA_UTILITY_API void ComputeConeIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
NAZARA_UTILITY_API void ComputeCubicSphereIndexVertexCount(unsigned int subdivision, std::size_t* indexCount, std::size_t* vertexCount);
NAZARA_UTILITY_API void ComputeIcoSphereIndexVertexCount(unsigned int recursionLevel, std::size_t* indexCount, std::size_t* vertexCount);

View File

@@ -8,68 +8,45 @@
#define NAZARA_UTILITY_BUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <array>
#include <functional>
#include <memory>
namespace Nz
{
class Buffer;
using BufferFactory = std::function<std::shared_ptr<Buffer>(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData)>;
class NAZARA_UTILITY_API Buffer
{
friend class Utility;
public:
using BufferFactory = std::function<std::unique_ptr<AbstractBuffer>(Buffer* parent, BufferType type)>;
Buffer(BufferType type);
Buffer(BufferType type, UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
inline Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage);
Buffer(const Buffer&) = delete;
Buffer(Buffer&&) = delete;
~Buffer() = default;
virtual ~Buffer();
bool CopyContent(const Buffer& buffer);
std::shared_ptr<Buffer> CopyContent(const BufferFactory& bufferFactory);
bool Create(UInt32 size, DataStorage storage = DataStorage::Software, BufferUsageFlags usage = 0);
void Destroy();
virtual bool Fill(const void* data, UInt64 offset, UInt64 size) = 0;
bool Fill(const void* data, UInt32 offset, UInt32 size);
inline AbstractBuffer* GetImpl() const;
inline UInt32 GetSize() const;
inline UInt64 GetSize() const;
inline DataStorage GetStorage() const;
inline BufferType GetType() const;
inline BufferUsageFlags GetUsage() const;
inline BufferUsageFlags GetUsageFlags() const;
inline bool HasStorage(DataStorage storage) const;
inline bool IsValid() const;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
bool SetStorage(DataStorage storage);
void Unmap() const;
virtual void* Map(UInt64 offset, UInt64 size) = 0;
virtual bool Unmap() = 0;
Buffer& operator=(const Buffer&) = delete;
Buffer& operator=(Buffer&&) = delete;
static bool IsStorageSupported(DataStorage storage);
static void SetBufferFactory(DataStorage storage, BufferFactory func);
private:
static bool Initialize();
static void Uninitialize();
std::unique_ptr<AbstractBuffer> m_impl;
BufferType m_type;
BufferUsageFlags m_usage;
UInt32 m_size;
static std::array<BufferFactory, DataStorageCount> s_bufferFactories;
DataStorage m_storage;
UInt64 m_size;
};
}

View File

@@ -8,19 +8,22 @@
namespace Nz
{
inline AbstractBuffer* Buffer::GetImpl() const
inline Buffer::Buffer(DataStorage storage, BufferType type, UInt64 size, BufferUsageFlags usage) :
m_type(type),
m_usage(usage),
m_storage(storage),
m_size(size)
{
return m_impl.get();
}
inline UInt32 Buffer::GetSize() const
inline UInt64 Nz::Buffer::GetSize() const
{
return m_size;
}
inline DataStorage Buffer::GetStorage() const
{
return m_impl->GetStorage();
return m_storage;
}
inline BufferType Buffer::GetType() const
@@ -28,20 +31,10 @@ namespace Nz
return m_type;
}
inline BufferUsageFlags Buffer::GetUsage() const
inline BufferUsageFlags Buffer::GetUsageFlags() const
{
return m_usage;
}
inline bool Buffer::HasStorage(DataStorage storage) const
{
return GetStorage() == storage;
}
inline bool Buffer::IsValid() const
{
return m_impl != nullptr;
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -16,16 +16,10 @@ namespace Nz
{
public:
BufferMapper();
BufferMapper(T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
BufferMapper(T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
BufferMapper(const T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
BufferMapper(const T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
BufferMapper(T& buffer, UInt64 offset, UInt64 length);
~BufferMapper();
bool Map(T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
bool Map(T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
bool Map(const T* buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
bool Map(const T& buffer, BufferAccess access, unsigned int offset = 0, unsigned int length = 0);
bool Map(T& buffer, UInt64 offset, UInt64 length);
const T* GetBuffer() const;
void* GetPointer() const;
@@ -33,7 +27,7 @@ namespace Nz
void Unmap();
private:
const T* m_buffer;
T* m_buffer;
void* m_ptr;
};
}

View File

@@ -17,33 +17,13 @@ namespace Nz
}
template<typename T>
BufferMapper<T>::BufferMapper(T* buffer, BufferAccess access, unsigned int offset, unsigned int length) :
BufferMapper<T>::BufferMapper(T& buffer, UInt64 offset, UInt64 length) :
m_buffer(nullptr)
{
if (!Map(buffer, access, offset, length))
if (!Map(buffer, offset, length))
NazaraError("Failed to map buffer"); ///TODO: Unexpected
}
template<typename T>
BufferMapper<T>::BufferMapper(T& buffer, BufferAccess access, unsigned int offset, unsigned int length) :
BufferMapper(&buffer, access, offset, length)
{
}
template<typename T>
BufferMapper<T>::BufferMapper(const T* buffer, BufferAccess access, unsigned int offset, unsigned int length) :
m_buffer(nullptr)
{
if (!Map(buffer, access, offset, length))
NazaraError("Failed to map buffer"); ///TODO: Unexpected
}
template<typename T>
BufferMapper<T>::BufferMapper(const T& buffer, BufferAccess access, unsigned int offset, unsigned int length) :
BufferMapper(&buffer, access, offset, length)
{
}
template<typename T>
BufferMapper<T>::~BufferMapper()
{
@@ -64,63 +44,21 @@ namespace Nz
}
template<typename T>
bool BufferMapper<T>::Map(T* buffer, BufferAccess access, unsigned int offset, unsigned int length)
bool BufferMapper<T>::Map(T& buffer, UInt64 offset, UInt64 length)
{
Unmap();
#if NAZARA_UTILITY_SAFE
if (!buffer)
m_buffer = &buffer;
m_ptr = buffer.Map(offset, length);
if (!m_ptr)
{
NazaraError("Buffer must be valid");
m_ptr = nullptr;
NazaraError("Failed to map buffer"); ///TODO: Unexpected
return false;
}
#endif
m_buffer = buffer;
m_ptr = buffer->Map(access, offset, length);
if (!m_ptr)
NazaraError("Failed to map buffer"); ///TODO: Unexpected
return true;
}
template<typename T>
bool BufferMapper<T>::Map(T& buffer, BufferAccess access, unsigned int offset, unsigned int length)
{
return Map(&buffer, access, offset, length);
}
template<typename T>
bool BufferMapper<T>::Map(const T* buffer, BufferAccess access, unsigned int offset, unsigned int length)
{
Unmap();
#if NAZARA_UTILITY_SAFE
if (!buffer)
{
NazaraError("Buffer must be valid");
m_ptr = nullptr;
return false;
}
#endif
m_buffer = buffer;
m_ptr = buffer->Map(access, offset, length);
if (!m_ptr)
NazaraError("Failed to map buffer"); ///TODO: Unexpected
return true;
}
template<typename T>
bool BufferMapper<T>::Map(const T& buffer, BufferAccess access, unsigned int offset, unsigned int length)
{
return Map(&buffer, access, offset, length);
}
template<typename T>
void BufferMapper<T>::Unmap()
{

View File

@@ -70,7 +70,9 @@ namespace Nz
DeviceLocal,
DirectMapping,
Dynamic,
Read,
PersistentMapping,
Write,
Max = DirectMapping
};

View File

@@ -17,40 +17,34 @@ namespace Nz
public:
IndexBuffer() = default;
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer);
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
IndexBuffer(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
IndexBuffer(bool largeIndices, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
IndexBuffer(bool largeIndices, UInt64 indexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
IndexBuffer(const IndexBuffer&) = default;
IndexBuffer(IndexBuffer&&) noexcept = default;
~IndexBuffer() = default;
unsigned int ComputeCacheMissCount() const;
unsigned int ComputeCacheMissCount();
bool Fill(const void* data, std::size_t startIndex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
bool Fill(const void* data, UInt64 startIndex, UInt64 length);
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetIndexCount() const;
inline std::size_t GetStride() const;
inline std::size_t GetStartOffset() const;
inline UInt64 GetEndOffset() const;
inline UInt64 GetIndexCount() const;
inline UInt64 GetStride() const;
inline UInt64 GetStartOffset() const;
inline bool HasLargeIndices() const;
inline bool IsValid() const;
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
inline void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
inline void* Map(UInt64 startIndex, UInt64 length);
inline void* Map(UInt64 startIndex, UInt64 length) const;
void* MapRaw(UInt64 offset, UInt64 size);
void* MapRaw(UInt64 offset, UInt64 size) const;
void Optimize();
void Reset();
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer);
void Reset(bool largeIndices, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
void Reset(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const IndexBuffer& indexBuffer);
void Unmap() const;
IndexBuffer& operator=(const IndexBuffer&) = default;
@@ -58,9 +52,9 @@ namespace Nz
private:
std::shared_ptr<Buffer> m_buffer;
std::size_t m_endOffset;
std::size_t m_indexCount;
std::size_t m_startOffset;
UInt64 m_endOffset;
UInt64 m_indexCount;
UInt64 m_startOffset;
bool m_largeIndices;
};
}

View File

@@ -13,22 +13,22 @@ namespace Nz
return m_buffer;
}
inline std::size_t IndexBuffer::GetEndOffset() const
inline UInt64 IndexBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline std::size_t IndexBuffer::GetIndexCount() const
inline UInt64 IndexBuffer::GetIndexCount() const
{
return m_indexCount;
}
inline std::size_t IndexBuffer::GetStride() const
inline UInt64 IndexBuffer::GetStride() const
{
return static_cast<std::size_t>((m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16));
return (m_largeIndices) ? sizeof(UInt32) : sizeof(UInt16);
}
inline std::size_t IndexBuffer::GetStartOffset() const
inline UInt64 IndexBuffer::GetStartOffset() const
{
return m_startOffset;
}
@@ -43,16 +43,16 @@ namespace Nz
return m_buffer != nullptr;
}
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length)
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length)
{
std::size_t stride = GetStride();
return MapRaw(access, startIndex*stride, length*stride);
UInt64 stride = GetStride();
return MapRaw(startIndex * stride, length * stride);
}
inline void* IndexBuffer::Map(BufferAccess access, std::size_t startIndex, std::size_t length) const
inline void* IndexBuffer::Map(UInt64 startIndex, UInt64 length) const
{
std::size_t stride = GetStride();
return MapRaw(access, startIndex*stride, length*stride);
UInt64 stride = GetStride();
return MapRaw(startIndex * stride, length * stride);
}
}

View File

@@ -19,10 +19,8 @@ namespace Nz
class NAZARA_UTILITY_API IndexMapper
{
public:
IndexMapper(IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadWrite, std::size_t indexCount = 0);
IndexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
IndexMapper(const IndexBuffer& indexBuffer, BufferAccess access = BufferAccess::ReadOnly, std::size_t indexCount = 0);
IndexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
IndexMapper(IndexBuffer& indexBuffer, std::size_t indexCount = 0);
IndexMapper(SubMesh& subMes);
~IndexMapper() = default;
UInt32 Get(std::size_t i) const;

View File

@@ -18,6 +18,7 @@
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/SoftwareBuffer.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VertexStruct.hpp>
@@ -28,20 +29,35 @@ namespace Nz
{
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
{
MeshParams();
// How buffer will be allocated (by default in RAM)
BufferFactory bufferFactory = &SoftwareBufferFactory;
BufferUsageFlags indexBufferFlags = 0; ///< Buffer usage flags used to build the index buffers
BufferUsageFlags vertexBufferFlags = 0; ///< Buffer usage flags used to build the vertex buffers
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
DataStorage storage = DataStorage::Hardware; ///< The place where the buffers will be allocated
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
bool animated = true; ///< If true, will load an animated version of the model if possible
bool center = false; ///< If true, will center the mesh vertices around the origin
// Buffer usage flags used to build the index buffers
BufferUsageFlags indexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
// Buffer usage flags used to build the vertex buffers
BufferUsageFlags vertexBufferFlags = BufferUsage::DirectMapping | BufferUsage::Read | BufferUsage::Write;
// A matrix which will transform every vertex position
Matrix4f matrix = Matrix4f::Identity();
// Offset to apply on the texture coordinates (not scaled)
Vector2f texCoordOffset = {0.f, 0.f};
// Scale to apply on the texture coordinates
Vector2f texCoordScale = {1.f, 1.f};
// If true, will load an animated version of the model if possible
bool animated = true;
// If true, will center the mesh vertices around the origin
bool center = false;
// Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
#ifndef NAZARA_DEBUG
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
bool optimizeIndexBuffers = true;
#else
bool optimizeIndexBuffers = false; ///< Since this optimization take a lot of time, especially in debug mode, don't enable it by default in debug.
bool optimizeIndexBuffers = false;
#endif
/* The declaration must have a Vector3f position component enabled

View File

@@ -17,12 +17,12 @@ namespace Nz
class NAZARA_UTILITY_API SkeletalMesh final : public SubMesh
{
public:
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
SkeletalMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
~SkeletalMesh() = default;
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final;
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
std::size_t GetVertexCount() const override;
@@ -30,11 +30,11 @@ namespace Nz
bool IsValid() const;
void SetAABB(const Boxf& aabb);
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
private:
Boxf m_aabb;
std::shared_ptr<const IndexBuffer> m_indexBuffer;
std::shared_ptr<IndexBuffer> m_indexBuffer;
std::shared_ptr<VertexBuffer> m_vertexBuffer;
};
}

View File

@@ -8,34 +8,30 @@
#define NAZARA_UTILITY_SOFTWAREBUFFER_HPP
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <vector>
namespace Nz
{
class Buffer;
class NAZARA_UTILITY_API SoftwareBuffer : public AbstractBuffer
class NAZARA_UTILITY_API SoftwareBuffer : public Buffer
{
public:
SoftwareBuffer(Buffer* parent, BufferType type);
SoftwareBuffer(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData);
~SoftwareBuffer() = default;
bool Fill(const void* data, UInt64 offset, UInt64 size) override;
bool Initialize(UInt64 size, BufferUsageFlags usage) override;
const UInt8* GetData() const;
UInt64 GetSize() const override;
DataStorage GetStorage() const override;
void* Map(BufferAccess access, UInt64 offset = 0, UInt64 size = 0) override;
void* Map(UInt64 offset = 0, UInt64 size = 0) override;
bool Unmap() override;
private:
std::vector<UInt8> m_buffer;
std::unique_ptr<UInt8[]> m_buffer;
bool m_mapped;
};
NAZARA_UTILITY_API std::shared_ptr<Buffer> SoftwareBufferFactory(BufferType type, UInt64 size, BufferUsageFlags usage, const void* initialData = nullptr);
}
#endif // NAZARA_UTILITY_SOFTWAREBUFFER_HPP

View File

@@ -15,7 +15,7 @@ namespace Nz
class NAZARA_UTILITY_API StaticMesh final : public SubMesh
{
public:
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<const IndexBuffer> indexBuffer);
StaticMesh(std::shared_ptr<VertexBuffer> vertexBuffer, std::shared_ptr<IndexBuffer> indexBuffer);
~StaticMesh() = default;
void Center();
@@ -24,7 +24,7 @@ namespace Nz
const Boxf& GetAABB() const override;
AnimationType GetAnimationType() const final;
const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const override;
const std::shared_ptr<VertexBuffer>& GetVertexBuffer() const;
std::size_t GetVertexCount() const override;
@@ -32,11 +32,11 @@ namespace Nz
bool IsValid() const;
void SetAABB(const Boxf& aabb);
void SetIndexBuffer(std::shared_ptr<const IndexBuffer> indexBuffer);
void SetIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer);
private:
Boxf m_aabb;
std::shared_ptr<const IndexBuffer> m_indexBuffer;
std::shared_ptr<IndexBuffer> m_indexBuffer;
std::shared_ptr<VertexBuffer> m_vertexBuffer;
};
}

View File

@@ -34,7 +34,7 @@ namespace Nz
virtual const Boxf& GetAABB() const = 0;
virtual AnimationType GetAnimationType() const = 0;
virtual const std::shared_ptr<const IndexBuffer>& GetIndexBuffer() const = 0;
virtual const std::shared_ptr<IndexBuffer>& GetIndexBuffer() const = 0;
std::size_t GetMaterialIndex() const;
PrimitiveMode GetPrimitiveMode() const;
std::size_t GetTriangleCount() const;

View File

@@ -18,8 +18,8 @@ namespace Nz
class NAZARA_UTILITY_API TriangleIterator
{
public:
TriangleIterator(PrimitiveMode primitiveMode, const IndexBuffer& indexBuffer);
TriangleIterator(const SubMesh& subMesh);
TriangleIterator(PrimitiveMode primitiveMode, IndexBuffer& indexBuffer);
TriangleIterator(SubMesh& subMesh);
~TriangleIterator() = default;
bool Advance();

View File

@@ -15,30 +15,21 @@ namespace Nz
class NAZARA_UTILITY_API UniformBuffer
{
public:
UniformBuffer() = default;
UniformBuffer(std::shared_ptr<Buffer> buffer);
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
UniformBuffer(UInt32 length, DataStorage storage, BufferUsageFlags usage);
UniformBuffer(std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
UniformBuffer(UInt64 size, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
UniformBuffer(const UniformBuffer&) = default;
UniformBuffer(UniformBuffer&&) noexcept = default;
~UniformBuffer() = default;
bool Fill(const void* data, UInt32 offset, UInt32 size);
bool Fill(const void* data, UInt64 offset, UInt64 size);
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline UInt32 GetEndOffset() const;
inline UInt32 GetStartOffset() const;
inline UInt64 GetEndOffset() const;
inline UInt64 GetStartOffset() const;
inline bool IsValid() const;
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0);
void* Map(BufferAccess access, UInt32 offset = 0, UInt32 size = 0) const;
void Reset();
void Reset(std::shared_ptr<Buffer> buffer);
void Reset(std::shared_ptr<Buffer> buffer, UInt32 offset, UInt32 size);
void Reset(UInt32 size, DataStorage storage, BufferUsageFlags usage);
void Reset(const UniformBuffer& uniformBuffer);
void* Map(UInt64 offset = 0, UInt64 size = 0);
void* Map(UInt64 offset = 0, UInt64 size = 0) const;
void Unmap() const;
@@ -47,8 +38,8 @@ namespace Nz
private:
std::shared_ptr<Buffer> m_buffer;
UInt32 m_endOffset;
UInt32 m_startOffset;
UInt64 m_endOffset;
UInt64 m_startOffset;
};
}

View File

@@ -13,20 +13,15 @@ namespace Nz
return m_buffer;
}
inline UInt32 UniformBuffer::GetEndOffset() const
inline UInt64 UniformBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline UInt32 UniformBuffer::GetStartOffset() const
inline UInt64 UniformBuffer::GetStartOffset() const
{
return m_startOffset;
}
inline bool UniformBuffer::IsValid() const
{
return m_buffer != nullptr;
}
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -18,34 +18,28 @@ namespace Nz
public:
VertexBuffer() = default;
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, UInt64 offset, UInt64 size);
VertexBuffer(std::shared_ptr<const VertexDeclaration> vertexDeclaration, UInt64 vertexCount, BufferUsageFlags usage, const BufferFactory& bufferFactory, const void* initialData = nullptr);
VertexBuffer(const VertexBuffer&) = default;
VertexBuffer(VertexBuffer&&) noexcept = default;
~VertexBuffer() = default;
bool Fill(const void* data, std::size_t startVertex, std::size_t length);
bool FillRaw(const void* data, std::size_t offset, std::size_t size);
bool Fill(const void* data, UInt64 startVertex, UInt64 length);
bool FillRaw(const void* data, UInt64 offset, UInt64 size);
inline const std::shared_ptr<Buffer>& GetBuffer() const;
inline std::size_t GetEndOffset() const;
inline std::size_t GetStartOffset() const;
inline std::size_t GetStride() const;
inline std::size_t GetVertexCount() const;
inline UInt64 GetEndOffset() const;
inline UInt64 GetStartOffset() const;
inline UInt64 GetStride() const;
inline UInt64 GetVertexCount() const;
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration() const;
inline bool IsValid() const;
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0);
void* Map(BufferAccess access, std::size_t startVertex = 0, std::size_t length = 0) const;
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0);
void* MapRaw(BufferAccess access, std::size_t offset = 0, std::size_t size = 0) const;
void Reset();
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer);
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::shared_ptr<Buffer> buffer, std::size_t offset, std::size_t size);
void Reset(std::shared_ptr<const VertexDeclaration> vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage);
void Reset(const VertexBuffer& vertexBuffer);
void* Map(UInt64 startVertex, UInt64 length);
void* Map(UInt64 startVertex, UInt64 length) const;
void* MapRaw(UInt64 offset, UInt64 size);
void* MapRaw(UInt64 offset, UInt64 size) const;
void SetVertexDeclaration(std::shared_ptr<const VertexDeclaration> vertexDeclaration);
@@ -57,9 +51,9 @@ namespace Nz
private:
std::shared_ptr<Buffer> m_buffer;
std::shared_ptr<const VertexDeclaration> m_vertexDeclaration;
std::size_t m_endOffset;
std::size_t m_startOffset;
std::size_t m_vertexCount;
UInt64 m_endOffset;
UInt64 m_startOffset;
UInt64 m_vertexCount;
};
}

View File

@@ -13,22 +13,22 @@ namespace Nz
return m_buffer;
}
inline std::size_t VertexBuffer::GetEndOffset() const
inline UInt64 VertexBuffer::GetEndOffset() const
{
return m_endOffset;
}
inline std::size_t VertexBuffer::GetStride() const
inline UInt64 VertexBuffer::GetStride() const
{
return static_cast<std::size_t>(m_vertexDeclaration->GetStride());
return static_cast<UInt64>(m_vertexDeclaration->GetStride());
}
inline std::size_t VertexBuffer::GetStartOffset() const
inline UInt64 VertexBuffer::GetStartOffset() const
{
return m_startOffset;
}
inline std::size_t VertexBuffer::GetVertexCount() const
inline UInt64 VertexBuffer::GetVertexCount() const
{
return m_vertexCount;
}

View File

@@ -20,10 +20,8 @@ namespace Nz
class NAZARA_UTILITY_API VertexMapper
{
public:
VertexMapper(SubMesh& subMesh, BufferAccess access = BufferAccess::ReadWrite);
VertexMapper(VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadWrite);
VertexMapper(const SubMesh& subMesh, BufferAccess access = BufferAccess::ReadOnly);
VertexMapper(const VertexBuffer& vertexBuffer, BufferAccess access = BufferAccess::ReadOnly);
VertexMapper(SubMesh& subMesh);
VertexMapper(VertexBuffer& vertexBuffer);
~VertexMapper();
template<typename T> SparsePtr<T> GetComponentPtr(VertexComponent component, std::size_t componentIndex = 0);