[Bf-blender-cvs] [1b928c2d9a4] blender2.8: Paint: add tool offset & mode to runtime data

Campbell Barton noreply at git.blender.org
Mon Nov 5 06:23:20 CET 2018


Commit: 1b928c2d9a4b4b4a57046176912e0ae6d77f9a1d
Author: Campbell Barton
Date:   Mon Nov 5 16:18:43 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB1b928c2d9a4b4b4a57046176912e0ae6d77f9a1d

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'

===================================================================

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/paint_toolslots.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_sculpt_paint.c

===================================================================

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->tools

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list