diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 0b7a34f4d2c..c41d94f15df 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -5281,9 +5281,10 @@ static void sculpt_restore_mesh(const Sculpt &sd, Object &ob) } } -void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) +namespace blender::ed::sculpt_paint { + +void flush_update_step(bContext *C, UpdateType update_type) { - using namespace blender; Depsgraph &depsgraph = *CTX_data_depsgraph_pointer(C); Object &ob = *CTX_data_active_object(C); SculptSession &ss = *ob.sculpt; @@ -5303,9 +5304,9 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) multires_mark_as_modified(&depsgraph, &ob, MULTIRES_COORDS_MODIFIED); } - if ((update_flags & SCULPT_UPDATE_IMAGE) != 0) { + if ((update_type == UpdateType::Image) != 0) { ED_region_tag_redraw(®ion); - if (update_flags == SCULPT_UPDATE_IMAGE) { + if (update_type == UpdateType::Image) { /* Early exit when only need to update the images. We don't want to tag any geometry updates * that would rebuilt the PBVH. */ return; @@ -5327,7 +5328,7 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) * only the part of the 3D viewport where changes happened. */ rcti r; - if (update_flags & SCULPT_UPDATE_COORDS) { + if (update_type == UpdateType::Position) { bke::pbvh::update_bounds(*ss.pbvh, PBVH_UpdateBB); } @@ -5349,7 +5350,7 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) } } - if (update_flags & SCULPT_UPDATE_COORDS && !ss.shapekey_active) { + if (update_type == UpdateType::Position && !ss.shapekey_active) { if (BKE_pbvh_type(*ss.pbvh) == PBVH_FACES) { /* Updating mesh positions without marking caches dirty is generally not good, but since * sculpt mode has special requirements and is expected to have sole ownership of the mesh it @@ -5378,9 +5379,8 @@ void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags) } } -void SCULPT_flush_update_done(const bContext *C, Object &ob, SculptUpdateType update_flags) +void flush_update_done(const bContext *C, Object &ob, UpdateType update_type) { - using namespace blender; /* After we are done drawing the stroke, check if we need to do a more * expensive depsgraph tag to update geometry. */ wmWindowManager *wm = CTX_wm_manager(C); @@ -5418,7 +5418,7 @@ void SCULPT_flush_update_done(const bContext *C, Object &ob, SculptUpdateType up } } - if (update_flags & SCULPT_UPDATE_IMAGE) { + if (update_type == UpdateType::Image) { LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { SpaceLink *sl = static_cast(area->spacedata.first); if (sl->spacetype != SPACE_IMAGE) { @@ -5429,20 +5429,20 @@ void SCULPT_flush_update_done(const bContext *C, Object &ob, SculptUpdateType up } } - if (update_flags & SCULPT_UPDATE_COORDS) { + if (update_type == UpdateType::Position) { bke::pbvh::update_bounds(*ss.pbvh, PBVH_UpdateOriginalBB); /* Coordinates were modified, so fake neighbors are not longer valid. */ SCULPT_fake_neighbors_free(ob); } - if (update_flags & SCULPT_UPDATE_MASK) { + if (update_type == UpdateType::Mask) { bke::pbvh::update_mask(*ss.pbvh); } BKE_sculpt_attributes_destroy_temporary_stroke(&ob); - if (update_flags & SCULPT_UPDATE_COORDS) { + if (update_type == UpdateType::Position) { if (BKE_pbvh_type(*ss.pbvh) == PBVH_BMESH) { BKE_pbvh_bmesh_after_stroke(*ss.pbvh); } @@ -5460,6 +5460,8 @@ void SCULPT_flush_update_done(const bContext *C, Object &ob, SculptUpdateType up } } +} // namespace blender::ed::sculpt_paint + /* Returns whether the mouse/stylus is over the mesh (1) * or over the background (0). */ static bool over_mesh(bContext *C, wmOperator * /*op*/, const float mval[2]) @@ -5633,18 +5635,18 @@ static void sculpt_stroke_update_step(bContext *C, /* Cleanup. */ if (brush.sculpt_tool == SCULPT_TOOL_MASK) { - SCULPT_flush_update_step(C, SCULPT_UPDATE_MASK); + flush_update_step(C, UpdateType::Mask); } else if (SCULPT_tool_is_paint(brush.sculpt_tool)) { if (SCULPT_use_image_paint_brush(tool_settings.paint_mode, ob)) { - SCULPT_flush_update_step(C, SCULPT_UPDATE_IMAGE); + flush_update_step(C, UpdateType::Image); } else { - SCULPT_flush_update_step(C, SCULPT_UPDATE_COLOR); + flush_update_step(C, UpdateType::Color); } } else { - SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); + flush_update_step(C, UpdateType::Position); } } @@ -5691,19 +5693,19 @@ static void sculpt_stroke_done(const bContext *C, PaintStroke * /*stroke*/) sculpt_stroke_undo_end(C, brush); if (brush->sculpt_tool == SCULPT_TOOL_MASK) { - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); + flush_update_done(C, ob, UpdateType::Mask); } else if (brush->sculpt_tool == SCULPT_TOOL_PAINT) { if (SCULPT_use_image_paint_brush(tool_settings->paint_mode, ob)) { - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_IMAGE); + flush_update_done(C, ob, UpdateType::Image); } else { BKE_sculpt_attributes_destroy_temporary_stroke(&ob); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR); + flush_update_done(C, ob, UpdateType::Color); } } else { - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); + flush_update_done(C, ob, UpdateType::Position); } WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, &ob); diff --git a/source/blender/editors/sculpt_paint/sculpt_cloth.cc b/source/blender/editors/sculpt_paint/sculpt_cloth.cc index 1b80315985b..d926343cbb7 100644 --- a/source/blender/editors/sculpt_paint/sculpt_cloth.cc +++ b/source/blender/editors/sculpt_paint/sculpt_cloth.cc @@ -1479,7 +1479,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent if (event->type == LEFTMOUSE && event->val == KM_RELEASE) { filter::cache_free(ss); undo::push_end(ob); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); + flush_update_done(C, ob, UpdateType::Position); return OPERATOR_FINISHED; } @@ -1518,7 +1518,7 @@ static int sculpt_cloth_filter_modal(bContext *C, wmOperator *op, const wmEvent if (ss.deform_modifiers_active || ss.shapekey_active) { SCULPT_flush_stroke_deform(sd, ob, true); } - SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); + flush_update_step(C, UpdateType::Position); return OPERATOR_RUNNING_MODAL; } diff --git a/source/blender/editors/sculpt_paint/sculpt_expand.cc b/source/blender/editors/sculpt_paint/sculpt_expand.cc index faea5328b0e..ed1d7588540 100644 --- a/source/blender/editors/sculpt_paint/sculpt_expand.cc +++ b/source/blender/editors/sculpt_paint/sculpt_expand.cc @@ -1228,20 +1228,20 @@ static void sculpt_expand_restore_original_state(bContext *C, Object &ob, Cache switch (expand_cache->target) { case SCULPT_EXPAND_TARGET_MASK: write_mask_data(ss, expand_cache->original_mask); - SCULPT_flush_update_step(C, SCULPT_UPDATE_MASK); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); + flush_update_step(C, UpdateType::Mask); + flush_update_done(C, ob, UpdateType::Mask); SCULPT_tag_update_overlays(C); break; case SCULPT_EXPAND_TARGET_FACE_SETS: sculpt_expand_restore_face_set_data(ob, expand_cache); - SCULPT_flush_update_step(C, SCULPT_UPDATE_FACE_SET); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_FACE_SET); + flush_update_step(C, UpdateType::FaceSet); + flush_update_done(C, ob, UpdateType::FaceSet); SCULPT_tag_update_overlays(C); break; case SCULPT_EXPAND_TARGET_COLORS: sculpt_expand_restore_color_data(ss, expand_cache); - SCULPT_flush_update_step(C, SCULPT_UPDATE_COLOR); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR); + flush_update_step(C, UpdateType::Color); + flush_update_done(C, ob, UpdateType::Color); break; } } @@ -1478,12 +1478,12 @@ static void sculpt_expand_update_for_vertex(bContext *C, Object &ob, const PBVHV sculpt_expand_mask_update_task(ss, mask_write, expand_cache->nodes[i]); } }); - SCULPT_flush_update_step(C, SCULPT_UPDATE_MASK); + flush_update_step(C, UpdateType::Mask); break; } case SCULPT_EXPAND_TARGET_FACE_SETS: sculpt_expand_face_sets_update(ob, expand_cache); - SCULPT_flush_update_step(C, SCULPT_UPDATE_FACE_SET); + flush_update_step(C, UpdateType::FaceSet); break; case SCULPT_EXPAND_TARGET_COLORS: threading::parallel_for(expand_cache->nodes.index_range(), 1, [&](const IndexRange range) { @@ -1491,7 +1491,7 @@ static void sculpt_expand_update_for_vertex(bContext *C, Object &ob, const PBVHV sculpt_expand_colors_update_task(ss, expand_cache->nodes[i]); } }); - SCULPT_flush_update_step(C, SCULPT_UPDATE_COLOR); + flush_update_step(C, UpdateType::Color); break; } } @@ -1586,13 +1586,13 @@ static void sculpt_expand_finish(bContext *C) switch (ss.expand_cache->target) { case SCULPT_EXPAND_TARGET_MASK: - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); + flush_update_done(C, ob, UpdateType::Mask); break; case SCULPT_EXPAND_TARGET_FACE_SETS: - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_FACE_SET); + flush_update_done(C, ob, UpdateType::FaceSet); break; case SCULPT_EXPAND_TARGET_COLORS: - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR); + flush_update_done(C, ob, UpdateType::Color); break; } diff --git a/source/blender/editors/sculpt_paint/sculpt_face_set.cc b/source/blender/editors/sculpt_paint/sculpt_face_set.cc index 57be481892f..d24a9fa93d3 100644 --- a/source/blender/editors/sculpt_paint/sculpt_face_set.cc +++ b/source/blender/editors/sculpt_paint/sculpt_face_set.cc @@ -1578,8 +1578,8 @@ static void edit_modify_coordinates( if (ss.deform_modifiers_active || ss.shapekey_active) { SCULPT_flush_stroke_deform(sd, ob, true); } - SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); + flush_update_step(C, UpdateType::Position); + flush_update_done(C, ob, UpdateType::Position); undo::push_end(ob); } diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc index df2dfc7f1c2..3797dee293b 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc @@ -286,7 +286,7 @@ static void sculpt_color_filter_apply(bContext *C, wmOperator *op, Object &ob) } }); - SCULPT_flush_update_step(C, SCULPT_UPDATE_COLOR); + flush_update_step(C, UpdateType::Color); } static void sculpt_color_filter_end(bContext *C, Object &ob) @@ -295,7 +295,7 @@ static void sculpt_color_filter_end(bContext *C, Object &ob) undo::push_end(ob); filter::cache_free(ss); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COLOR); + flush_update_done(C, ob, UpdateType::Color); } static int sculpt_color_filter_modal(bContext *C, wmOperator *op, const wmEvent *event) diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc index 4676bcee3c9..c7b8cbfbcd9 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_mesh.cc @@ -733,7 +733,7 @@ static void sculpt_mesh_filter_apply(bContext *C, wmOperator *op) bke::pbvh::update_normals(*ss.pbvh, ss.subdiv_ccg); } - SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); + flush_update_step(C, UpdateType::Position); } static void sculpt_mesh_update_strength(wmOperator *op, @@ -784,7 +784,7 @@ static void sculpt_mesh_filter_end(bContext *C) SculptSession &ss = *ob.sculpt; cache_free(ss); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); + flush_update_done(C, ob, UpdateType::Position); } static int sculpt_mesh_filter_confirm(SculptSession &ss, diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.hh b/source/blender/editors/sculpt_paint/sculpt_intern.hh index f47c5e33296..6a921c20061 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_intern.hh @@ -61,15 +61,19 @@ struct wmOperatorType; /** \name Sculpt Types * \{ */ -enum SculptUpdateType { - SCULPT_UPDATE_COORDS = 1 << 0, - SCULPT_UPDATE_MASK = 1 << 1, - SCULPT_UPDATE_VISIBILITY = 1 << 2, - SCULPT_UPDATE_COLOR = 1 << 3, - SCULPT_UPDATE_IMAGE = 1 << 4, - SCULPT_UPDATE_FACE_SET = 1 << 5, +namespace blender::ed::sculpt_paint { + +enum class UpdateType { + Position, + Mask, + Visibility, + Color, + Image, + FaceSet, }; +} + struct SculptCursorGeometryInfo { blender::float3 location; blender::float3 normal; @@ -726,8 +730,18 @@ bool SCULPT_handles_colors_report(SculptSession &ss, ReportList *reports); /** \name Sculpt Update Functions * \{ */ -void SCULPT_flush_update_step(bContext *C, SculptUpdateType update_flags); -void SCULPT_flush_update_done(const bContext *C, Object &ob, SculptUpdateType update_flags); +namespace blender::ed::sculpt_paint { + +/** + * Triggers redraws, updates, and dependency graph tags as necessary after each brush calculation. + */ +void flush_update_step(bContext *C, UpdateType update_type); +/** + * Triggers redraws, updates, and dependency graph tags as necessary when a brush stroke finishes. + */ +void flush_update_done(const bContext *C, Object &ob, UpdateType update_type); + +} void SCULPT_pbvh_clear(Object &ob); diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index 5d3eed27ae1..b2a65f9b4ea 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -967,7 +967,7 @@ static int sculpt_mask_by_color_invoke(bContext *C, wmOperator *op, const wmEven bke::pbvh::update_mask(*ss.pbvh); undo::push_end(ob); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); + flush_update_done(C, ob, UpdateType::Mask); DEG_id_tag_update(&ob.id, ID_RECALC_GEOMETRY); return OPERATOR_FINISHED; @@ -1176,7 +1176,7 @@ static int sculpt_bake_cavity_exec(bContext *C, wmOperator *op) bke::pbvh::update_mask(*ss.pbvh); undo::push_end(ob); - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_MASK); + flush_update_done(C, ob, UpdateType::Mask); SCULPT_tag_update_overlays(C); return OPERATOR_FINISHED; diff --git a/source/blender/editors/sculpt_paint/sculpt_project.cc b/source/blender/editors/sculpt_paint/sculpt_project.cc index 8bc430ea875..9ba5959e45f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_project.cc +++ b/source/blender/editors/sculpt_paint/sculpt_project.cc @@ -90,8 +90,8 @@ static void gesture_end(bContext &C, gesture::GestureData &gesture_data) SCULPT_flush_stroke_deform(sd, *gesture_data.vc.obact, true); } - SCULPT_flush_update_step(&C, SCULPT_UPDATE_COORDS); - SCULPT_flush_update_done(&C, *gesture_data.vc.obact, SCULPT_UPDATE_COORDS); + flush_update_step(&C, UpdateType::Position); + flush_update_done(&C, *gesture_data.vc.obact, UpdateType::Position); } static void init_operation(gesture::GestureData &gesture_data, wmOperator & /*op*/) diff --git a/source/blender/editors/sculpt_paint/sculpt_transform.cc b/source/blender/editors/sculpt_paint/sculpt_transform.cc index 90958689419..540a5321131 100644 --- a/source/blender/editors/sculpt_paint/sculpt_transform.cc +++ b/source/blender/editors/sculpt_paint/sculpt_transform.cc @@ -321,7 +321,7 @@ void update_modal_transform(bContext *C, Object &ob) SCULPT_flush_stroke_deform(sd, ob, true); } - SCULPT_flush_update_step(C, SCULPT_UPDATE_COORDS); + flush_update_step(C, UpdateType::Position); } void end_transform(bContext *C, Object &ob) @@ -330,7 +330,7 @@ void end_transform(bContext *C, Object &ob) if (ss.filter_cache) { filter::cache_free(ss); } - SCULPT_flush_update_done(C, ob, SCULPT_UPDATE_COORDS); + flush_update_done(C, ob, UpdateType::Position); } enum class PivotPositionMode {