[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55994] trunk/blender: Paint refactoring commit, non-disruptive (in theory :p)

Antony Riakiotakis kalast at gmail.com
Fri Apr 12 19:21:31 CEST 2013


Revision: 55994
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55994
Author:   psy-fi
Date:     2013-04-12 17:21:31 +0000 (Fri, 12 Apr 2013)
Log Message:
-----------
Paint refactoring commit, non-disruptive (in theory :p)

* Fix precision overflow issue with overlay previews,
* Expose alpha mask mapping to UI (still not functional but coming soon).
* More overlay refactoring:

Overlay now does minimal checking for texture refresh.
Instead, we now have invalidation flags to set an aspect of the brush
overlay as invalid. This is necessary because this way we will be able to
separate and preview different brush attributes on the overlays, using
different textures:

These attributes/aspects are:

Primary texture (main texture for sculpt, vertex, imapaint)
Secondary texture (mask/alpha texture for imapaint)
Cursor texture (cursor texture. It involves brush strength and curves)

Modified the relevant RNA property update functions and C update callback
functions to call the relevant cursor invalidation functions instead
of checking every frame for multiple properties.

Properties that affect this are:

Image changes, if image is used by current brush,
Texture slot changes, similarly
Curve changes,
Object mode change invalidates the cursor
Paint tool change invalidates the cursor.

These changes give slightly more invalidation cases than simply
comparing the relevant properties each frame, but these do not occur in
performance critical moments and it's a much more elegant system than
adding more variables to check per frame each time we add something on
the system.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py
    trunk/blender/source/blender/blenkernel/BKE_paint.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/blenkernel/intern/colortools.c
    trunk/blender/source/blender/blenkernel/intern/paint.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/render/render_update.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image_proj.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_ops.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_utils.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_vertex.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt.c
    trunk/blender/source/blender/editors/sculpt_paint/sculpt_uv.c
    trunk/blender/source/blender/editors/space_buttons/buttons_context.c
    trunk/blender/source/blender/editors/space_buttons/buttons_texture.c
    trunk/blender/source/blender/editors/space_image/image_draw.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/makesrna/intern/rna_brush.c
    trunk/blender/source/blender/makesrna/intern/rna_internal.h
    trunk/blender/source/blender/makesrna/intern/rna_texture.c
    trunk/blender/source/blender/nodes/texture/node_texture_tree.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_paint_common.py	2013-04-12 17:21:31 UTC (rev 55994)
@@ -120,6 +120,12 @@
 def brush_mask_texture_settings(layout, brush):
     mask_tex_slot = brush.mask_texture_slot
 
+    layout.label(text="Mask Mapping:")
+
+    # map_mode
+    layout.row().prop(mask_tex_slot, "mask_map_mode", text="")
+    layout.separator()
+
     if brush.mask_texture:
         layout.label(text="Mask Mapping:")
         col = layout.column()

Modified: trunk/blender/source/blender/blenkernel/BKE_paint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-04-12 17:21:31 UTC (rev 55994)
@@ -36,6 +36,7 @@
 struct BMesh;
 struct BMFace;
 struct Brush;
+struct CurveMapping;
 struct MDisps;
 struct MeshElemMap;
 struct GridPaintMask;
@@ -47,6 +48,7 @@
 struct PBVH;
 struct Scene;
 struct StrokeCache;
+struct Tex;
 struct ImagePool;
 struct UnifiedPaintSettings;
 
@@ -65,16 +67,26 @@
 	PAINT_INVALID = 6
 } PaintMode;
 
+/* overlay invalidation */
+#define PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY 1
+#define PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY 2
+#define PAINT_INVALID_OVERLAY_CURVE 4
+
+void BKE_paint_invalidate_overlay_tex (struct Scene *scene,const struct Tex *tex);
+void BKE_paint_invalidate_cursor_overlay (struct Scene *scene, struct CurveMapping *curve);
+void BKE_paint_invalidate_overlay_all(void);
+int BKE_paint_get_overlay_flags (void);
+void BKE_paint_reset_overlay_invalid (void);
+
 void BKE_paint_init(struct Paint *p, const char col[3]);
 void BKE_paint_free(struct Paint *p);
 void BKE_paint_copy(struct Paint *src, struct Paint *tar);
 
