Reworked IndexBuffer, Vertex[Buffer|Declaration|Structs]

Former-commit-id: e3f637f2680afda57a444f73b8f7ad681bb1b8a5
This commit is contained in:
Lynix
2013-07-01 16:14:29 +02:00
parent 35d9a2fef7
commit 4abefc3e93
32 changed files with 713 additions and 1101 deletions

View File

@@ -20,8 +20,6 @@ class NAZARA_API NzAbstractBuffer
virtual bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false) = 0;
virtual void* GetPointer() = 0;
virtual bool IsHardware() const = 0;
virtual void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) = 0;

View File

@@ -28,31 +28,27 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
using BufferFunction = NzAbstractBuffer* (*)(NzBuffer* parent, nzBufferType type);
NzBuffer(nzBufferType type);
NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzBuffer(nzBufferType type, unsigned int size, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
~NzBuffer();
bool CopyContent(const NzBuffer& buffer);
bool Create(unsigned int length, nzUInt8 typeSize, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
bool Create(unsigned int size, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
void Destroy();
bool Fill(const void* data, unsigned int offset, unsigned int length, bool forceDiscard = false);
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false);
NzAbstractBuffer* GetImpl() const;
unsigned int GetLength() const;
void* GetPointer();
const void* GetPointer() const;
unsigned int GetSize() const;
nzBufferStorage GetStorage() const;
nzBufferType GetType() const;
nzUInt8 GetTypeSize() const;
nzBufferUsage GetUsage() const;
bool IsHardware() const;
bool IsValid() const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const;
bool SetStorage(nzBufferStorage storage);
@@ -68,9 +64,8 @@ class NAZARA_API NzBuffer : public NzResource, NzNonCopyable
nzBufferStorage m_storage;
nzBufferType m_type;
nzBufferUsage m_usage;
nzUInt8 m_typeSize;
NzAbstractBuffer* m_impl;
unsigned int m_length;
unsigned int m_size;
static BufferFunction s_bufferFunctions[nzBufferStorage_Max+1];
};

View File

@@ -15,6 +15,48 @@ enum nzAnimationType
nzAnimationType_Max = nzAnimationType_Static
};
enum nzAttributeType
{
nzAttributeType_Color,
nzAttributeType_Double1,
nzAttributeType_Double2,
nzAttributeType_Double3,
nzAttributeType_Double4,
nzAttributeType_Float1,
nzAttributeType_Float2,
nzAttributeType_Float3,
nzAttributeType_Float4,
nzAttributeType_Max = nzAttributeType_Float4
};
enum nzAttributeUsage
{
nzAttributeUsage_InstanceData0,
nzAttributeUsage_InstanceData1,
nzAttributeUsage_InstanceData2,
nzAttributeUsage_InstanceData3,
nzAttributeUsage_InstanceData4,
nzAttributeUsage_InstanceData5,
nzAttributeUsage_Normal,
nzAttributeUsage_Position,
nzAttributeUsage_Tangent,
nzAttributeUsage_TexCoord,
nzAttributeUsage_Userdata0,
nzAttributeUsage_Userdata1,
nzAttributeUsage_Userdata2,
nzAttributeUsage_Userdata3,
nzAttributeUsage_Userdata4,
nzAttributeUsage_Userdata5,
nzAttributeUsage_FirstInstanceData = nzAttributeUsage_InstanceData0,
nzAttributeUsage_FirstVertexData = nzAttributeUsage_Normal,
nzAttributeUsage_LastInstanceData = nzAttributeUsage_InstanceData5,
nzAttributeUsage_LastVertexData = nzAttributeUsage_Userdata5,
nzAttributeUsage_Max = nzAttributeUsage_Userdata5
};
enum nzBufferAccess
{
nzBufferAccess_DiscardAndWrite,
@@ -27,7 +69,7 @@ enum nzBufferAccess
enum nzBufferStorage
{
//nzBufferStorage_Both,
//nzBufferStorage_Both, ///TODO
nzBufferStorage_Hardware,
nzBufferStorage_Software,
@@ -64,40 +106,6 @@ enum nzCubemapFace
nzCubemapFace_Max = nzCubemapFace_NegativeZ
};
enum nzElementStream
{
nzElementStream_VertexData,
nzElementStream_InstancedData,
nzElementStream_Max = nzElementStream_InstancedData
};
enum nzElementType
{
nzElementType_Color,
nzElementType_Double1,
nzElementType_Double2,
nzElementType_Double3,
nzElementType_Double4,
nzElementType_Float1,
nzElementType_Float2,
nzElementType_Float3,
nzElementType_Float4,
nzElementType_Max = nzElementType_Float4
};
enum nzElementUsage
{
nzElementUsage_Diffuse,
nzElementUsage_Normal,
nzElementUsage_Position,
nzElementUsage_Tangent,
nzElementUsage_TexCoord,
nzElementUsage_Max = nzElementUsage_TexCoord
};
enum nzEventType
{
nzEventType_GainedFocus,
@@ -209,6 +217,23 @@ enum nzPrimitiveMode
nzPrimitiveMode_Max = nzPrimitiveMode_TriangleFan
};
enum nzVertexLayout
{
// Déclarations destinées au rendu
nzVertexLayout_XY,
nzVertexLayout_XY_UV,
nzVertexLayout_XYZ,
nzVertexLayout_XYZ_Normal,
nzVertexLayout_XYZ_Normal_UV,
nzVertexLayout_XYZ_Normal_UV_Tangent,
nzVertexLayout_XYZ_UV,
// Déclarations destinées à l'instancing
nzVertexLayout_Matrix4,
nzVertexLayout_Max = nzVertexLayout_Matrix4
};
enum nzWindowCursor
{
nzWindowCursor_None,

View File

@@ -20,28 +20,30 @@ using NzIndexBufferRef = NzResourceRef<NzIndexBuffer>;
class NAZARA_API NzIndexBuffer : public NzResource
{
public:
NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount);
NzIndexBuffer(unsigned int length, bool largeIndices = false, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(const NzIndexBuffer& indexBuffer);
~NzIndexBuffer();
NzIndexBuffer(bool largeIndices, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzIndexBuffer(bool largeIndices, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(const NzIndexBuffer& vertexBuffer);
~NzIndexBuffer() = default;
unsigned int ComputeCacheMissCount() const;
bool Fill(const void* data, unsigned int offset, unsigned int length, bool forceDiscard = false);
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false);
bool FillIndices(const void* data, unsigned int startIndex, unsigned int length, bool forceDiscard = false);
NzBuffer* GetBuffer() const;
unsigned int GetEndOffset() const;
unsigned int GetIndexCount() const;
void* GetPointer();
const void* GetPointer() const;
unsigned int GetStartIndex() const;
unsigned int GetStride() const;
unsigned int GetStartOffset() const;
bool HasLargeIndices() const;
bool IsHardware() const;
bool IsSequential() const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const;
void* MapIndices(nzBufferAccess access, unsigned int startVertex = 0, unsigned int length = 0);
void* MapIndices(nzBufferAccess access, unsigned int startVertex = 0, unsigned int length = 0) const;
void Optimize();
@@ -51,9 +53,10 @@ class NAZARA_API NzIndexBuffer : public NzResource
private:
NzBufferRef m_buffer;
bool m_ownsBuffer;
bool m_largeIndices;
unsigned int m_endOffset;
unsigned int m_indexCount;
unsigned int m_startIndex;
unsigned int m_startOffset;
};
#endif // NAZARA_INDEXBUFFER_HPP

View File

@@ -113,8 +113,6 @@ class NAZARA_API NzMesh : public NzResource, NzResourceListener
void Transform(const NzMatrix4f& matrix);
static const NzVertexDeclaration* GetDeclaration();
private:
void OnResourceReleased(const NzResource* resource, int index) override;

View File

@@ -21,35 +21,38 @@ using NzVertexBufferRef = NzResourceRef<NzVertexBuffer>;
class NAZARA_API NzVertexBuffer : public NzResource
{
public:
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, NzBuffer* buffer, unsigned int startOffset, unsigned int endOffset);
NzVertexBuffer(const NzVertexDeclaration* vertexDeclaration, unsigned int length, nzBufferStorage storage = nzBufferStorage_Software, nzBufferUsage usage = nzBufferUsage_Static);
NzVertexBuffer(const NzVertexBuffer& vertexBuffer);
~NzVertexBuffer();
~NzVertexBuffer() = default;
bool Fill(const void* data, unsigned int offset, unsigned int length, bool forceDiscard = false);
bool Fill(const void* data, unsigned int offset, unsigned int size, bool forceDiscard = false);
bool FillVertices(const void* data, unsigned int startVertex, unsigned int length, bool forceDiscard = false);
NzBuffer* GetBuffer() const;
void* GetPointer();
const void* GetPointer() const;
unsigned int GetStartVertex() const;
nzUInt8 GetTypeSize() const;
unsigned int GetEndOffset() const;
unsigned int GetStartOffset() const;
unsigned int GetStride() const;
unsigned int GetVertexCount() const;
const NzVertexDeclaration* GetVertexDeclaration() const;
bool IsHardware() const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int length = 0) const;
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0);
void* Map(nzBufferAccess access, unsigned int offset = 0, unsigned int size = 0) const;
void* MapVertices(nzBufferAccess access, unsigned int startVertex = 0, unsigned int length = 0);
void* MapVertices(nzBufferAccess access, unsigned int startVertex = 0, unsigned int length = 0) const;
bool SetStorage(nzBufferStorage storage);
void SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
void Unmap() const;
private:
NzBufferRef m_buffer;
NzVertexDeclarationConstRef m_vertexDeclaration;
bool m_ownsBuffer;
unsigned int m_startVertex;
unsigned int m_endOffset;
unsigned int m_startOffset;
unsigned int m_vertexCount;
};

