Cleanup: Sculpt: Move update flush tags and functions to namespace

Also conver the update flags to  a regular enum class.
Only a single type was used at the same time anyway.
This commit is contained in:
Hans Goudey
2024-06-04 12:43:27 -04:00
parent 7fdfa47f23
commit b5ef3f0b6a
10 changed files with 71 additions and 55 deletions

View File

@@ -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(&region);
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<SpaceLink *>(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);

View File

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

View File

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

View File

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

View File

@@ -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)

View File

@@ -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,

View File

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

View File

@@ -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;

View File

@@ -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*/)

View File

@@ -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 {