Skip to content

Commit b3bf6d0

Browse files
committed
Re-added docs for Index and Vertex buffer types and cleaned files
1 parent e6bfa8b commit b3bf6d0

File tree

18 files changed

+317
-116
lines changed

18 files changed

+317
-116
lines changed

engine/render/renderer/platform/vulkan/IndexBuffer.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,96 @@ class IndexBuffer
2323

2424
// 'Structors
2525

26+
/**
27+
* The default constructor for the IndexBuffer class
28+
*/
2629
IndexBuffer() = default;
30+
31+
/**
32+
* The IndexBuffer base constructor. Accepts index data along with a size to construct the
33+
* buffer with
34+
* @param data the data to copy into the buffer
35+
* @param dataSize the size of the data in bytes
36+
*/
2737
IndexBuffer(void* data, uint64_t dataSize);
38+
39+
/**
40+
* A zero copy constructor. Initialises the IndexBuffer with a maximum size but no data
41+
* @param bufferSize the total size of the buffer in bytes
42+
*/
2843
IndexBuffer(unsigned long bufferSize);
44+
45+
/**
46+
* An IndexBuffer copy constructor. Creates a new IndexBuffer with the contents of another
47+
* IndexBuffer
48+
* @param other the index buffer to copy data from
49+
*/
2950
IndexBuffer(const IndexBuffer& other);
51+
52+
/**
53+
* An IndexBuffer move constructor. Creates a new IndexBuffer with the moved memory from another
54+
* IndexBuffer
55+
* @param other the IndexBuffer to move data from
56+
*/
3057
IndexBuffer(IndexBuffer&& other);
58+
59+
/**
60+
* The IndexBuffer destructor. Frees all memory and resets the IndexBuffer
61+
*/
3162
~IndexBuffer();
3263

3364
// Operator overload
3465

66+
/**
67+
* The IndexBuffer copy assignment operator. Copies the value from one IndexBuffer into another
68+
* @param other the IndexBuffer to copy data from
69+
* @return a reference to the current IndexBuffer
70+
*/
3571
IndexBuffer& operator=(const IndexBuffer& other);
72+
73+
/**
74+
* The IndexBuffer move assignment operator. Moves the value from one IndexBuffer into another
75+
* @param other the IndexBuffer to move data from
76+
* @return a reference to the current IndexBuffer
77+
*/
3678
IndexBuffer& operator=(IndexBuffer&& other);
3779

3880
// Functions
3981

82+
/**
83+
* Frees all memory from the IndexBuffer and resets all values
84+
*/
4085
void Free();
86+
87+
/**
88+
* Copies the provided data into the IndexBuffer with an offset
89+
* @param data the data to be copied into the buffer
90+
* @param size the size in bytes of the data
91+
* @param offset the byte offset to copy the data to
92+
*/
4193
void Copy(const void* data, unsigned long size, unsigned long offset = 0);
94+
95+
/**
96+
* Binds the IndexBuffer for rendering
97+
* @param commandBuffer the command buffer to bind to
98+
* @param offset the byte offset to bind
99+
*/
42100
void Bind(const CommandBuffer& commandBuffer, uint64_t offset = 0);
43101

44102
private:
45103

104+
/**
105+
* Swaps the contents of two buffers
106+
* @param other the buffer to swap values with
107+
*/
46108
void Swap(IndexBuffer& other);
109+
110+
/**
111+
* Allocates memory for the buffer
112+
* @param device the device to allocate memory from
113+
*/
47114
void Allocate(VkDevice device);
115+
48116
void* rawBuffer {nullptr};
49117
VkBuffer buffer {nullptr};
50118
VkDeviceMemory memory {nullptr};

engine/render/renderer/platform/vulkan/VertexBuffer.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,87 @@ class VertexBuffer
2323

2424
// 'Structor
2525

26+
/**
27+
* The default constructor for the VertexBuffer
28+
*/
2629
VertexBuffer() = default;
30+
31+
/**
32+
* A constructor for the VertexBuffer which accepts vertex data during construction
33+
* @param data the vertex data to be copied in
34+
* @param bufferSize the size of the data in bytes
35+
*/
2736
VertexBuffer(void* data, unsigned long bufferSize);
37+
38+
/**
39+
* A zero-data constructor for the VertxBuffer. Initialises a vertex buffer with no data but
40+
* with the given size
41+
* @param bufferSize the total size of the buffer in bytes
42+
*/
2843
VertexBuffer(unsigned long bufferSize);
44+
45+
/**
46+
* The move constructor from another VertexBuffer
47+
* @param other the other vertex buffer to move
48+
*/
2949
VertexBuffer(VertexBuffer&& other);
50+
51+
/**
52+
* The copy constructor from another VertexBuffer
53+
* @param other the other vertex buffer to copy from
54+
*/
3055
VertexBuffer(const VertexBuffer& other);
56+
57+
/**
58+
* The VertexBuffer destructor
59+
*/
3160
~VertexBuffer();
3261

