[Bf-blender-cvs] [8b75f609e49] temp-udim-images: Support 2D painting across tiles in

Lukas Stockner noreply at git.blender.org
Fri Jun 15 14:09:14 CEST 2018


Commit: 8b75f609e49368184d85cebb9331e17045b9d35a
Author: Lukas Stockner
Date:   Thu Jun 14 11:21:57 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB8b75f609e49368184d85cebb9331e17045b9d35a

Support 2D painting across tiles in

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

M	source/blender/editors/include/ED_paint.h
M	source/blender/editors/interface/interface_ops.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_intern.h

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

diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index 246419d64aa..b35236cadd0 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -41,7 +41,7 @@ void ED_keymap_paint(struct wmKeyConfig *keyconf);
 /* paint_image.c */
 void ED_imapaint_clear_partial_redraw(void);
 void ED_imapaint_dirty_region(struct Image *ima, struct ImBuf *ibuf, int x, int y, int w, int h, bool find_old);
-void ED_imapaint_bucket_fill(struct bContext *C, float color[3], struct wmOperator *op);
+void ED_imapaint_bucket_fill(struct bContext *C, float color[3], struct wmOperator *op, const int mouse[2]);
 
 /* paint_image_undo.c */
 void ED_image_undo_push_begin(const char *name);
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 6fcede58737..e040db756fd 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -1259,7 +1259,7 @@ void UI_drop_color_copy(wmDrag *drag, wmDropBox *drop)
 	RNA_boolean_set(drop->ptr, "gamma", drag_info->gamma_corrected);
 }
 
-static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
 	ARegion *ar = CTX_wm_region(C);
 	uiBut *but = NULL;
@@ -1300,7 +1300,7 @@ static int drop_color_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
 			srgb_to_linearrgb_v3_v3(color, color);
 		}
 
-		ED_imapaint_bucket_fill(C, color, op);
+		ED_imapaint_bucket_fill(C, color, op, event->mval);
 	}
 
 	ED_region_tag_redraw(ar);
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 599d74379aa..d6d8fcd591e 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -472,7 +472,7 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
 	}
 	else {
 		pop->mode = PAINT_MODE_2D;
-		pop->custom_paint = paint_2d_new_stroke(C, op, mouse, mode);
+		pop->custom_paint = paint_2d_new_stroke(C, op, mode);
 	}
 
 	if (!pop->custom_paint) {
@@ -582,7 +582,7 @@ static void paint_stroke_done(const bContext *C, struct PaintStroke *stroke)
 				float color[3];
 
 				srgb_to_linearrgb_v3_v3(color, BKE_brush_color_get(scene, brush));
-				paint_2d_bucket_fill(C, color, brush, pop->prevmouse, pop->custom_paint);
+				paint_2d_bucket_fill(C, color, brush, pop->startmouse, pop->prevmouse, pop->custom_paint);
 			}
 			else {
 				paint_proj_stroke(C, pop->custom_paint, pop->startmouse, pop->prevmouse, paint_stroke_flipped(stroke),
@@ -1213,7 +1213,7 @@ void PAINT_OT_brush_colors_flip(wmOperatorType *ot)
 }
 
 
-void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op)
+void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op, const int mouse[2])
 {
 	wmWindowManager *wm = CTX_wm_manager(C);
 	SpaceImage *sima = CTX_wm_space_image(C);
@@ -1223,7 +1223,8 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op)
 
 	ED_image_undo_push_begin(op->type->name);
 