View File

@@ -12,15 +12,6 @@
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Utility/Enums.hpp>
struct NzVertexElement
{
unsigned int offset;
unsigned int usageIndex = 0;
nzElementStream stream = nzElementStream_VertexData;
nzElementType type;
nzElementUsage usage;
};
class NzVertexDeclaration;
using NzVertexDeclarationConstRef = NzResourceRef<const NzVertexDeclaration>;
@@ -30,38 +21,45 @@ struct NzVertexDeclarationImpl;
class NAZARA_API NzVertexDeclaration : public NzResource
{
friend class NzUtility;
public:
NzVertexDeclaration() = default;
NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount);
NzVertexDeclaration(const NzVertexDeclaration& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept;
~NzVertexDeclaration();
NzVertexDeclaration();
NzVertexDeclaration(NzVertexDeclaration& declaration);
~NzVertexDeclaration() = default;
bool Create(const NzVertexElement* elements, unsigned int elementCount);
void Destroy();
void DisableAttribute(nzAttributeUsage usage);
void EnableAttribute(nzAttributeUsage usage, nzAttributeType type, unsigned int offset);
const NzVertexElement* GetElement(unsigned int i) const;
const NzVertexElement* GetElement(nzElementStream stream, unsigned int i) const;
const NzVertexElement* GetElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const;
unsigned int GetElementCount() const;
unsigned int GetElementCount(nzElementStream stream) const;
unsigned int GetStride(nzElementStream stream) const;
void GetAttribute(nzAttributeUsage usage, bool* enabled, nzAttributeType* type, unsigned int* offset) const;
unsigned int GetStride() const;
bool HasElement(unsigned int i) const;
bool HasElement(nzElementStream stream, unsigned int i) const;
bool HasElement(nzElementStream stream, nzElementUsage usage, unsigned int usageIndex = 0) const;
bool HasStream(nzElementStream stream) const;
bool IsValid() const;
void SetStride(unsigned int stride);
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept;
static unsigned int GetElementCount(nzElementType type);
static unsigned int GetElementSize(nzElementType type);
static NzVertexDeclaration* Get(nzVertexLayout layout);
static unsigned int GetAttributeSize(nzAttributeType type);
private:
NzVertexDeclarationImpl* m_sharedImpl = nullptr;
static bool Initialize();
static void Uninitialize();
struct Attribute
{
nzAttributeType type;
bool enabled = false;
unsigned int offset;
// Il serait aussi possible de préciser le stride de façon indépendante, ce que je ne permets pas
// pour décomplexifier l'interface en enlevant quelque chose d'inutile.
// Si vous pensez que ça peut être utile, n'hésitez pas à me le faire savoir !
// PS: Même cas pour le diviseur (instancing)
};
Attribute m_attributes[nzAttributeUsage_Max+1];
unsigned int m_stride;
static NzVertexDeclaration s_declarations[nzVertexLayout_Max+1];
};
#endif // NAZARA_VERTEXDECLARATION_HPP

