diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-05-15 18:37:05 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-05-15 18:37:05 +0400 |
commit | e1229b2978c37a043f3932657ac5cfa156093866 (patch) | |
tree | 9b11c52390302485cf1b5be799d693e4fce03f22 /source/blender/editors/sculpt_paint/paint_image_2d.c | |
parent | 71775dc2a49d8ec20d31544f2fccf69729a8cd39 (diff) |
Attempt to fix #35057 and #35372: slow texture painting performance.
After the paint refactoring for 2.67, the OpenGL texture was getting updated for
every stroke point, rather than once for every redraw. With a small brush radius
and low spacing the number of stroke points can be quite large, which might have
a big performance impact depending on the graphics card / drivers.
Also for 2D image paint, avoid redrawing the button panels and properties editor
during painting.
There is another possible cause for slowdowns with 3D texture painting which was
not fixed. Projection painting is creating and destroying threads for every stroke
point. Depending on the CPU/OS there might be a lot of overhead in doing that if
the brush size is small.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image_2d.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image_2d.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 956dcc858f8..640796fa26c 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -153,6 +153,8 @@ typedef struct ImagePaintState { int faceindex; float uv[2]; int do_facesel; + + bool need_redraw; } ImagePaintState; @@ -1016,17 +1018,16 @@ static void paint_2d_canvas_free(ImagePaintState *s) image_undo_remove_masks(); } -int paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser) +void paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int eraser) { float newuv[2], olduv[2]; - int redraw = 0; ImagePaintState *s = ps; BrushPainter *painter = s->painter; ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL); const bool is_data = (ibuf && ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA); if (!ibuf) - return 0; + return; s->blend = s->brush->blend; if (eraser) @@ -1064,19 +1065,10 @@ int paint_2d_stroke(void *ps, const float prev_mval[2], const float mval[2], int brush_painter_2d_refresh_cache(s, painter, newuv); - if (paint_2d_op(s, painter->cache.ibuf, painter->cache.mask, olduv, newuv)) { - imapaint_image_update(s->sima, s->image, ibuf, false); - BKE_image_release_ibuf(s->image, ibuf, NULL); - redraw |= 1; - } - else { - BKE_image_release_ibuf(s->image, ibuf, NULL); - } - - if (redraw) - imapaint_clear_partial_redraw(); + if (paint_2d_op(s, painter->cache.ibuf, painter->cache.mask, olduv, newuv)) + s->need_redraw = true; - return redraw; + BKE_image_release_ibuf(s->image, ibuf, NULL); } void *paint_2d_new_stroke(bContext *C, wmOperator *op) @@ -1116,10 +1108,24 @@ void *paint_2d_new_stroke(bContext *C, wmOperator *op) return s; } -void paint_2d_redraw(const bContext *C, void *ps, int final) +void paint_2d_redraw(const bContext *C, void *ps, bool final) { ImagePaintState *s = ps; + if (s->need_redraw) { + ImBuf *ibuf = BKE_image_acquire_ibuf(s->image, s->sima ? &s->sima->iuser : NULL, NULL); + + imapaint_image_update(s->sima, s->image, ibuf, false); + imapaint_clear_partial_redraw(); + + BKE_image_release_ibuf(s->image, ibuf, NULL); + + s->need_redraw = false; + } + else if (!final) { + return; + } + if (final) { if (s->image && !(s->sima && s->sima->lock)) GPU_free_image(s->image); @@ -1131,7 +1137,7 @@ void paint_2d_redraw(const bContext *C, void *ps, int final) if (!s->sima || !s->sima->lock) ED_region_tag_redraw(CTX_wm_region(C)); else - WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image); + WM_event_add_notifier(C, NC_IMAGE | NA_PAINTING, s->image); } } |