7
7
//
8
8
9
9
#include " Mesh.h"
10
- #include " Swapchain.h"
11
- #include " utils/TypeAdaptor.h"
12
10
13
11
#include < utils/Logging.h>
14
12
13
+ #include " Swapchain.h"
14
+ #include " utils/TypeAdaptor.h"
15
+
15
16
namespace Siege ::Vulkan
16
17
{
17
18
Mesh::Mesh (const VertexData& vertices)
@@ -24,7 +25,7 @@ Mesh::Mesh(const VertexData& vertices)
24
25
25
26
if (vertices.count == 0 ) return ;
26
27
27
- for (size_t i = 0 ; i < frames; i++) SetVertexBuffers (vertices, i);
28
+ for (size_t i = 0 ; i < frames; i++) SetVertexBuffers (vertices, i);
28
29
}
29
30
30
31
Mesh::Mesh (const VertexData& vertices, const IndexData& indices) : Mesh(vertices)
@@ -37,7 +38,7 @@ Mesh::Mesh(const VertexData& vertices, const IndexData& indices) : Mesh(vertices
37
38
38
39
if (indices.count == 0 ) return ;
39
40
40
- for (size_t i = 0 ; i < frames; i++) SetIndexBuffers (indices, i);
41
+ for (size_t i = 0 ; i < frames; i++) SetIndexBuffers (indices, i);
41
42
}
42
43
43
44
void Mesh::Swap (Mesh& other)
@@ -59,8 +60,15 @@ Mesh::~Mesh()
59
60
60
61
void Mesh::Free ()
61
62
{
62
- perFrameVertexBuffers.MForEach (LAMBDA (VertexBufferUpdate& buffer){ Buffer::DestroyBuffer (buffer.updateBuffer ); });
63
- perFrameIndexBuffers.MForEach (LAMBDA (IndexBufferUpdate& buffer){ Buffer::DestroyBuffer (buffer.updateBuffer ); });
63
+ for (auto it = perFrameVertexBuffers.CreateIterator (); it; ++it)
64
+ {
65
+ Buffer::DestroyBuffer ((*it).updateBuffer );
66
+ }
67
+
68
+ for (auto it = perFrameIndexBuffers.CreateIterator (); it; ++it)
69
+ {
70
+ Buffer::DestroyBuffer ((*it).updateBuffer );
71
+ }
64
72
65
73
perFrameVertexBuffers.Clear ();
66
74
perFrameIndexBuffers.Clear ();
@@ -83,10 +91,14 @@ void Mesh::SetVertexBuffers(const VertexData& vertices, uint32_t currentFrame)
83
91
if (vertices.count > vertexBufferUpdate.count )
84
92
{
85
93
Buffer::DestroyBuffer (vertexBufferUpdate.updateBuffer );
86
- AllocateBuffer (vertexBufferUpdate.updateBuffer , vertices.vertexSize * vertices.count , Utils::BufferType::VERTEX_BUFFER);
94
+ AllocateBuffer (vertexBufferUpdate.updateBuffer ,
95
+ vertices.vertexSize * vertices.count ,
96
+ Utils::BufferType::VERTEX_BUFFER);
87
97
}
88
98
89
- Buffer::CopyData (vertexBufferUpdate.updateBuffer , vertices.vertexSize * vertices.count , vertices.vertices );
99
+ Buffer::CopyData (vertexBufferUpdate.updateBuffer ,
100
+ vertices.vertexSize * vertices.count ,
101
+ vertices.vertices );
90
102
91
103
vertexBufferUpdate.count = vertices.count ;
92
104
}
@@ -98,10 +110,14 @@ void Mesh::SetIndexBuffers(const IndexData& indices, uint32_t currentFrame)
98
110
if (indices.count > indexBufferUpdate.count )
99
111
{
100
112
Buffer::DestroyBuffer (indexBufferUpdate.updateBuffer );
101
- AllocateBuffer (indexBufferUpdate.updateBuffer , sizeof (uint32_t ) * indices.count , Utils::BufferType::INDEX_BUFFER);
113
+ AllocateBuffer (indexBufferUpdate.updateBuffer ,
114
+ sizeof (uint32_t ) * indices.count ,
115
+ Utils::BufferType::INDEX_BUFFER);
102
116
}
103
117
104
- Buffer::CopyData (indexBufferUpdate.updateBuffer , indices.count * sizeof (uint32_t ), indices.indices );
118
+ Buffer::CopyData (indexBufferUpdate.updateBuffer ,
119
+ indices.count * sizeof (uint32_t ),
120
+ indices.indices );
105
121
106
122
indexBufferUpdate.count = indices.count ;
107
123
}
@@ -125,7 +141,9 @@ void Mesh::Update(const VertexData& vertices, uint32_t currentFrameIndex)
125
141
SetVertexBuffers (vertices, currentFrameIndex);
126
142
}
127
143
128
- void Mesh::UpdateIndexed (const VertexData& vertices, const IndexData& indices, uint32_t currentFrameIndex)
144
+ void Mesh::UpdateIndexed (const VertexData& vertices,
145
+ const IndexData& indices,
146
+ uint32_t currentFrameIndex)
129
147
{
130
148
Update (vertices, currentFrameIndex);
131
149
SetIndexBuffers (indices, currentFrameIndex);
0 commit comments