[Bf-blender-cvs] [dfa0eb298ed] master: Sculpt: Fix T101502: GPU tris miscounted for dyntopo

Joseph Eagar noreply at git.blender.org
Thu Oct 6 23:04:18 CEST 2022


Commit: dfa0eb298ed3fa08cc70a472eb9427b515040457
Author: Joseph Eagar
Date:   Thu Oct 6 14:03:17 2022 -0700
Branches: master
https://developer.blender.org/rBdfa0eb298ed3fa08cc70a472eb9427b515040457

Sculpt: Fix T101502: GPU tris miscounted for dyntopo

Dyntopo PBVH draw was miscounting the number of triangles.

===================================================================

M	source/blender/draw/intern/draw_pbvh.cc

===================================================================

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<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; });



More information about the Bf-blender-cvs mailing list