Brush: Add Main argument to BKE_paint_ensure

This is used by the brush assets branch. Though it is unused currently, the
argument is added now to reduce the trivial boilerplate changes in the diff.
This commit is contained in:
Hans Goudey
2024-05-01 11:44:16 -04:00
parent 722ad638c5
commit c549c1b29c
11 changed files with 38 additions and 35 deletions

View File

@@ -173,7 +173,7 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name);
/**
* Call when entering each respective paint mode.
*/
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint);
bool BKE_paint_ensure(Main *bmain, ToolSettings *ts, Paint **r_paint);
void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3]);
void BKE_paint_free(Paint *p);
/**
@@ -188,7 +188,7 @@ void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint);
void BKE_paint_cavity_curve_preset(Paint *p, int preset);
eObjectMode BKE_paint_object_mode_from_paintmode(PaintMode mode);
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode);
bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode);
Paint *BKE_paint_get_active_from_paintmode(Scene *sce, PaintMode mode);
const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(PaintMode mode);
const char *BKE_paint_get_tool_enum_translation_context_from_paintmode(PaintMode mode);
@@ -732,7 +732,7 @@ void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
Main *bmain,
Object *ob,
MultiresModifierData *mmd);
void BKE_sculpt_toolsettings_data_ensure(Scene *scene);
void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene);
PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob);

View File

@@ -326,7 +326,7 @@ void BKE_paint_reset_overlay_invalid(ePaintOverlayControlFlags flag)
overlay_flags &= ~(flag);
}
bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
bool BKE_paint_ensure_from_paintmode(Main *bmain, Scene *sce, PaintMode mode)
{
ToolSettings *ts = sce->toolsettings;
Paint **paint_ptr = nullptr;
@@ -371,7 +371,7 @@ bool BKE_paint_ensure_from_paintmode(Scene *sce, PaintMode mode)
break;
}
if (paint_ptr) {
BKE_paint_ensure(ts, paint_ptr);
BKE_paint_ensure(bmain, ts, paint_ptr);
return true;
}
return false;
@@ -1091,7 +1091,7 @@ eObjectMode BKE_paint_object_mode_from_paintmode(const PaintMode mode)
}
}
bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
bool BKE_paint_ensure(Main * /*bmain*/, ToolSettings *ts, Paint **r_paint)
{
Paint *paint = nullptr;
if (*r_paint) {
@@ -1176,7 +1176,7 @@ void BKE_paint_init(Main *bmain, Scene *sce, PaintMode mode, const uchar col[3])
UnifiedPaintSettings *ups = &sce->toolsettings->unified_paint_settings;
Paint *paint = BKE_paint_get_active_from_paintmode(sce, mode);
BKE_paint_ensure_from_paintmode(sce, mode);
BKE_paint_ensure_from_paintmode(bmain, sce, mode);
/* If there's no brush, create one */
Brush *brush = BKE_paint_brush(paint);
@@ -2001,9 +2001,9 @@ void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph,
}
}
void BKE_sculpt_toolsettings_data_ensure(Scene *scene)
void BKE_sculpt_toolsettings_data_ensure(Main *bmain, Scene *scene)
{
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->sculpt);
BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->sculpt);
Sculpt *sd = scene->toolsettings->sculpt;

View File

@@ -2874,10 +2874,10 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
ToolSettings *ts = scene->toolsettings;
/* Ensure new Paint modes. */
BKE_paint_ensure_from_paintmode(scene, PaintMode::GPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::GPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
/* Set default Draw brush. */
if (brush != nullptr) {
@@ -2918,9 +2918,9 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain)
/* Reset all grease pencil brushes. */
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
/* Ensure new Paint modes. */
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
}
}

View File