View File

@@ -15,9 +15,9 @@ struct NzVertexStruct_XY
NzVector2f position;
};
struct NzVertexStruct_XY_Color : public NzVertexStruct_XY
struct NzVertexStruct_XY_UV : public NzVertexStruct_XY
{
NzVector3f color;
NzVector2f uv;
};
/////////////////////////////////////////
@@ -27,87 +27,24 @@ struct NzVertexStruct_XYZ
NzVector3f position;
};
struct NzVertexStruct_XYZ_Color : public NzVertexStruct_XYZ
{
NzVector3f color;
};
struct NzVertexStruct_XYZ_Normal : public NzVertexStruct_XYZ
{
NzVector3f normal;
};
struct NzVertexStruct_XYZ_Normal_Color : public NzVertexStruct_XYZ_Normal
{
NzVector3f color;
};
/////////////////////////////////////////
struct NzVertexStruct_XYZ_UV : public NzVertexStruct_XYZ
{
NzVector2f uv;
};
struct NzVertexStruct_XYZ_UV_Color : public NzVertexStruct_XYZ_UV
{
NzVector3f color;
};
struct NzVertexStruct_XYZ_Normal_UV : public NzVertexStruct_XYZ_Normal
{
NzVector2f uv;
};
struct NzVertexStruct_XYZ_Normal_UV_Color : public NzVertexStruct_XYZ_Normal_UV
{
NzVector3f color;
};
struct NzVertexStruct_XYZ_Normal_UV_Tangent : public NzVertexStruct_XYZ_Normal_UV
{
NzVector3f tangent;
};
struct NzVertexStruct_XYZ_Normal_UV_Tangent_Color : public NzVertexStruct_XYZ_Normal_UV_Tangent
struct NzVertexStruct_XYZ_UV : public NzVertexStruct_XYZ
{
NzVector3f color;
};
/////////////////////////////////////////
struct NzVertexStruct_XYZ_UV_UV2 : public NzVertexStruct_XYZ_UV
{
NzVector2f uv2;
};
struct NzVertexStruct_XYZ_UV_UV2_Color : public NzVertexStruct_XYZ_UV_UV2
{
NzVector3f color;
};
/////////////////////////////////////////
struct NzVertexStruct_XYZ_Normal_UV_UV2 : public NzVertexStruct_XYZ_Normal_UV
{
NzVector2f uv2;
};
struct NzVertexStruct_XYZ_Normal_UV_UV2_Color : public NzVertexStruct_XYZ_Normal_UV_UV2
{
NzVector3f color;
};
struct NzVertexStruct_XYZ_Normal_UV_UV2_Tangent : public NzVertexStruct_XYZ_Normal_UV_UV2
{
NzVector3f tangent;
};
/////////////////////////////////////////
struct NzVertexStruct_XYZ_Normal_UV_UV2_Tangent_Color : public NzVertexStruct_XYZ_Normal_UV_UV2_Tangent
{
NzVector3f color;
NzVector2f uv;
};
#endif // NAZARA_VERTEXSTRUCT_HPP