-	paint_2d_bucket_fill(C, color, NULL, NULL, NULL);
+	float mouse_init[2] = {mouse[0], mouse[1]};
+	paint_2d_bucket_fill(C, color, NULL, mouse_init, NULL, NULL);
 
 	BKE_undosys_step_push(wm->undo_stack, C, op->type->name);
 
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 4f59d7b9994..3688259eef6 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -94,22 +94,21 @@ typedef struct BrushPainterCache {
 	unsigned short *tex_mask_old;
 	unsigned int tex_mask_old_w;
 	unsigned int tex_mask_old_h;
+
+	int image_size[2];
 } BrushPainterCache;
 
 typedef struct BrushPainter {
 	Scene *scene;
 	Brush *brush;
 
-	float lastpaintpos[2];  /* position of last paint op */
-	float startpaintpos[2]; /* position of first paint */
-
 	short firsttouch;       /* first paint op */
 
 	struct ImagePool *pool;	/* image pool */
 	rctf tex_mapping;		/* texture coordinate mapping */
 	rctf mask_mapping;		/* mask texture coordinate mapping */
 
-	BrushPainterCache cache;
+	bool cache_invert;
 } BrushPainter;
 
 typedef struct ImagePaintRegion {
@@ -118,6 +117,28 @@ typedef struct ImagePaintRegion {
 	int width, height;
 } ImagePaintRegion;
 
+typedef enum ImagePaintTileState {
+	PAINT2D_TILE_EMPTY = 0,
+	PAINT2D_TILE_FAILED,
+	PAINT2D_TILE_READY,
+} ImagePaintTileState;
+
+typedef struct ImagePaintTile {
+	ImageUser iuser;
+	int cache_idx;
+	ImBuf *canvas;
+	float radius_fac[2];
+	int size[2];
+	float uv_ofs[2];
+	bool need_redraw;
+	BrushPainterCache cache;
+
+	ImagePaintTileState state;
+
+	float last_paintpos[2];  /* position of last paint op */
+	float start_paintpos[2]; /* position of first paint */
+} ImagePaintTile;
+
 typedef struct ImagePaintState {
 	BrushPainter *painter;
 	SpaceImage *sima;
@@ -129,10 +150,7 @@ typedef struct ImagePaintState {
 	Brush *brush;
 	short tool, blend;
 	Image *image;
-	ImBuf *canvas;
 	ImBuf *clonecanvas;
-	const char *warnpackedfile;
-	const char *warnmultifile;
 
 	bool do_masking;
 
@@ -143,11 +161,7 @@ typedef struct ImagePaintState {
 	int do_facesel;
 	int symmetry;
 
-	bool need_redraw;
-
-	ImageUser iuser;
-	float uv_ofs[2];
-	float radius_fac[2];
+	ImagePaintTile *tiles;
 
 	BlurKernel *blurkernel;
 } ImagePaintState;
@@ -160,42 +174,39 @@ static BrushPainter *brush_painter_2d_new(Scene *scene, Brush *brush, bool inver
 	painter->brush = brush;
 	painter->scene = scene;
 	painter->firsttouch = 1;
-	painter->cache.lastdiameter[0] = -1; /* force ibuf create in refresh */
-	painter->cache.invert = invert;
+	painter->cache_invert = invert;
 
 	return painter;
 }
 
 
-static void brush_painter_2d_require_imbuf(BrushPainter *painter, bool use_float, bool use_color_correction)
+static void brush_painter_2d_require_imbuf(Brush *brush, ImagePaintTile *tile, bool use_float, bool use_color_correction)
 {
-	Brush *brush = painter->brush;
-
-	if ((painter->cache.use_float != use_float)) {
-		if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf);
-		if (painter->cache.curve_mask) MEM_freeN(painter->cache.curve_mask);
-		if (painter->cache.tex_mask) MEM_freeN(painter->cache.tex_mask);
-		if (painter->cache.tex_mask_old) MEM_freeN(painter->cache.tex_mask_old);
-		painter->cache.ibuf = NULL;
-		painter->cache.curve_mask = NULL;
-		painter->cache.tex_mask = NULL;
-		painter->cache.lastdiameter[0] = -1; /* force ibuf create in refresh */
-	}
-
-	painter->cache.use_float = use_float;
-	painter->cache.use_color_correction = use_float && use_color_correction;
-	painter->cache.is_texbrush = (brush->mtex.tex && brush->imagepaint_tool == PAINT_TOOL_DRAW) ? true : false;
-	painter->cache.is_maskbrush = (brush->mask_mtex.tex) ? true : false;
+	BrushPainterCache *cache = &tile->cache;
+	if ((cache->use_float != use_float)) {
+		if (cache->ibuf) IMB_freeImBuf(cache->ibuf);
+		if (cache->curve_mask) MEM_freeN(cache->curve_mask);
+		if (cache->tex_mask) MEM_freeN(cache->tex_mask);
+		if (cache->tex_mask_old) MEM_freeN(cache->tex_mask_old);
+		cache->ibuf = NULL;
+		cache->curve_mask = NULL;
+		cache->tex_mask = NULL;
+		cache->lastdiameter[0] = -1; /* force ibuf create in refresh */
+	}
+
+	cache->use_float = use_float;
+	cache->use_color_correction = use_float && use_color_correction;
+	cache->is_texbrush = (brush->mtex.tex && brush->imagepaint_tool == PAINT_TOOL_DRAW) ? true : false;
+	cache->is_maskbrush = (brush->mask_mtex.tex) ? true : false;
 }
 
-static void brush_painter_2d_free(BrushPainter *painter)
+static void brush_painter_cache_2d_free(BrushPainterCache *cache)
 {
-	if (painter->cache.ibuf) IMB_freeImBuf(painter->cache.ibuf);
-	if (painter->cache.texibuf) IMB_freeImBuf(painter->cache.texibuf);
-	if (painter->cache.curve_mask) MEM_freeN(painter->cache.curve_mask);
-	if (painter->cache.tex_mask) MEM_freeN(painter->cache.tex_mask);
-	if (painter->cache.tex_mask_old) MEM_freeN(painter->cache.tex_mask_old);
-	MEM_freeN(painter);
+	if (cache->ibuf) IMB_freeImBuf(cache->ibuf);
+	if (cache->texibuf) IMB_freeImBuf(cache->texibuf);
+	if (cache->curve_mask) MEM_freeN(cache->curve_mask);
+	if (cache->tex_mask) MEM_freeN(cache->tex_mask);
+	if (cache->tex_mask_old) MEM_freeN(cache->tex_mask_old);
 }
 
 static void brush_imbuf_tex_co(rctf *mapping, int x, int y, float texco[3])
@@ -234,11 +245,12 @@ static unsigned short *brush_painter_mask_ibuf_new(BrushPainter *painter, const
 
 /* update rectangular section of the brush image */
 static void brush_painter_mask_imbuf_update(
-        BrushPainter *painter, unsigned short *tex_mask_old,
+        BrushPainter *painter, ImagePaintTile *tile, unsigned short *tex_mask_old,
         int origx, int origy, int w, int h, int xt, int yt, const int diameter[2])
 {
 	Scene *scene = painter->scene;
 	Brush *brush = painter->brush;
+	BrushPainterCache *cache = &tile->cache;
 	rctf tex_mapping = painter->mask_mapping;
 	struct ImagePool *pool = painter->pool;
 	unsigned short res;
@@ -247,8 +259,8 @@ static void brush_painter_mask_imbuf_update(
 
 	int x, y, thread = 0;
 
-	unsigned short *tex_mask = painter->cache.tex_mask;
-	unsigned short *tex_mask_cur = painter->cache.tex_mask_old;
+	unsigned short *tex_mask = cache->tex_mask;
+	unsigned short *tex_mask_cur = cache->tex_mask_old;
 
 	/* fill pixels */
 	for (y = origy; y < h; y++) {
@@ -267,7 +279,7 @@ static void brush_painter_mask_imbuf_update(
 
 			/* read from old texture buffer */
 			if (use_texture_old) {
-				res = *(tex_mask_old + ((y - origy + yt) * painter->cache.tex_mask_old_w + (x - origx + xt)));
+				res = *(tex_mask_old + ((y - origy + yt) * cache->tex_mask_old_w + (x - origx + xt)));
 			}
 
 			/* write to new texture mask */
@@ -284,9 +296,9 @@ static void brush_painter_mask_imbuf_update(
  * This can be considerably faster for brushes that change size due to pressure or
  * textures that stick to the surface where only part of the pixels are new
  */
-static void brush_painter_mask_imbuf_partial_upda

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list