@@ -17,6 +17,12 @@ void VertexArray::Append(ArenaAllocator &alloc, const VertexArray &other) {
17
17
18
18
D_ASSERT (properties.HasZ () == other.properties .HasZ ());
19
19
D_ASSERT (properties.HasM () == other.properties .HasM ());
20
+ #ifdef DEBUG
21
+ if (properties.HasZ () != other.properties .HasZ ()) {
22
+ // This is mostly here to prevent the ToString() method to be optimized out.
23
+ throw InternalException (" Cannot append vertex arrays with different Z properties. self: %s, other: %s" , ToString (vertex_count), other.ToString (other.vertex_count ));
24
+ }
25
+ #endif
20
26
auto old_count = vertex_count;
21
27
auto new_count = vertex_count + other.vertex_count ;
22
28
Resize (alloc, new_count);
@@ -79,11 +85,15 @@ void VertexArray::SetVertexType(ArenaAllocator &alloc, bool has_z, bool has_m, d
79
85
for (int64_t i = vertex_count - 1 ; i >= 0 ; i--) {
80
86
auto old_offset = i * old_vertex_size;
81
87
auto new_offset = i * new_vertex_size;
82
- memcpy (vertex_data + new_offset, vertex_data + old_offset, sizeof (double ) * 2 );
83
- auto z_offset = old_offset + sizeof (double ) * 2 ;
84
- auto m_offset = old_offset + sizeof (double ) * 3 ;
85
- memcpy (vertex_data + new_offset + m_offset, vertex_data + z_offset, sizeof (double ));
86
- memcpy (vertex_data + new_offset + z_offset, &default_z, sizeof (double ));
88
+ auto old_m_offset = old_offset + sizeof (double ) * 2 ;
89
+ auto new_z_offset = new_offset + sizeof (double ) * 2 ;
90
+ auto new_m_offset = new_offset + sizeof (double ) * 3 ;
91
+ // Move the M value
92
+ memcpy (vertex_data + new_m_offset, vertex_data + old_m_offset, sizeof (double ));
93
+ // Set the new Z value
94
+ memcpy (vertex_data + new_z_offset, &default_z, sizeof (double ));
95
+ // Move the X and Y values
96
+ memcpy (vertex_data + new_offset, vertex_data + old_offset, sizeof (double ) * 2 );
87
97
}
88
98
} else if (!used_to_have_z && has_z && !used_to_have_m && has_m) {
89
99
// 2. We go from XY to XYZM
@@ -190,48 +200,51 @@ double VertexArray::Length() const {
190
200
}
191
201
192
202
string VertexArray::ToString () const {
203
+ return ToString (vertex_count);
204
+ }
205
+ string VertexArray::ToString (uint32_t count) const {
193
206
auto has_z = properties.HasZ ();
194
207
auto has_m = properties.HasM ();
195
208
196
209
if (has_z && has_m) {
197
- string result = StringUtil::Format (" VertexArray XYZM (%d) [" , vertex_count);
198
- for (uint32_t i = 0 ; i < vertex_count ; i++) {
210
+ string result = StringUtil::Format (" VertexArray XYZM (%d/%d ) [" , count , vertex_count);
211
+ for (uint32_t i = 0 ; i < count ; i++) {
199
212
auto vertex = GetExact<VertexXYZM>(i);
200
213
result += StringUtil::Format (" (%f, %f, %f, %f)" , vertex.x , vertex.y , vertex.z , vertex.m );
201
- if (i < vertex_count - 1 ) {
214
+ if (i < count - 1 ) {
202
215
result += " , " ;
203
216
}
204
217
}
205
218
result += " ]" ;
206
219
return result;
207
220
} else if (has_z) {
208
- string result = StringUtil::Format (" VertexArray XYZ (%d) [" , vertex_count);
209
- for (uint32_t i = 0 ; i < vertex_count ; i++) {
221
+ string result = StringUtil::Format (" VertexArray XYZ (%d/%d ) [" , count , vertex_count);
222
+ for (uint32_t i = 0 ; i < count ; i++) {
210
223
auto vertex = GetExact<VertexXYZ>(i);
211
224
result += StringUtil::Format (" (%f, %f, %f)" , vertex.x , vertex.y , vertex.z );
212
- if (i < vertex_count - 1 ) {
225
+ if (i < count - 1 ) {
213
226
result += " , " ;
214
227
}
215
228
}
216
229
result += " ]" ;
217
230
return result;
218
231
} else if (has_m) {
219
- string result = StringUtil::Format (" VertexArray XYM (%d/%d) [" , vertex_count);
220
- for (uint32_t i = 0 ; i < vertex_count ; i++) {
232
+ string result = StringUtil::Format (" VertexArray XYM (%d/%d) [" , count, vertex_count);
233
+ for (uint32_t i = 0 ; i < count ; i++) {
221
234
auto vertex = GetExact<VertexXYM>(i);
222
235
result += StringUtil::Format (" (%f, %f, %f)" , vertex.x , vertex.y , vertex.m );
223
- if (i < vertex_count - 1 ) {
236
+ if (i < count - 1 ) {
224
237
result += " , " ;
225
238
}
226
239
}
227
240
result += " ]" ;
228
241
return result;
229
242
} else {
230
- string result = StringUtil::Format (" VertexArray XY (%d/%d) [" , vertex_count);
231
- for (uint32_t i = 0 ; i < vertex_count ; i++) {
243
+ string result = StringUtil::Format (" VertexArray XY (%d/%d) [" , count, vertex_count);
244
+ for (uint32_t i = 0 ; i < count ; i++) {
232
245
auto vertex = GetExact<VertexXY>(i);
233
246
result += StringUtil::Format (" (%f, %f)" , vertex.x , vertex.y );
234
- if (i < vertex_count - 1 ) {
247
+ if (i < count - 1 ) {
235
248
result += " , " ;
236
249
}
237
250
}
0 commit comments