[Bf-blender-cvs] [7137951f9cc] temp-T96710-pbvh-pixels: Add tagging flag for pixel update.

Jeroen Bakker noreply at git.blender.org
Fri Apr 1 16:06:04 CEST 2022


Commit: 7137951f9ccb210b1edd7ad6988f42e02366ac33
Author: Jeroen Bakker
Date:   Fri Apr 1 16:05:54 2022 +0200
Branches: temp-T96710-pbvh-pixels
https://developer.blender.org/rB7137951f9ccb210b1edd7ad6988f42e02366ac33

Add tagging flag for pixel update.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/BKE_pbvh.hh
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_pixels.cc
M	source/blender/editors/sculpt_paint/sculpt.c

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 54af9374d47..14ab7f84214 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -72,6 +72,8 @@ typedef enum {
 
   PBVH_UpdateTopology = 1 << 13,
   PBVH_UpdateColor = 1 << 14,
+  PBVH_UpdatePixels = 1 << 15,
+
 } PBVHNodeFlags;
 
 typedef struct PBVHFrustumPlanes {
@@ -290,6 +292,8 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
 void BKE_pbvh_node_mark_update(PBVHNode *node);
 void BKE_pbvh_node_mark_update_mask(PBVHNode *node);
 void BKE_pbvh_node_mark_update_color(PBVHNode *node);
+void BKE_pbvh_node_mark_update_pixels(PBVHNode *node);
+void BKE_pbvh_mark_update_pixels(PBVH *pbvh);
 void BKE_pbvh_node_mark_update_visibility(PBVHNode *node);
 void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node);
 void BKE_pbvh_node_mark_redraw(PBVHNode *node);
diff --git a/source/blender/blenkernel/BKE_pbvh.hh b/source/blender/blenkernel/BKE_pbvh.hh
index b10fed5b238..39acf17973d 100644
--- a/source/blender/blenkernel/BKE_pbvh.hh
+++ b/source/blender/blenkernel/BKE_pbvh.hh
@@ -105,6 +105,13 @@ struct Triangles {
     loop_indices.clear();
   }
 
+  void clear()
+  {
+    paint_input.clear();
+    loop_indices.clear();
+    poly_indices.clear();
+  }
+
   uint64_t size() const
   {
     return paint_input.size();
@@ -192,6 +199,12 @@ struct NodeData {
     }
   }
 
+  void clear_data()
+  {
+    tiles.clear();
+    triangles.clear();
+  }
+
   static void free_func(void *instance)
   {
     NodeData *node_data = static_cast<NodeData *>(instance);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 060c0fd8ecc..620943ca3e6 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1744,6 +1744,21 @@ void BKE_pbvh_node_mark_update_color(PBVHNode *node)
   node->flag |= PBVH_UpdateColor | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
 }
 
+void BKE_pbvh_node_mark_update_pixels(PBVHNode *node)
+{
+  node->flag |= PBVH_UpdatePixels;
+}
+
+void BKE_pbvh_mark_update_pixels(PBVH *pbvh)
+{
+  for (int n = 0; n < pbvh->totnode; n++) {
+    PBVHNode *node = &pbvh->nodes[n];
+    if (node->flag & PBVH_Leaf) {
+      BKE_pbvh_node_mark_update_pixels(node);
+    }
+  }
+}
+
 void BKE_pbvh_node_mark_update_visibility(PBVHNode *node)
 {
   node->flag |= PBVH_UpdateVisibility | PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers |
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index d7076a7cd30..b5b299010a8 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -191,6 +191,7 @@ static void do_encode_pixels(void *__restrict userdata,
     node_data->tiles.append(tile_data);
   }
   node_data->triangles.cleanup_after_init();
+  node->flag = static_cast<PBVHNodeFlags>(node->flag & ~PBVH_UpdatePixels);
 }
 
 static bool should_pixels_be_updated(PBVHNode *node)
@@ -198,6 +199,9 @@ static bool should_pixels_be_updated(PBVHNode *node)
   if ((node->flag & PBVH_Leaf) == 0) {
     return false;
   }
+  if ((node->flag & PBVH_UpdatePixels) != 0) {
+    return true;
+  }
   NodeData *node_data = static_cast<NodeData *>(node->pixels.node_data);
   if (node_data != nullptr) {
     return false;
@@ -255,8 +259,12 @@ static bool find_nodes_to_update(PBVH *pbvh,
       if (node->pixels.node_data == nullptr) {
         NodeData *node_data = MEM_new<NodeData>(__func__);
         node->pixels.node_data = node_data;
-        r_nodes_to_update.append(node);
       }
+      else {
+        NodeData *node_data = static_cast<NodeData *>(node->pixels.node_data);
+        node_data->clear_data();
+      }
+      r_nodes_to_update.append(node);
     }
     else if (contains_triangles(node)) {
       /* Mark polygons that are owned by other leafs, so they don't be added twice. */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index d45ec80001e..8788e71e0d6 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2766,6 +2766,11 @@ static void sculpt_pbvh_update_pixels(SculptSession *ss, Object *ob)
     return;
   }
 
+  // If image is different than previous the PBVH should be tagged to fully rebuild the pixels.
+  // If any image tile image has a different resolution
+  // If uvmap changes.
+  // If other uvmap is selected.
+
   BKE_pbvh_build_pixels(ss->pbvh,
                         ss->pmap,
                         mesh->mpoly,



More information about the Bf-blender-cvs mailing list