@@ -555,9 +555,9 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
}
/* Ensure new Paint modes. */
BKE_paint_ensure_from_paintmode(scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(scene, PaintMode::WeightGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::VertexGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::SculptGPencil);
BKE_paint_ensure_from_paintmode(bmain, scene, PaintMode::WeightGPencil);
/* Enable cursor. */
if (ts->gp_paint) {

View File

@@ -420,8 +420,8 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op)
if (mode == OB_MODE_PAINT_GPENCIL_LEGACY) {
/* Be sure we have brushes and Paint settings.
* Need Draw and Vertex (used for Tint). */
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint);
BKE_brush_gpencil_paint_presets(bmain, ts, false);
@@ -572,7 +572,7 @@ static int gpencil_sculptmode_toggle_exec(bContext *C, wmOperator *op)
if (mode == OB_MODE_SCULPT_GPENCIL_LEGACY) {
/* Be sure we have brushes. */
BKE_paint_ensure(ts, (Paint **)&ts->gp_sculptpaint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_sculptpaint);
const bool reset_mode = (BKE_paint_brush(&ts->gp_sculptpaint->paint) == nullptr);
BKE_brush_gpencil_sculpt_presets(bmain, ts, reset_mode);
@@ -711,7 +711,7 @@ static int gpencil_weightmode_toggle_exec(bContext *C, wmOperator *op)
if (mode == OB_MODE_WEIGHT_GPENCIL_LEGACY) {
/* Be sure we have brushes. */
Paint *weight_paint = BKE_paint_get_active_from_paintmode(scene, PaintMode::WeightGPencil);
BKE_paint_ensure(ts, &weight_paint);
BKE_paint_ensure(bmain, ts, &weight_paint);
if (ob->type == OB_GREASE_PENCIL) {
ED_paint_cursor_start(weight_paint, grease_pencil_poll_weight_cursor);
@@ -829,8 +829,8 @@ static int gpencil_vertexmode_toggle_exec(bContext *C, wmOperator *op)
if (mode == OB_MODE_VERTEX_GPENCIL_LEGACY) {
/* Be sure we have brushes.
* Need Draw as well (used for Palettes). */
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(ts, (Paint **)&ts->gp_vertexpaint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_vertexpaint);
const bool reset_mode = (BKE_paint_brush(&ts->gp_vertexpaint->paint) == nullptr);
BKE_brush_gpencil_vertex_presets(bmain, ts, reset_mode);

View File

@@ -1428,7 +1428,7 @@ void ED_gpencil_add_defaults(bContext *C, Object *ob)
Main *bmain = CTX_data_main(C);
ToolSettings *ts = CTX_data_tool_settings(C);
BKE_paint_ensure(ts, (Paint **)&ts->gp_paint);
BKE_paint_ensure(bmain, ts, (Paint **)&ts->gp_paint);
Paint *paint = &ts->gp_paint->paint;
Brush *brush = BKE_paint_brush(paint);
/* if not exist, create a new one */

View File

@@ -282,7 +282,8 @@ static void curves_sculptmode_enter(bContext *C)
wmMsgBus *mbus = CTX_wm_message_bus(C);
Object *ob = CTX_data_active_object(C);
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt);
BKE_paint_ensure(
CTX_data_main(C), scene->toolsettings, (Paint **)&scene->toolsettings->curves_sculpt);
CurvesSculpt *curves_sculpt = scene->toolsettings->curves_sculpt;
ob->mode = OB_MODE_SCULPT_CURVES;

View File

@@ -556,7 +556,8 @@ void get_brush_alpha_data(const Scene *scene,
void init_stroke(Depsgraph *depsgraph, Object *ob);
void init_session_data(const ToolSettings *ts, Object *ob);
void init_session(Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode);
void init_session(
Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode);
Vector<PBVHNode *> pbvh_gather_generic(Object *ob, VPaint *wp, Brush *brush);

View File

@@ -214,10 +214,11 @@ void init_stroke(Depsgraph *depsgraph, Object *ob)
}
/* Toggle operator for turning vertex paint mode on or off (copied from sculpt.cc) */
void init_session(Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode)
void init_session(
Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, eObjectMode object_mode)
{
/* Create persistent sculpt mode data */
BKE_sculpt_toolsettings_data_ensure(scene);
BKE_sculpt_toolsettings_data_ensure(bmain, scene);
BLI_assert(ob->sculpt == nullptr);
ob->sculpt = MEM_new<SculptSession>(__func__);
@@ -321,7 +322,7 @@ void mode_enter_generic(
const PaintMode paint_mode = PaintMode::Vertex;
ED_mesh_color_ensure(mesh, nullptr);
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->vpaint);
BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->vpaint);
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
ED_paint_cursor_start(paint, vertex_paint_poll);
BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_VERTEX_PAINT);
@@ -329,7 +330,7 @@ void mode_enter_generic(
else if (mode_flag == OB_MODE_WEIGHT_PAINT) {
const PaintMode paint_mode = PaintMode::Weight;
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->wpaint);
BKE_paint_ensure(bmain, scene->toolsettings, (Paint **)&scene->toolsettings->wpaint);
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
ED_paint_cursor_start(paint, weight_paint_poll);
BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_WEIGHT_PAINT);
@@ -351,7 +352,7 @@ void mode_enter_generic(
BKE_sculptsession_free(ob);
}
vwpaint::init_session(depsgraph, scene, ob, mode_flag);
vwpaint::init_session(bmain, depsgraph, scene, ob, mode_flag);
/* Flush object mode. */
DEG_id_tag_update(&ob->id, ID_RECALC_SYNC_TO_EVAL);

View File

@@ -280,7 +280,7 @@ namespace blender::ed::sculpt_paint {
static void sculpt_init_session(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
{
/* Create persistent sculpt mode data. */
BKE_sculpt_toolsettings_data_ensure(scene);
BKE_sculpt_toolsettings_data_ensure(bmain, scene);
/* Create sculpt mode session data. */
if (ob->sculpt != nullptr) {

View File

@@ -187,7 +187,7 @@ static void toolsystem_ref_link(bContext *C, WorkSpace *workspace, bToolRef *tre
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
if (workspace == WM_window_get_active_workspace(win)) {
Scene *scene = WM_window_get_active_scene(win);
BKE_paint_ensure_from_paintmode(scene, paint_mode);
BKE_paint_ensure_from_paintmode(bmain, scene, paint_mode);
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
Brush *brush = BKE_paint_toolslots_brush_get(paint, slot_index);
if (brush == nullptr) {