diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-05 08:18:43 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-05 08:18:43 +0300 |
commit | 1b928c2d9a4b4b4a57046176912e0ae6d77f9a1d (patch) | |
tree | c19777cbf0b7108f7440a62eea228355488d29b9 /source/blender/blenkernel | |
parent | 56917bcf731c6d3568d920a6ccbec524c25aaea1 (diff) |
Paint: add tool offset & mode to runtime data
It was getting too impractical to call BKE_paint_brush_tool_info
which needed to lookup the scene pointers.
Now each store tool offset and brush mode in 'Paint.runtime'
Diffstat (limited to 'source/blender/blenkernel')
-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 |
3 files changed, 53 insertions, 65 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); } |