Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jbakker>2021-12-07 12:14:27 +0300
committerJeroen Bakker <jeroen@blender.org>2021-12-07 12:33:23 +0300
commite2f0b4a0cbe5934dbd591caa53f9259eee431cee (patch)
tree7afb67d5b4add1b8f1f4512353afb2d249f15904 /source/blender/editors
parent1de363662427ff66693106b4bbde46337d651842 (diff)
Cleanup: Use rcti marking dirty regions when texture painting.
Dirty regions when painting are not using rcti. Meaning less understandable code. Found issue when refactoring the image_gpu partial update. In a future change gpu partial update API will be using rcti also what makes the code even cleaner. Reviewed By: campbellbarton Differential Revision: https://developer.blender.org/D13260
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c42
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c32
-rw-r--r--source/blender/editors/sculpt_paint/paint_intern.h7
3 files changed, 32 insertions, 49 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index 6ba5c43f698..ab868df770d 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -87,7 +87,7 @@
* 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};
+static ImagePaintPartialRedraw imapaintpartial = {{0}};
ImagePaintPartialRedraw *get_imapaintpartial(void)
{
@@ -103,7 +103,7 @@ void set_imapaintpartial(struct ImagePaintPartialRedraw *ippr)
void ED_imapaint_clear_partial_redraw(void)
{
- memset(&imapaintpartial, 0, sizeof(imapaintpartial));
+ BLI_rcti_init_minmax(&imapaintpartial.dirty_region);
}
void imapaint_region_tiles(
@@ -132,19 +132,9 @@ void ED_imapaint_dirty_region(
return;
}
- if (!imapaintpartial.enabled) {
- imapaintpartial.x1 = x;
- imapaintpartial.y1 = y;
- imapaintpartial.x2 = x + w;
- imapaintpartial.y2 = y + h;
- imapaintpartial.enabled = 1;
- }
- else {
- imapaintpartial.x1 = min_ii(imapaintpartial.x1, x);
- imapaintpartial.y1 = min_ii(imapaintpartial.y1, y);
- imapaintpartial.x2 = max_ii(imapaintpartial.x2, x + w);
- imapaintpartial.y2 = max_ii(imapaintpartial.y2, y + h);
- }
+ rcti rect_to_merge;
+ BLI_rcti_init(&rect_to_merge, x, x + w, y, y + h);
+ BLI_rcti_do_minmax_rcti(&imapaintpartial.dirty_region, &rect_to_merge);
imapaint_region_tiles(ibuf, x, y, w, h, &tilex, &tiley, &tilew, &tileh);
@@ -167,23 +157,27 @@ void ED_imapaint_dirty_region(
void imapaint_image_update(
SpaceImage *sima, Image *image, ImBuf *ibuf, ImageUser *iuser, short texpaint)
{
- if (imapaintpartial.x1 != imapaintpartial.x2 && imapaintpartial.y1 != imapaintpartial.y2) {
- IMB_partial_display_buffer_update_delayed(
- ibuf, imapaintpartial.x1, imapaintpartial.y1, imapaintpartial.x2, imapaintpartial.y2);
+ if (BLI_rcti_is_empty(&imapaintpartial.dirty_region)) {
+ return;
}
if (ibuf->mipmap[0]) {
ibuf->userflags |= IB_MIPMAP_INVALID;
}
+ IMB_partial_display_buffer_update_delayed(ibuf,
+ imapaintpartial.dirty_region.xmin,
+ imapaintpartial.dirty_region.ymin,
+ imapaintpartial.dirty_region.xmax,
+ imapaintpartial.dirty_region.ymax);
+
/* TODO: should set_tpage create ->rect? */
if (texpaint || (sima && sima->lock)) {
- int w = imapaintpartial.x2 - imapaintpartial.x1;
- int h = imapaintpartial.y2 - imapaintpartial.y1;
- if (w && h) {
- /* Testing with partial update in uv editor too */
- BKE_image_update_gputexture(image, iuser, imapaintpartial.x1, imapaintpartial.y1, w, h);
- }
+ const int w = BLI_rcti_size_x(&imapaintpartial.dirty_region);
+ const int h = BLI_rcti_size_y(&imapaintpartial.dirty_region);
+ /* Testing with partial update in uv editor too */
+ BKE_image_update_gputexture(
+ image, iuser, imapaintpartial.dirty_region.xmin, imapaintpartial.dirty_region.ymin, w, h);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 33166988f7d..3e5d8e812d2 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -4649,13 +4649,7 @@ static void project_paint_end(ProjPaintState *ps)
/* 1 = an undo, -1 is a redo. */
static void partial_redraw_single_init(ImagePaintPartialRedraw *pr)
{
- pr->x1 = INT_MAX;
- pr->y1 = INT_MAX;
-
- pr->x2 = -1;
- pr->y2 = -1;
-
- pr->enabled = 1;
+ BLI_rcti_init_minmax(&pr->dirty_region);
}
static void partial_redraw_array_init(ImagePaintPartialRedraw *pr)
@@ -4671,16 +4665,11 @@ static bool partial_redraw_array_merge(ImagePaintPartialRedraw *pr,
ImagePaintPartialRedraw *pr_other,
int tot)
{
- bool touch = 0;
+ bool touch = false;
while (tot--) {
- pr->x1 = min_ii(pr->x1, pr_other->x1);
- pr->y1 = min_ii(pr->y1, pr_other->y1);
-
- pr->x2 = max_ii(pr->x2, pr_other->x2);
- pr->y2 = max_ii(pr->y2, pr_other->y2);
-
- if (pr->x2 != -1) {
- touch = 1;
+ BLI_rcti_do_minmax_rcti(&pr->dirty_region, &pr_other->dirty_region);
+ if (!BLI_rcti_is_empty(&pr->dirty_region)) {
+ touch = true;
}
pr++;
@@ -4703,7 +4692,7 @@ static bool project_image_refresh_tagged(ProjPaintState *ps)
/* look over each bound cell */
for (i = 0; i < PROJ_BOUNDBOX_SQUARED; i++) {
pr = &(projIma->partRedrawRect[i]);
- if (pr->x2 != -1) { /* TODO: use 'enabled' ? */
+ if (BLI_rcti_is_valid(&pr->dirty_region)) {
set_imapaintpartial(pr);
imapaint_image_update(NULL, projIma->ima, projIma->ibuf, &projIma->iuser, true);
redraw = 1;
@@ -5117,11 +5106,10 @@ static void do_projectpaint_mask_f(ProjPaintState *ps, ProjPixel *projPixel, flo
static void image_paint_partial_redraw_expand(ImagePaintPartialRedraw *cell,
const ProjPixel *projPixel)
{
- cell->x1 = min_ii(cell->x1, (int)projPixel->x_px);
- cell->y1 = min_ii(cell->y1, (int)projPixel->y_px);
-
- cell->x2 = max_ii(cell->x2, (int)projPixel->x_px + 1);
- cell->y2 = max_ii(cell->y2, (int)projPixel->y_px + 1);
+ rcti rect_to_add;
+ BLI_rcti_init(
+ &rect_to_add, projPixel->x_px, projPixel->x_px + 1, projPixel->y_px, projPixel->y_px + 1);
+ BLI_rcti_do_minmax_rcti(&cell->dirty_region, &rect_to_add);
}
static void copy_original_alpha_channel(ProjPixel *pixel, bool is_floatbuf)
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 30314742958..d1bcf87e871 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -24,6 +24,9 @@
#pragma once
#include "BKE_paint.h"
+
+#include "BLI_rect.h"
+
#include "DNA_scene_types.h"
#ifdef __cplusplus
@@ -45,7 +48,6 @@ struct Scene;
struct VPaint;
struct ViewContext;
struct bContext;
-struct rcti;
struct wmEvent;
struct wmKeyConfig;
struct wmOperator;
@@ -180,8 +182,7 @@ void ED_vpaint_proj_handle_free(struct VertProjHandle *vp_handle);
/* paint_image.c */
typedef struct ImagePaintPartialRedraw {
- int x1, y1, x2, y2; /* XXX, could use 'rcti' */
- int enabled;
+ rcti dirty_region;
} ImagePaintPartialRedraw;
bool image_texture_paint_poll(struct bContext *C);