3362
// Operators
3463

64+
/**
65+
* The copy assignment operator. Copies the values of one Vertex Buffer to another
66+
* @param other the Vertex Buffer to copy
67+
* @return a reference to the current VertexBuffer
68+
*/
3569
VertexBuffer& operator=(const VertexBuffer& other);
70+
71+
/**
72+
* The move assignment operator. Moves the values of one Vertex Buffer to another
73+
* @param other the Vertex buffer being moved
74+
* @return a reference to the current VertexBuffer
75+
*/
3676
VertexBuffer& operator=(VertexBuffer&& other);
3777

3878
// Functions
3979

80+
/**
81+
* Copies the provided data into the buffer
82+
* @param data the data to be copied
83+
* @param size the size of the data in bytes
84+
* @param offset the offset to copy the data to within the buffer
85+
*/
4086
void Copy(const void* data, unsigned long size, unsigned long offset = 0);
87+
88+
/**
89+
* Binds the VertexBuffer for rendering
90+
* @param commandBuffer the command buffer the binding should apply to
91+
* @param offset the offset of the buffer to bind in bytes
92+
* @param binding the vertex binding ID to use
93+
*/
4194
void Bind(const CommandBuffer& commandBuffer, const uint64_t* offset, unsigned int binding = 0);
95+
96+
/**
97+
* Frees the contents of the VertexBuffer
98+
*/
4299
void Free();
43100

101+
/**
102+
* Casts the contents of the buffer to a specific type
103+
* @tparam T the type to cast the contents to
104+
* @param offset the offset to retrieve in bytes
105+
* @return the entire buffer cast to the requested type
106+
*/
44107
template<typename T>
45108
const T* Cast(unsigned long offset = 0)
46109
{
@@ -49,8 +112,18 @@ class VertexBuffer
49112

50113
private:
51114

115+
/**
116+
* Swaps the contents of two VertexBuffers
117+
* @param other the VertexBuffer to swap with
118+
*/
52119
void Swap(VertexBuffer& other);
120+
121+
/**
122+
* Allocates the memory for the VertexBuffer
123+
* @param device the device used for allocation
124+
*/
53125
void Allocate(VkDevice device);
126+
54127
void* rawBuffer {nullptr};
55128
VkBuffer buffer {nullptr};
56129
VkDeviceMemory memory {nullptr};

engine/render/renderer/renderer/Renderer2D.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ void Renderer2D::RenderQuads(Vulkan::CommandBuffer& buffer, size_t index)
239239
uint64_t bindOffset = sizeof(QuadVertex) * vertexBufferOffset;
240240

241241
quadVBuffer.Bind(buffer, &bindOffset);
242-
// quadVertexBuffer.Bind(buffer, &vertexBufferOffset);
243242

244243
Vulkan::Utils::DrawIndexed(buffer.Get(), 6, quadArr.Count(), 0, 0, 0);
245244
}

engine/utils/Logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class VariantContainer
9999
DEFINE_VARIANT_TYPE(const Vec2& data, "Vector2(" + ToString(data) + ")");
100100
DEFINE_VARIANT_TYPE(const Vec3& data, "Vector3(" + ToString(data) + ")");
101101
DEFINE_VARIANT_TYPE(const Vec4& data, "Vector4(" + ToString(data) + ")");
102-
// DEFINE_VARIANT_TYPE(const Mat2& data, "Mat2(" + ToString(data) + ")");
102+
DEFINE_VARIANT_TYPE(const Mat2& data, "Mat2(" + ToString(data) + ")");
103103
DEFINE_VARIANT_TYPE(const Mat3& data, "Mat3(" + ToString(data) + ")");
104104
DEFINE_VARIANT_TYPE(const Mat4& data, "Mat4(" + ToString(data) + ")");
105105

engine/utils/math/Maths.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818

