Slightly improve undo performance in dyntopo when last operator was mask
authorAntony Riakiotakis <kalast@gmail.com>
Fri, 20 Dec 2013 11:41:38 +0000 (13:41 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Fri, 20 Dec 2013 11:42:03 +0000 (13:42 +0200)
modification. In that case no pbvh needs to be freed and recreated and
we can get away just with draw buffer update (all of them for now. When
pbvh nodes get logged for undo we will be able to only update the
affected ones).

source/blender/editors/sculpt_paint/sculpt_undo.c

index 846801ae85d3332ab51a3ac0b21a2ff6c063b0c4..e011e0f3c77bbd7bb3590dded26e6484bcf3c5a2 100644 (file)
@@ -266,7 +266,8 @@ static int sculpt_undo_restore_mask(bContext *C, DerivedMesh *dm, SculptUndoNode
        return 1;
 }
 
-static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode,
+static void sculpt_undo_bmesh_restore_generic(bContext *C,
+                                              SculptUndoNode *unode,
                                               Object *ob,
                                               SculptSession *ss)
 {
@@ -279,9 +280,27 @@ static void sculpt_undo_bmesh_restore_generic(SculptUndoNode *unode,
                unode->applied = TRUE;
        }
 
-       /* A bit lame, but for now just recreate the PBVH. The alternative
-        * is to store changes to the PBVH in the undo stack. */
-       sculpt_pbvh_clear(ob);
+       if (unode->type == SCULPT_UNDO_MASK) {
+               int i, totnode;
+               PBVHNode **nodes;
+
+               #ifdef _OPENMP
+               Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
+               #else
+               (void)C;
+               #endif
+
+               BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode);
+
+               #pragma omp parallel for schedule(guided) if (sd->flags & SCULPT_USE_OPENMP)
+               for (i = 0; i < totnode; i++)
+                       BKE_pbvh_node_mark_redraw(nodes[i]);
+       }
+       else {
+               /* A bit lame, but for now just recreate the PBVH. The alternative
+                * is to store changes to the PBVH in the undo stack. */
+               sculpt_pbvh_clear(ob);
+       }
 }
 
 /* Create empty sculpt BMesh and enable logging */
@@ -362,7 +381,7 @@ static int sculpt_undo_bmesh_restore(bContext *C,
 
                default:
                        if (ss->bm_log) {
-                               sculpt_undo_bmesh_restore_generic(unode, ob, ss);
+                               sculpt_undo_bmesh_restore_generic(C, unode, ob, ss);
                                return TRUE;
                        }
                        break;