Sculpt: Fix T101502: GPU tris miscounted for dyntopo

Dyntopo PBVH draw was miscounting the number of triangles.
This commit is contained in:
2022-10-06 14:03:17 -07:00
parent eae3fa8730
commit dfa0eb298e

View File

@@ -707,26 +707,14 @@ struct PBVHBatches {
}
BMLoop *l = f->l_first;
do {
callback(l->prev);
callback(l);
} while ((l = l->next) != f->l_first);
callback(l->next);
}
GSET_FOREACH_END();
};
faces_count = 0;
GSET_FOREACH_BEGIN (BMFace *, f, args->bm_faces) {
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
continue;
}
BMLoop *l = f->l_first;
do {
faces_count++;
} while ((l = l->next) != f->l_first);
}
GSET_FOREACH_END();
tris_count = faces_count;
faces_count = tris_count = count_faces(args);
int existing_num = GPU_vertbuf_get_vertex_len(vbo.vert_buf);
void *existing_data = GPU_vertbuf_get_data(vbo.vert_buf);
@@ -741,7 +729,24 @@ struct PBVHBatches {
GPUVertBufRaw access;
GPU_vertbuf_attr_get_raw_data(vbo.vert_buf, 0, &access);
#if 0 /* Enable to fuzz gpu data (to check for overallocation). */
existing_data = GPU_vertbuf_get_data(vbo.vert_buf);
uchar *c = static_cast<uchar *>(existing_data);
for (int i : IndexRange(vert_count * access.stride)) {
*c++ = i & 255;
}
#endif
switch (vbo.type) {
case CD_PROP_COLOR:
case CD_PROP_BYTE_COLOR: {
ushort4 white = {USHRT_MAX, USHRT_MAX, USHRT_MAX, USHRT_MAX};
foreach_bmesh([&](BMLoop * /*l*/) {
*static_cast<ushort4 *>(GPU_vertbuf_raw_step(&access)) = white;
});
break;
}
case CD_PBVH_CO_TYPE:
foreach_bmesh(
[&](BMLoop *l) { *static_cast<float3 *>(GPU_vertbuf_raw_step(&access)) = l->v->co; });