diff options
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 64 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint_toolslots.c | 43 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 22 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 9 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_sculpt_paint.c | 20 |
10 files changed, 87 insertions, 93 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index 06e4aad68ec..6dcd3a7c446 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -130,6 +130,8 @@ void BKE_paint_init(struct Main *bmain, struct Scene *sce, ePaintMode mode, cons void BKE_paint_free(struct Paint *p); void BKE_paint_copy(struct Paint *src, struct Paint *tar, const int flag); +void BKE_paint_runtime_init(const struct ToolSettings *ts, struct Paint *paint); + void BKE_paint_cavity_curve_preset(struct Paint *p, int preset); eObjectMode BKE_paint_object_mode_from_paint_mode(ePaintMode mode); @@ -138,9 +140,6 @@ struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_lay struct Paint *BKE_paint_get_active_from_context(const struct bContext *C); ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C); struct Brush *BKE_paint_brush(struct Paint *paint); -bool BKE_paint_brush_tool_info( - const struct Scene *scene, const struct Paint *paint, - uint *r_tool_offset, eObjectMode *r_ob_mode); void BKE_paint_brush_set(struct Paint *paint, struct Brush *br); struct Palette *BKE_paint_palette(struct Paint *paint); void BKE_paint_palette_set(struct Paint *p, struct Palette *palette); @@ -177,9 +176,9 @@ void BKE_paint_stroke_get_average(struct Scene *scene, struct Object *ob, float /* Tool slot API. */ void BKE_paint_toolslots_init_from_main(struct Main *bmain); void BKE_paint_toolslots_len_ensure(struct Paint *paint, int len); -void BKE_paint_toolslots_brush_update_ex(struct Scene *scene, struct Paint *paint, struct Brush *brush); -void BKE_paint_toolslots_brush_update(struct Scene *scene, struct Paint *paint); -void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Scene *scene, struct Paint *paint); +void BKE_paint_toolslots_brush_update_ex(struct Paint *paint, struct Brush *brush); +void BKE_paint_toolslots_brush_update(struct Paint *paint); +void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint); /* Used for both vertex color and weight paint */ struct SculptVertexPaintGeomMap { diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index e6ef18efcc9..e2e926736c7 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -302,55 +302,36 @@ void BKE_paint_brush_set(Paint *p, Brush *br) } } -bool BKE_paint_brush_tool_info( - const Scene *scene, const struct Paint *paint, - uint *r_tool_offset, eObjectMode *r_ob_mode) +void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint) { - ToolSettings *ts = scene->toolsettings; if (paint == &ts->imapaint.paint) { - if (r_tool_offset != NULL) { - *r_tool_offset = offsetof(Brush, imagepaint_tool); - } - if (r_ob_mode != NULL) { - *r_ob_mode = OB_MODE_TEXTURE_PAINT; - } + paint->runtime.tool_offset = offsetof(Brush, imagepaint_tool); + paint->runtime.ob_mode = OB_MODE_TEXTURE_PAINT; } else if (paint == &ts->sculpt->paint) { - if (r_tool_offset != NULL) { - *r_tool_offset = offsetof(Brush, sculpt_tool); - } - if (r_ob_mode != NULL) { - *r_ob_mode = OB_MODE_SCULPT; - } + paint->runtime.tool_offset = offsetof(Brush, sculpt_tool); + paint->runtime.ob_mode = OB_MODE_SCULPT; } else if (paint == &ts->vpaint->paint) { - if (r_tool_offset != NULL) { - *r_tool_offset = offsetof(Brush, vertexpaint_tool); - } - if (r_ob_mode != NULL) { - *r_ob_mode = OB_MODE_VERTEX_PAINT; - } + paint->runtime.tool_offset = offsetof(Brush, vertexpaint_tool); + paint->runtime.ob_mode = OB_MODE_VERTEX_PAINT; } else if (paint == &ts->wpaint->paint) { - if (r_tool_offset != NULL) { - *r_tool_offset = offsetof(Brush, vertexpaint_tool); - } - if (r_ob_mode != NULL) { - *r_ob_mode = OB_MODE_WEIGHT_PAINT; - } + paint->runtime.tool_offset = offsetof(Brush, vertexpaint_tool); + paint->runtime.ob_mode = OB_MODE_WEIGHT_PAINT; } else if (paint == &ts->gp_paint->paint) { - if (r_tool_offset != NULL) { - *r_tool_offset = offsetof(Brush, gpencil_tool); - } - if (r_ob_mode != NULL) { - *r_ob_mode = OB_MODE_GPENCIL_PAINT; - } + paint->runtime.tool_offset = offsetof(Brush, gpencil_tool); + paint->runtime.ob_mode = OB_MODE_GPENCIL_PAINT; + } + else if (paint == &ts->uvsculpt->paint) { + /* We don't use these yet. */ + paint->runtime.tool_offset = 0; + paint->runtime.ob_mode = 0; } else { - return false; + BLI_assert(0); } - return true; } @@ -585,6 +566,15 @@ bool BKE_paint_ensure(const ToolSettings *ts, struct Paint **r_paint) &ts->vpaint->paint, &ts->wpaint->paint, &ts->uvsculpt->paint)); + +#ifdef DEBUG + struct Paint paint_test = **r_paint; + BKE_paint_runtime_init(ts, *r_paint); + /* Swap so debug doesn't hide errors when release fails. */ + SWAP(Paint, **r_paint, paint_test); + BLI_assert(paint_test.runtime.ob_mode == (*r_paint)->runtime.ob_mode); + BLI_assert(paint_test.runtime.tool_offset == (*r_paint)->runtime.tool_offset); +#endif return true; } @@ -613,6 +603,8 @@ bool BKE_paint_ensure(const ToolSettings *ts, struct Paint **r_paint) paint->flags |= PAINT_SHOW_BRUSH; + BKE_paint_runtime_init(ts, paint); + *r_paint = paint; return false; } diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index 4f728778b29..61e0f03ce9e 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -42,15 +42,14 @@ void BKE_paint_toolslots_len_ensure(Paint *paint, int len) } } -static void paint_toolslots_init(Main *bmain, Scene *scene, Paint *paint) +static void paint_toolslots_init(Main *bmain, Paint *paint) { if (paint == NULL) { return; } - uint tool_offset = 0; - eObjectMode ob_mode = 0; - bool ok = BKE_paint_brush_tool_info(scene, paint, &tool_offset, &ob_mode); - BLI_assert(ok); + const uint tool_offset = paint->runtime.tool_offset; + const eObjectMode ob_mode = paint->runtime.ob_mode; + BLI_assert(tool_offset && ob_mode); for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) { if (brush->ob_mode & ob_mode) { const int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset); @@ -67,20 +66,19 @@ void BKE_paint_toolslots_init_from_main(struct Main *bmain) { for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; - paint_toolslots_init(bmain, scene, &ts->imapaint.paint); - paint_toolslots_init(bmain, scene, &ts->sculpt->paint); - paint_toolslots_init(bmain, scene, &ts->vpaint->paint); - paint_toolslots_init(bmain, scene, &ts->wpaint->paint); - paint_toolslots_init(bmain, scene, &ts->gp_paint->paint); + paint_toolslots_init(bmain, &ts->imapaint.paint); + paint_toolslots_init(bmain, &ts->sculpt->paint); + paint_toolslots_init(bmain, &ts->vpaint->paint); + paint_toolslots_init(bmain, &ts->wpaint->paint); + paint_toolslots_init(bmain, &ts->gp_paint->paint); } } -void BKE_paint_toolslots_brush_update_ex(Scene *scene, Paint *paint, Brush *brush) +void BKE_paint_toolslots_brush_update_ex(Paint *paint, Brush *brush) { - uint tool_offset = 0; - bool ok = BKE_paint_brush_tool_info(scene, paint, &tool_offset, NULL); - BLI_assert(ok); + const uint tool_offset = paint->runtime.tool_offset; + BLI_assert(tool_offset != 0); int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset); BKE_paint_toolslots_len_ensure(paint, slot_index + 1); PaintToolSlot *tslot = &paint->tool_slots[slot_index]; @@ -89,25 +87,24 @@ void BKE_paint_toolslots_brush_update_ex(Scene *scene, Paint *paint, Brush *brus tslot->brush = brush; } -void BKE_paint_toolslots_brush_update(Scene *scene, Paint *paint) +void BKE_paint_toolslots_brush_update(Paint *paint) { if (paint->brush == NULL) { return; } - BKE_paint_toolslots_brush_update_ex(scene, paint, paint->brush); + BKE_paint_toolslots_brush_update_ex(paint, paint->brush); } /** * Run this to ensure brush types are set for each slot on entering modes * (for new scenes for example). */ -void BKE_paint_toolslots_brush_validate(Main *bmain, Scene *scene, Paint *paint) +void BKE_paint_toolslots_brush_validate(Main *bmain, Paint *paint) { /* Clear slots with invalid slots or mode (unlikely but possible). */ - uint tool_offset = 0; - eObjectMode ob_mode = 0; - bool ok = BKE_paint_brush_tool_info(scene, paint, &tool_offset, &ob_mode); - BLI_assert(ok); + const uint tool_offset = paint->runtime.tool_offset; + const eObjectMode ob_mode = paint->runtime.ob_mode; + BLI_assert(tool_offset && ob_mode); for (int i = 0; i < paint->tool_slots_len; i++) { PaintToolSlot *tslot = &paint->tool_slots[i]; if (tslot->brush) { @@ -120,8 +117,8 @@ void BKE_paint_toolslots_brush_validate(Main *bmain, Scene *scene, Paint *paint) } /* Unlikely but possible the active brush is not currently using a slot. */ - BKE_paint_toolslots_brush_update(scene, paint); + BKE_paint_toolslots_brush_update(paint); /* Fill slots from brushes. */ - paint_toolslots_init(bmain, scene, paint); + paint_toolslots_init(bmain, paint); } diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 6b5b5c59706..4a2a0b3efe2 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -5917,6 +5917,8 @@ static void link_paint(FileData *fd, Scene *sce, Paint *p) } p->palette = newlibadr_us(fd, sce->id.lib, p->palette); p->paint_cursor = NULL; + + BKE_paint_runtime_init(sce->toolsettings, p); } } @@ -6200,7 +6202,7 @@ static void link_recurs_seq(FileData *fd, ListBase *lb) } } -static void direct_link_paint(FileData *fd, Paint *p) +static void direct_link_paint(FileData *fd, const Scene *scene, Paint *p) { if (p->num_input_samples < 1) p->num_input_samples = 1; @@ -6212,15 +6214,17 @@ static void direct_link_paint(FileData *fd, Paint *p) BKE_paint_cavity_curve_preset(p, CURVE_PRESET_LINE); p->tool_slots = newdataadr(fd, p->tool_slots); + + BKE_paint_runtime_init(scene->toolsettings, p); } -static void direct_link_paint_helper(FileData *fd, Paint **paint) +static void direct_link_paint_helper(FileData *fd, const Scene *scene, Paint **paint) { /* TODO. is this needed */ (*paint) = newdataadr(fd, (*paint)); if (*paint) { - direct_link_paint(fd, *paint); + direct_link_paint(fd, scene, *paint); } } @@ -6277,13 +6281,13 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->toolsettings= newdataadr(fd, sce->toolsettings); if (sce->toolsettings) { - direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->sculpt); - direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->vpaint); - direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->wpaint); - direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->uvsculpt); - direct_link_paint_helper(fd, (Paint**)&sce->toolsettings->gp_paint); + direct_link_paint_helper(fd, sce, (Paint**)&sce->toolsettings->sculpt); + direct_link_paint_helper(fd, sce, (Paint**)&sce->toolsettings->vpaint); + direct_link_paint_helper(fd, sce, (Paint**)&sce->toolsettings->wpaint); + direct_link_paint_helper(fd, sce, (Paint**)&sce->toolsettings->uvsculpt); + direct_link_paint_helper(fd, sce, (Paint**)&sce->toolsettings->gp_paint); - direct_link_paint(fd, &sce->toolsettings->imapaint.paint); + direct_link_paint(fd, sce, &sce->toolsettings->imapaint.paint); sce->toolsettings->imapaint.paintcursor = NULL; sce->toolsettings->particle.paintcursor = NULL; diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index fc50fa7359f..1d29761bb74 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -282,7 +282,6 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op) struct wmMsgBus *mbus = CTX_wm_message_bus(C); Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); bGPdata *gpd = ED_gpencil_data_get_active(C); ToolSettings *ts = CTX_data_tool_settings(C); @@ -325,7 +324,7 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op) if (paint->brush == NULL) { BKE_brush_gpencil_presets(C); } - BKE_paint_toolslots_brush_validate(bmain, scene, &ts->gp_paint->paint); + BKE_paint_toolslots_brush_validate(bmain, &ts->gp_paint->paint); } /* setup other modes */ diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index be51c8071c2..4bd625c3cc6 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1132,7 +1132,7 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) BKE_paint_init(bmain, scene, ePaintTextureProjective, PAINT_CURSOR_TEXTURE_PAINT); - BKE_paint_toolslots_brush_validate(bmain, scene, &imapaint->paint); + BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); if (U.glreslimit != 0) GPU_free_images(bmain); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 22695423bda..103cb6b5f2f 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1249,7 +1249,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C); wmWindowManager *wm = CTX_wm_manager(C); ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); - BKE_paint_toolslots_brush_validate(bmain, scene, &ts->wpaint->paint); + BKE_paint_toolslots_brush_validate(bmain, &ts->wpaint->paint); } /* Weightpaint works by overriding colors in mesh, @@ -2395,7 +2395,7 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C); wmWindowManager *wm = CTX_wm_manager(C); ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); - BKE_paint_toolslots_brush_validate(bmain, scene, &ts->vpaint->paint); + BKE_paint_toolslots_brush_validate(bmain, &ts->vpaint->paint); } BKE_mesh_batch_cache_dirty_tag(ob->data, BKE_MESH_BATCH_DIRTY_ALL); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index d5e629f205d..84e189a86bf 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -5835,7 +5835,7 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) } else { ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, op->reports); - BKE_paint_toolslots_brush_validate(bmain, scene, &ts->sculpt->paint); + BKE_paint_toolslots_brush_validate(bmain, &ts->sculpt->paint); } WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 795a48532ce..d235cef1109 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -797,6 +797,13 @@ typedef struct TimeMarker { #define PAINT_MAX_INPUT_SAMPLES 64 +typedef struct Paint_Runtime { + /* Avoid having to compare with scene pointer everywhere. */ + unsigned int tool_offset; + unsigned short ob_mode; + char _pad[2]; +} Paint_Runtime; + /* We might want to store other things here. */ typedef struct PaintToolSlot { struct Brush *brush; @@ -831,6 +838,8 @@ typedef struct Paint { float tile_offset[3]; int pad2; + + struct Paint_Runtime runtime; } Paint; /* ------------------------------------------- */ diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index d3ff9d94a23..a66f1cc01ce 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -272,22 +272,16 @@ static char *rna_ParticleEdit_path(PointerRNA *UNUSED(ptr)) static bool rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value) { - Scene *scene = (Scene *)ptr->id.data; const Paint *paint = ptr->data; Brush *brush = value.id.data; - eObjectMode ob_mode = 0; - uint brush_tool_offset = 0; - - /* check the origin of the Paint struct to see which paint - * mode to select from */ - - bool ok = BKE_paint_brush_tool_info(scene, paint, &brush_tool_offset, &ob_mode); - BLI_assert(ok); + const uint tool_offset = paint->runtime.tool_offset; + const eObjectMode ob_mode = paint->runtime.ob_mode; + BLI_assert(tool_offset && ob_mode); if (brush->ob_mode & ob_mode) { if (paint->brush) { - const char *tool_a = (const char *)POINTER_OFFSET(paint->brush, brush_tool_offset); - const char *tool_b = (const char *)POINTER_OFFSET(brush, brush_tool_offset); + const char *tool_a = (const char *)POINTER_OFFSET(paint->brush, tool_offset); + const char *tool_b = (const char *)POINTER_OFFSET(brush, tool_offset); if (*tool_a == *tool_b) { return true; } @@ -443,11 +437,11 @@ static char *rna_ParticleBrush_path(PointerRNA *UNUSED(ptr)) static void rna_Paint_brush_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { - Scene *scene = (Scene *)ptr->id.data; Paint *paint = ptr->data; Brush *br = paint->brush; BKE_paint_invalidate_overlay_all(); - BKE_paint_toolslots_brush_update(scene, paint); + /* Needed because we're not calling 'BKE_paint_brush_set' which handles this. */ + BKE_paint_toolslots_brush_update(paint); WM_main_add_notifier(NC_BRUSH | NA_SELECTED, br); } |