[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55090] trunk/blender/source/blender: Texture paint refactoring commit

Antony Riakiotakis kalast at gmail.com
Thu Mar 7 13:11:38 CET 2013


Revision: 55090
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55090
Author:   psy-fi
Date:     2013-03-07 12:11:38 +0000 (Thu, 07 Mar 2013)
Log Message:
-----------
Texture paint refactoring commit

This is as close as I can get to keeping the old code intact. After this
commit, I will have to change existing code paths, making testing of
functionality harder.

Changes:

* Keep only projective texturing code in paint_image_proj.c
* Move 2D code to paint_image_2d.c. This needed the introduction of
allocation/cleanup functions for the relevant structures.
* Common code interface for both modes stays in paint_image.c (which
still includes all old code, system should work as it did with the
exception of non-projective 3D paint mode) and is made public. This is
not a lot of code, only rectangle invalidation and undo system.
* Changed the naming in the new code slightly: imapaint_ prefixed functions refer to
common functions used by both systems, paint_2d_ prefixed to 2d
painting. There will be an interface for the projection painting as
well. Probably there is some leftover naming conversions to do.

TODO:

* Move operator init/exec/modal to common interface file
* Get rid of old BKE_brush_painter_paint, now brush_painter_2d_paint.
All code uses stroke system for the stroke management
* Write space pressure management for the paint stroke system (for other
systems to access as well :) )
* Move texture paint tablet presssure exception code for old bugs to
stroke system (makes me wonder...aren't other systems also influenced by
these pressure issues?) or up in the function hierarchy inside texture
paint. This code is still not there so users with tablets may notice
some issues.
* possibly change other systems to pre-multiply pressure with the
relevant influenced attributes in the stroke function. This could get
tricky though and it's possible that it could backfire.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_brush.h
    trunk/blender/source/blender/blenkernel/BKE_paint.h
    trunk/blender/source/blender/blenkernel/intern/brush.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_intern.h
    trunk/blender/source/blender/editors/sculpt_paint/paint_stroke.c

Modified: trunk/blender/source/blender/blenkernel/BKE_brush.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_brush.h	2013-03-07 11:53:11 UTC (rev 55089)
+++ trunk/blender/source/blender/blenkernel/BKE_brush.h	2013-03-07 12:11:38 UTC (rev 55090)
@@ -79,13 +79,13 @@
 typedef struct BrushPainter BrushPainter;
 typedef int (*BrushFunc)(void *user, struct ImBuf *ibuf, const float lastpos[2], const float pos[2]);
 