-/* TODO, give these BKE_ prefix too */
-struct Paint *paint_get_active(struct Scene *sce);
-struct Paint *paint_get_active_from_context(const struct bContext *C);
-PaintMode paintmode_get_active_from_context(const struct bContext *C);
-struct Brush *paint_brush(struct Paint *paint);
-void paint_brush_set(struct Paint *paint, struct Brush *br);
+struct Paint *BKE_paint_get_active(struct Scene *sce);
+struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
+PaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
+struct Brush *BKE_paint_brush(struct Paint *paint);
+void BKE_paint_brush_set(struct Paint *paint, struct Brush *br);
 
 /* testing face select mode
  * Texture paint could be removed since selected faces are not used

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -224,7 +224,7 @@
 	}
 
 	for (scene = bmain->scene.first; scene && ELEM(0, is_lib, is_local); scene = scene->id.next) {
-		if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
+		if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
 			if (scene->id.lib) is_lib = TRUE;
 			else is_local = TRUE;
 		}
@@ -249,9 +249,9 @@
 		BKE_id_lib_local_paths(bmain, brush->id.lib, &brush_new->id);
 		
 		for (scene = bmain->scene.first; scene; scene = scene->id.next) {
-			if (paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
+			if (BKE_paint_brush(&scene->toolsettings->imapaint.paint) == brush) {
 				if (scene->id.lib == NULL) {
-					paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
+					BKE_paint_brush_set(&scene->toolsettings->imapaint.paint, brush_new);
 				}
 			}
 		}

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -47,6 +47,7 @@
 #include "BKE_colortools.h"
 #include "BKE_curve.h"
 #include "BKE_fcurve.h"
+#include "BKE_paint.h"
 
 
 #include "IMB_colormanagement.h"

Modified: trunk/blender/source/blender/blenkernel/intern/paint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/paint.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/blenkernel/intern/paint.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -59,8 +59,48 @@
 const char PAINT_CURSOR_WEIGHT_PAINT[3] = {200, 200, 255};
 const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
 
-Paint *paint_get_active(Scene *sce)
+static int overlay_flags = 0;
+
+void BKE_paint_invalidate_overlay_tex (Scene *scene, const Tex *tex)
 {
+	Paint *p = BKE_paint_get_active(scene);
+	Brush *br = p->brush;
+
+	if (br->mtex.tex == tex)
+		overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY;
+	if (br->mask_mtex.tex == tex)
+		overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY;
+}
+
+void BKE_paint_invalidate_cursor_overlay (Scene *scene, CurveMapping *curve)
+{
+	Paint *p = BKE_paint_get_active(scene);
+	Brush *br = p->brush;
+
+	if (br->curve == curve)
+		overlay_flags |= PAINT_INVALID_OVERLAY_CURVE;
+}
+
+void BKE_paint_invalidate_overlay_all()
+{
+	overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY;
+	overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY;
+	overlay_flags |= PAINT_INVALID_OVERLAY_CURVE;
+}
+
+int BKE_paint_get_overlay_flags () {
+	return overlay_flags;
+}
+
+void BKE_paint_reset_overlay_invalid (void) {
+	overlay_flags &= ~(PAINT_INVALID_OVERLAY_TEXTURE_PRIMARY |
+	                   PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY |
+	                   PAINT_INVALID_OVERLAY_CURVE);
+}
+
+
+Paint *BKE_paint_get_active(Scene *sce)
+{
 	if (sce) {
 		ToolSettings *ts = sce->toolsettings;
 		
@@ -89,7 +129,7 @@
 	return NULL;
 }
 
-Paint *paint_get_active_from_context(const bContext *C)
+Paint *BKE_paint_get_active_from_context(const bContext *C)
 {
 	Scene *sce = CTX_data_scene(C);
 	SpaceImage *sima;
@@ -138,7 +178,7 @@
 	return NULL;
 }
 
-PaintMode paintmode_get_active_from_context(const bContext *C)
+PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
 {
 	Scene *sce = CTX_data_scene(C);
 	SpaceImage *sima;
@@ -187,12 +227,12 @@
 	return PAINT_INVALID;
 }
 
-Brush *paint_brush(Paint *p)
+Brush *BKE_paint_brush(Paint *p)
 {
 	return p ? p->brush : NULL;
 }
 
-void paint_brush_set(Paint *p, Brush *br)
+void BKE_paint_brush_set(Paint *p, Brush *br)
 {
 	if (p) {
 		id_us_min((ID *)p->brush);
@@ -228,10 +268,10 @@
 	Brush *brush;
 
 	/* If there's no brush, create one */