1919
namespace Siege
2020
{
21+
22+
template<typename T>
23+
inline constexpr T Epsilon()
24+
{
25+
return static_cast<T>(1e-6);
26+
}
27+
2128
struct BoundedBox
2229
{
2330
// 'Structors

engine/utils/math/mat/Equality.h

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,28 @@ namespace Siege
2121
* @tparam T the type of numerical value stored by the matrix
2222
* @param lhs the matrix on the left hand side of the operation
2323
* @param rhs the matrix on the right hand side of the operation
24+
* @param epsilon the tolerance level for the comparison
2425
* @return a boolean specifying if they are equal within the given tolerance
2526
*/
2627
template<typename T>
27-
inline constexpr bool FEquals(const Mat<T, 4, 4>& lhs, const Mat<T, 4, 4>& rhs)
28+
inline constexpr bool Equals(const Mat<T, 4, 4>& lhs, const Mat<T, 4, 4>& rhs, T epsilon = 0)
2829
{
29-
T epsilon = std::numeric_limits<T>::epsilon();
30-
31-
return (lhs[0][0] - rhs[0][0] <= epsilon) && (lhs[0][1] - rhs[0][1] <= epsilon) &&
32-
(lhs[0][2] - rhs[0][2] <= epsilon) && (lhs[0][3] - rhs[0][3] <= epsilon) &&
33-
(lhs[1][0] - rhs[1][0] <= epsilon) && (lhs[1][1] - rhs[1][1] <= epsilon) &&
34-
(lhs[1][2] - rhs[1][2] <= epsilon) && (lhs[1][3] - rhs[1][3] <= epsilon) &&
35-
(lhs[2][0] - rhs[2][0] <= epsilon) && (lhs[2][1] - rhs[2][1] <= epsilon) &&
36-
(lhs[2][2] - rhs[2][2] <= epsilon) && (lhs[2][3] - rhs[2][3] <= epsilon) &&
37-
(lhs[3][0] - rhs[3][0] <= epsilon) && (lhs[3][1] - rhs[3][1] <= epsilon) &&
38-
(lhs[3][2] - rhs[3][2] <= epsilon) && (lhs[3][3] - rhs[3][3] <= epsilon);
30+
return (std::fabs(lhs[0][0] - rhs[0][0]) <= epsilon) &&
31+
(std::fabs(lhs[0][1] - rhs[0][1]) <= epsilon) &&
32+
(std::fabs(lhs[0][2] - rhs[0][2]) <= epsilon) &&
33+
(std::fabs(lhs[0][3] - rhs[0][3]) <= epsilon) &&
34+
(std::fabs(lhs[1][0] - rhs[1][0]) <= epsilon) &&
35+
(std::fabs(lhs[1][1] - rhs[1][1]) <= epsilon) &&
36+
(std::fabs(lhs[1][2] - rhs[1][2]) <= epsilon) &&
37+
(std::fabs(lhs[1][3] - rhs[1][3]) <= epsilon) &&
38+
(std::fabs(lhs[2][0] - rhs[2][0]) <= epsilon) &&
39+
(std::fabs(lhs[2][1] - rhs[2][1]) <= epsilon) &&
40+
(std::fabs(lhs[2][2] - rhs[2][2]) <= epsilon) &&
41+
(std::fabs(lhs[2][3] - rhs[2][3]) <= epsilon) &&
42+
(std::fabs(lhs[3][0] - rhs[3][0]) <= epsilon) &&
43+
(std::fabs(lhs[3][1] - rhs[3][1]) <= epsilon) &&
44+
(std::fabs(lhs[3][2] - rhs[3][2]) <= epsilon) &&
45+
(std::fabs(lhs[3][3] - rhs[3][3]) <= epsilon);
3946
}
4047

4148
/**
@@ -44,18 +51,21 @@ inline constexpr bool FEquals(const Mat<T, 4, 4>& lhs, const Mat<T, 4, 4>& rhs)
4451
* @tparam T the type of numerical value stored by the matrix
4552
* @param lhs the matrix on the left hand side of the operation
4653
* @param rhs the matrix on the right hand side of the operation
54+
* @param epsilon the tolerance level for the comparison
4755
* @return a boolean specifying if they are equal within the given tolerance
4856
*/
4957
template<typename T>
50-
inline constexpr bool FEquals(const Mat<T, 3, 3>& lhs, const Mat<T, 3, 3>& rhs)
58+
inline constexpr bool Equals(const Mat<T, 3, 3>& lhs, const Mat<T, 3, 3>& rhs, T epsilon = 0)
5159
{
52-
T epsilon = std::numeric_limits<T>::epsilon();
53-
54-
return (lhs[0][0] - rhs[0][0] <= epsilon) && (lhs[0][1] - rhs[0][1] <= epsilon) &&
55-
(lhs[0][2] - rhs[0][2] <= epsilon) && (lhs[1][0] - rhs[1][0] <= epsilon) &&
56-
(lhs[1][1] - rhs[1][1] <= epsilon) && (lhs[1][2] - rhs[1][2] <= epsilon) &&
57-
(lhs[2][0] - rhs[2][0] <= epsilon) && (lhs[2][1] - rhs[2][1] <= epsilon) &&
58-
(lhs[2][2] - rhs[2][2] <= epsilon);
60+
return (std::fabs(lhs[0][0] - rhs[0][0]) <= epsilon) &&
61+
(std::fabs(lhs[0][1] - rhs[0][1]) <= epsilon) &&
62+
(std::fabs(lhs[0][2] - rhs[0][2]) <= epsilon) &&
63+
(std::fabs(lhs[1][0] - rhs[1][0]) <= epsilon) &&
64+
(std::fabs(lhs[1][1] - rhs[1][1]) <= epsilon) &&
65+
(std::fabs(lhs[1][2] - rhs[1][2]) <= epsilon) &&
66+
(std::fabs(lhs[2][0] - rhs[2][0]) <= epsilon) &&
67+
(std::fabs(lhs[2][1] - rhs[2][1]) <= epsilon) &&
68+
(std::fabs(lhs[2][2] - rhs[2][2]) <= epsilon);
5969
}
6070

6171
/**
@@ -64,14 +74,16 @@ inline constexpr bool FEquals(const Mat<T, 3, 3>& lhs, const Mat<T, 3, 3>& rhs)
6474
* @tparam T the type of numerical value stored by the matrix
6575
* @param lhs the matrix on the left hand side of the operation
6676
* @param rhs the matrix on the right hand side of the operation
77+
* @param epsilon the tolerance level for the comparison
6778
* @return a boolean specifying if they are equal within the given tolerance
6879
*/
6980
template<typename T>
70-
inline constexpr bool FEquals(const Mat<T, 2, 2>& lhs, const Mat<T, 2, 2>& rhs)
81+
inline constexpr bool Equals(const Mat<T, 2, 2>& lhs, const Mat<T, 2, 2>& rhs, T epsilon = 0)
7182
{
72-
T epsilon = std::numeric_limits<T>::epsilon();
73-
return (lhs[0][0] - rhs[0][0] <= epsilon) && (lhs[0][1] - rhs[0][1] <= epsilon) &&
74-
(lhs[1][0] - rhs[1][0] <= epsilon) && (lhs[1][1] - rhs[1][1] <= epsilon);
83+
return (std::fabs(lhs[0][0] - rhs[0][0]) <= epsilon) &&
84+
(std::fabs(lhs[0][1] - rhs[0][1]) <= epsilon) &&
85+
(std::fabs(lhs[1][0] - rhs[1][0]) <= epsilon) &&
86+
(std::fabs(lhs[1][1] - rhs[1][1]) <= epsilon);
7587
}
7688
} // namespace Siege
7789

engine/utils/math/vec/Equality.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
namespace Siege
1717
{
1818

19+
/**
20+
* Calculates the epsilon scaled to the larger of the values to compare. Creates a more generous
21+
* tolerance level than a standard epsilon
22+
* @tparam T The type of the values to compare
23+
* @param lhs the value on the left hand side
24+
* @param rhs the value on the right hand side
25+
* @return the scaled epsilon of the two values
26+
*/
1927
template<typename T>
2028
inline constexpr T ScaledEpsilon(T lhs, T rhs)
2129
{

engine/utils/math/vec/Vec2.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ struct Vec<T, 2>
258258
{
259259
switch (index)
260260
{
261-
default:
262-
case (0):
263-
return x;
264261
case (1):
265262
return y;
263+
case (0):
264+
default:
265+
return x;
266266
}
267267
}
268268

engine/utils/math/vec/Vec3.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,13 @@ struct Vec<T, 3>
293293
{
294294
switch (index)
295295
{
296-
default:
297-
case (0):
298-
return x;
299296
case (1):
300297
return y;
301298
case (2):
302299
return z;
300+
case (0):
301+
default:
302+
return x;
303303
}
304304
}
305305

engine/utils/math/vec/Vec4.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ struct Vec<T, 4>
303303
{
304304
switch (index)
305305
{
306-
default:
307-
case (0):
308-
return x;
309306
case (1):
310307
return y;
311308
case (2):
312309
return z;
313310
case (3):
314311
return w;
312+
case (0):
313+
default:
314+
return x;
315315
}
316316
}
317317

0 commit comments

Comments
 (0)