From dfa0eb298ed3fa08cc70a472eb9427b515040457 Mon Sep 17 00:00:00 2001 From: Joseph Eagar Date: Thu, 6 Oct 2022 14:03:17 -0700 Subject: Sculpt: Fix T101502: GPU tris miscounted for dyntopo Dyntopo PBVH draw was miscounting the number of triangles. --- source/blender/draw/intern/draw_pbvh.cc | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'source') diff --git a/source/blender/draw/intern/draw_pbvh.cc b/source/blender/draw/intern/draw_pbvh.cc index 6b807222079..02e7f937987 100644 --- a/source/blender/draw/intern/draw_pbvh.cc +++ b/source/blender/draw/intern/draw_pbvh.cc @@ -707,26 +707,14 @@ struct PBVHBatches { } BMLoop *l = f->l_first; - do { - callback(l); - } while ((l = l->next) != f->l_first); + callback(l->prev); + callback(l); + 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(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(GPU_vertbuf_raw_step(&access)) = white; + }); + break; + } case CD_PBVH_CO_TYPE: foreach_bmesh( [&](BMLoop *l) { *static_cast(GPU_vertbuf_raw_step(&access)) = l->v->co; }); -- cgit v1.2.3