-	brush = paint_brush(p);
+	brush = BKE_paint_brush(p);
 	if (brush == NULL)
 		brush = BKE_brush_add(G.main, "Brush");
-	paint_brush_set(p, brush);
+	BKE_paint_brush_set(p, brush);
 
 	memcpy(p->paint_cursor_col, col, 3);
 	p->paint_cursor_col[3] = 128;

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -63,6 +63,7 @@
 #include "BKE_texture.h"
 #include "BKE_tracking.h"
 #include "BKE_unit.h"
+#include "BKE_paint.h"
 
 #include "ED_screen.h"
 #include "ED_util.h"
@@ -4323,6 +4324,7 @@
 {
 	int mx, my, a;
 	bool changed = false;
+	Scene *scene = CTX_data_scene(C);
 
 	mx = event->x;
 	my = event->y;
@@ -4451,6 +4453,7 @@
 				}
 				else {
 					curvemapping_changed(cumap, true);  /* remove doubles */
+					BKE_paint_invalidate_cursor_overlay(scene, cumap);
 				}
 			}
 

Modified: trunk/blender/source/blender/editors/render/render_update.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_update.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/editors/render/render_update.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -53,6 +53,7 @@
 #include "BKE_main.h"
 #include "BKE_material.h"
 #include "BKE_node.h"
+#include "BKE_paint.h"
 #include "BKE_scene.h"
 #include "BKE_texture.h"
 #include "BKE_world.h"
@@ -333,6 +334,10 @@
 	/* icons */
 	BKE_icon_changed(BKE_icon_getid(&tex->id));
 
+	/* paint overlays */
+	for (scene = bmain->scene.first; scene; scene = scene->id.next)
+		BKE_paint_invalidate_overlay_tex(scene, tex);
+
 	/* find materials */
 	for (ma = bmain->mat.first; ma; ma = ma->id.next) {
 		if (!material_uses_texture(ma, tex))

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-04-12 15:45:44 UTC (rev 55993)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_cursor.c	2013-04-12 17:21:31 UTC (rev 55994)
@@ -67,53 +67,34 @@
  * There is also some ugliness with sculpt-specific code.
  */
 
-typedef struct Snapshot {
-	float size[3];
-	float ofs[3];
-	float rot;
-	int BKE_brush_size_get;
+typedef struct TexSnapshot {
 	int winx;
 	int winy;
-	int brush_map_mode;
+	bool init;
+} TexSnapshot;
+
+typedef struct CurveSnapshot {
+	int BKE_brush_size_get;
 	int curve_changed_timestamp;
-} Snapshot;
+	bool init;
+} CurveSnapshot;
 
-static int same_snap(Snapshot *snap, Brush *brush, ViewContext *vc)
+static int same_tex_snap(TexSnapshot *snap, Brush *brush, ViewContext *vc)
 {
 	MTex *mtex = &brush->mtex;
 
-	return (((mtex->tex) &&
-	         equals_v3v3(mtex->ofs, snap->ofs) &&
-	         equals_v3v3(mtex->size, snap->size) &&
-	         (brush->mtex.brush_map_mode == MTEX_MAP_MODE_STENCIL ||
-	         mtex->rot == snap->rot)) &&
+	return (/* make brush smaller shouldn't cause a resample */
+	        //(mtex->brush_map_mode != MTEX_MAP_MODE_VIEW ||
+	        //(BKE_brush_size_get(vc->scene, brush) <= snap->BKE_brush_size_get)) &&
 
-	        /* make brush smaller shouldn't cause a resample */
-	        ((mtex->brush_map_mode == MTEX_MAP_MODE_VIEW &&
-	          (BKE_brush_size_get(vc->scene, brush) <= snap->BKE_brush_size_get)) ||

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list