-BrushPainter *BKE_brush_painter_new(struct Scene *scene, struct Brush *brush);
-void BKE_brush_painter_require_imbuf(BrushPainter *painter, short flt,
+BrushPainter *brush_painter_2d_new(struct Scene *scene, struct Brush *brush);
+void brush_painter_2d_require_imbuf(BrushPainter *painter, short flt,
                                      short texonly, int size);
-int BKE_brush_painter_paint(BrushPainter *painter, BrushFunc func, const float pos[2],
+int brush_painter_2d_paint(BrushPainter *painter, BrushFunc func, const float pos[2],
                             double time, float pressure, void *user, int use_color_correction);
-void BKE_brush_painter_break_stroke(BrushPainter *painter);
-void BKE_brush_painter_free(BrushPainter *painter);
+void brush_painter_2d_break_stroke(BrushPainter *painter);
+void brush_painter_2d_free(BrushPainter *painter);
 
 /* texture */
 unsigned int *BKE_brush_gen_texture_cache(struct Brush *br, int half_side);

Modified: trunk/blender/source/blender/blenkernel/BKE_paint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-03-07 11:53:11 UTC (rev 55089)
+++ trunk/blender/source/blender/blenkernel/BKE_paint.h	2013-03-07 12:11:38 UTC (rev 55090)
@@ -54,7 +54,7 @@
 extern const char PAINT_CURSOR_WEIGHT_PAINT[3];
 extern const char PAINT_CURSOR_TEXTURE_PAINT[3];
 
-typedef enum {
+typedef enum PaintMode{
 	PAINT_SCULPT,
 	PAINT_VERTEX,
 	PAINT_WEIGHT,

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-07 11:53:11 UTC (rev 55089)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2013-03-07 12:11:38 UTC (rev 55090)
@@ -53,6 +53,7 @@
 #include "IMB_imbuf_types.h"
 
 #include "RE_render_ext.h" /* externtex */
+#include "RE_shader_ext.h"
 
 static void brush_defaults(Brush *brush)
 {
@@ -841,6 +842,49 @@
 	return curvemapping_evaluateF(br->curve, 0, p);
 }
 
+/* TODO: should probably be unified with BrushPainter stuff? */
+unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side)
+{
+	unsigned int *texcache = NULL;
+	MTex *mtex = &br->mtex;
+	TexResult texres = {0};
+	int hasrgb, ix, iy;
+	int side = half_side * 2;
+
+	if (mtex->tex) {
+		float x, y, step = 2.0 / side, co[3];
+
+		texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache");
+
+		/*do normalized cannonical view coords for texture*/
+		for (y = -1.0, iy = 0; iy < side; iy++, y += step) {
+			for (x = -1.0, ix = 0; ix < side; ix++, x += step) {
+				co[0] = x;
+				co[1] = y;
+				co[2] = 0.0f;
+
+				/* This is copied from displace modifier code */
+				hasrgb = multitex_ext(mtex->tex, co, NULL, NULL, 0, &texres, NULL);
+
+				/* if the texture gave an RGB value, we assume it didn't give a valid
+				 * intensity, so calculate one (formula from do_material_tex).
+				 * if the texture didn't give an RGB value, copy the intensity across
+				 */
+				if (hasrgb & TEX_RGB)
+					texres.tin = rgb_to_grayscale(&texres.tr);
+
+				((char *)texcache)[(iy * side + ix) * 4] =
+				((char *)texcache)[(iy * side + ix) * 4 + 1] =
+				((char *)texcache)[(iy * side + ix) * 4 + 2] =
+				((char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(texres.tin * 255.0f);
+			}
+		}
+	}
+
+	return texcache;
+}
+
+
 /**** Radial Control ****/
 struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br)
 {

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-03-07 11:53:11 UTC (rev 55089)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-03-07 12:11:38 UTC (rev 55090)
@@ -140,9 +140,6 @@
 #define IMAPAINT_TILE_SIZE          (1 << IMAPAINT_TILE_BITS)
 #define IMAPAINT_TILE_NUMBER(size)  (((size) + IMAPAINT_TILE_SIZE - 1) >> IMAPAINT_TILE_BITS)
 
-static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint);
-
-
 typedef struct ImagePaintState {
 	SpaceImage *sima;
 	View2D *v2d;
@@ -171,11 +168,6 @@
 	MTFace         *dm_mtface;
 } ImagePaintState;
 
-typedef struct ImagePaintPartialRedraw {
-	int x1, y1, x2, y2;  /* XXX, could use 'rcti' */
-	int enabled;
-} ImagePaintPartialRedraw;
-
 typedef struct ImagePaintRegion {
 	int destx, desty;
 	int srcx, srcy;
@@ -411,8 +403,19 @@
 	char gen_type;
 } UndoImageTile;
 
+/* this is a static resource for non-globality,
+ * Maybe it should be exposed as part of the
+ * paint operation, but for now just give a public interface */
 static ImagePaintPartialRedraw imapaintpartial = {0, 0, 0, 0, 0};
 
+ImagePaintPartialRedraw *get_imapaintpartial(void) {
+	return &imapaintpartial;
+}
+
+void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr) {
+	imapaintpartial = *ippr;
+}
+
 /* UNDO */
 
 static void undo_copy_tile(UndoImageTile *tile, ImBuf *tmpibuf, ImBuf *ibuf, int restore)
@@ -433,7 +436,7 @@
 		            tile->y * IMAPAINT_TILE_SIZE, 0, 0, IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE);
 }
 
-static void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int x_tile, int y_tile)
+void *image_undo_push_tile(Image *ima, ImBuf *ibuf, ImBuf **tmpibuf, int x_tile, int y_tile)
 {
 	ListBase *lb = undo_paint_push_get_list(UNDO_PAINT_IMAGE);
 	UndoImageTile *tile;
@@ -4349,7 +4352,7 @@
 	// we may want to use this later 
 	// BKE_brush_painter_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
 	
-	if (BKE_brush_painter_paint(painter, project_paint_op, pos, time, pressure, ps, 0)) {
+	if (brush_painter_2d_paint(painter, project_paint_op, pos, time, pressure, ps, 0)) {
 		return 1;
 	}
 	else return 0;
@@ -4373,12 +4376,12 @@
 
 /* Imagepaint Partial Redraw & Dirty Region */
 
-static void imapaint_clear_partial_redraw(void)
+void imapaint_clear_partial_redraw(void)
 {
 	memset(&imapaintpartial, 0, sizeof(imapaintpartial));
 }
 
-static void imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int h)
+void imapaint_dirty_region(Image *ima, ImBuf *ibuf, int x, int y, int w, int h)
 {
 	ImBuf *tmpibuf = NULL;
 	int srcx = 0, srcy = 0, origx;
@@ -4417,7 +4420,7 @@
 		IMB_freeImBuf(tmpibuf);
 }
 
-static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint)
+void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, short texpaint)
 {
 	if (imapaintpartial.x1 != imapaintpartial.x2 &&
 	    imapaintpartial.y1 != imapaintpartial.y2)
@@ -4717,7 +4720,7 @@
 static int imapaint_canvas_set(ImagePaintState *s, Image *ima)
 {
 	ImBuf *ibuf = BKE_image_acquire_ibuf(ima, s->sima ? &s->sima->iuser : NULL, NULL);
-	
+
 	/* verify that we can paint and set canvas */
 	if (ima == NULL) {
 		return 0;
@@ -4740,7 +4743,7 @@
 	if (s->tool == PAINT_TOOL_CLONE) {
 		ima = s->brush->clone.image;
 		ibuf = BKE_image_acquire_ibuf(ima, s->sima ? &s->sima->iuser : NULL, NULL);
-		
+
 		if (!ima || !ibuf || !(ibuf->rect || ibuf->rect_float)) {
 			BKE_image_release_ibuf(ima, ibuf, NULL);
 			BKE_image_release_ibuf(s->image, s->canvas, NULL);
@@ -4780,12 +4783,12 @@
 	pos[0] = uv[0] * ibuf->x;
 	pos[1] = uv[1] * ibuf->y;
 
-	BKE_brush_painter_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
+	brush_painter_2d_require_imbuf(painter, ((ibuf->rect_float) ? 1 : 0), 0, 0);
 
 	/* OCIO_TODO: float buffers are now always linear, so always use color correction
 	 *            this should probably be changed when texture painting color space is supported
 	 */
-	if (BKE_brush_painter_paint(painter, imapaint_paint_op, pos, time, pressure, s, is_data == FALSE)) {
+	if (brush_painter_2d_paint(painter, imapaint_paint_op, pos, time, pressure, s, is_data == FALSE)) {
 		if (update)
 			imapaint_image_update(s->sima, image, ibuf, texpaint);
 		BKE_image_release_ibuf(image, ibuf, NULL);
@@ -4844,7 +4847,7 @@
 			redraw |= imapaint_paint_sub_stroke(s, painter, s->image, texpaint,
 			                                    fwuv, time, 1, pressure);
 			imapaint_clear_partial_redraw();
-			BKE_brush_painter_break_stroke(painter);
+			brush_painter_2d_break_stroke(painter);
 		}
 
 		/* set new canvas */
@@ -5044,7 +5047,7 @@
 		ps->do_mask_normal = FALSE;  /* no need to do blending */
 }
 
-static void paint_brush_init_tex(Brush *brush)
+void paint_brush_init_tex(Brush *brush)
 {
 	/* init mtex nodes */ 
 	if (brush) {
@@ -5167,7 +5170,7 @@
 	                      image_undo_restore, image_undo_free);
 
 	/* create painter */
-	pop->painter = BKE_brush_painter_new(scene, pop->s.brush);
+	pop->painter = brush_painter_2d_new(scene, pop->s.brush);
 
 	{
 		UnifiedPaintSettings *ups = &settings->unified_paint_settings;
@@ -5214,7 +5217,7 @@
 	pop->first = 0;
 }
 
-static void paint_brush_exit_tex(Brush *brush)
+void paint_brush_exit_tex(Brush *brush)
 {
 	if (brush) {
 		MTex *mtex = &brush->mtex;
@@ -5234,7 +5237,7 @@
 
 	settings->imapaint.flag &= ~IMAGEPAINT_DRAWING;
 	imapaint_canvas_free(&pop->s);
-	BKE_brush_painter_free(pop->painter);
+	brush_painter_2d_free(pop->painter);
 
 	if (pop->mode == PAINT_MODE_3D_PROJECT) {
 		BKE_brush_size_set(scene, pop->ps.brush, pop->orig_brush_size);

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-07 11:53:11 UTC (rev 55089)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image_2d.c	2013-03-07 12:11:38 UTC (rev 55090)
@@ -35,18 +35,85 @@
 
 #include "DNA_brush_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
+#include "DNA_object_types.h"
 
+#include "BKE_context.h"
 #include "BKE_brush.h"
+#include "BKE_main.h"
+#include "BKE_image.h"
+#include "BKE_paint.h"
+#include "BKE_report.h"
 
+#include "ED_screen.h"
+
 #include "BLI_math.h"
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list