diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2013-10-09 20:00:15 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2013-10-09 20:00:15 +0400 |
commit | fe727ab4a26351894ee277aacbfd1696316bc189 (patch) | |
tree | 86a74e866d6244ee7523173104970e3bd7b12a42 | |
parent | 6e1fe4ddd9209aa1b5bc562d92f82a6bfb743513 (diff) |
Paint cursor overlays: Delete the cursor texture overlay resources when
exiting a paint mode.
5 files changed, 58 insertions, 25 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index c18afd066fa..05fe23eb223 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -79,6 +79,30 @@ typedef struct TexSnapshot { bool old_col; } TexSnapshot; +typedef struct CursorSnapshot { + GLuint overlay_texture; + int size; + int zoom; +} CursorSnapshot; + +static TexSnapshot primary_snap = {0}; +static TexSnapshot secondary_snap = {0}; +static CursorSnapshot cursor_snap = {0}; + +/* delete overlay cursor textures to preserve memory and invalidate all overlay flags */ +void paint_cursor_delete_textures() +{ + glDeleteTextures(1, &primary_snap.overlay_texture); + glDeleteTextures(1, &secondary_snap.overlay_texture); + glDeleteTextures(1, &cursor_snap.overlay_texture); + + memset(&primary_snap, 0, sizeof(TexSnapshot)); + memset(&secondary_snap, 0, sizeof(TexSnapshot)); + memset(&cursor_snap, 0, sizeof(TexSnapshot)); + + BKE_paint_invalidate_overlay_all(); +} + static int same_tex_snap(TexSnapshot *snap, MTex *mtex, ViewContext *vc, bool col, float zoom) { return (/* make brush smaller shouldn't cause a resample */ @@ -103,9 +127,7 @@ static void make_tex_snap(TexSnapshot *snap, ViewContext *vc, float zoom) static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool primary) { - static int init = 0; - static TexSnapshot primary_snap = {0}; - static TexSnapshot secondary_snap = {0}; + bool init; TexSnapshot *target; MTex *mtex = (primary) ? &br->mtex : &br->mask_mtex; @@ -120,12 +142,14 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima (overlay_flags & PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY); target = (primary) ? &primary_snap : &secondary_snap; - + refresh = !target->overlay_texture || (invalid != 0) || !same_tex_snap(target, mtex, vc, col, zoom); + init = (target->overlay_texture != 0); + if (refresh) { struct ImagePool *pool = NULL; /* stencil is rotated later */ @@ -160,7 +184,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima target->overlay_texture = 0; } - init = 0; + init = false; target->old_size = size; } @@ -267,7 +291,6 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima if (refresh) { if (!init || (target->old_col != col)) { glTexImage2D(GL_TEXTURE_2D, 0, format, size, size, 0, format, GL_UNSIGNED_BYTE, buffer); - init = 1; } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, format, GL_UNSIGNED_BYTE, buffer); @@ -297,10 +320,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) { - static GLuint overlay_texture = 0; - static int init = 0; - static int old_size = -1; - static int old_zoom = -1; + bool init; OverlayControlFlags overlay_flags = BKE_paint_get_overlay_flags(); GLubyte *buffer = NULL; @@ -310,14 +330,16 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) int refresh; refresh = - !overlay_texture || + !cursor_snap.overlay_texture || (overlay_flags & PAINT_INVALID_OVERLAY_CURVE) || - old_zoom != zoom; + cursor_snap.zoom != zoom; + + init = (cursor_snap.overlay_texture != 0); if (refresh) { int s, r; - old_zoom = zoom; + cursor_snap.zoom = zoom; s = BKE_brush_size_get(vc->scene, br); r = 1; @@ -330,18 +352,18 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) if (size < 256) size = 256; - if (size < old_size) - size = old_size; + if (size < cursor_snap.size) + size = cursor_snap.size; - if (old_size != size) { - if (overlay_texture) { - glDeleteTextures(1, &overlay_texture); - overlay_texture = 0; + if (cursor_snap.size != size) { + if (cursor_snap.overlay_texture) { + glDeleteTextures(1, &cursor_snap.overlay_texture); + cursor_snap.overlay_texture = 0; } - init = 0; + init = false; - old_size = size; + cursor_snap.size = size; } buffer = MEM_mallocN(sizeof(GLubyte) * size * size, "load_tex"); @@ -383,14 +405,14 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) } } - if (!overlay_texture) - glGenTextures(1, &overlay_texture); + if (!cursor_snap.overlay_texture) + glGenTextures(1, &cursor_snap.overlay_texture); } else { - size = old_size; + size = cursor_snap.size; } - glBindTexture(GL_TEXTURE_2D, overlay_texture); + glBindTexture(GL_TEXTURE_2D, cursor_snap.overlay_texture); if (refresh) { if (!init) { diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 910a49a8f7d..34603d7516c 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -792,6 +792,7 @@ static void toggle_paint_cursor(bContext *C, int enable) if (settings->imapaint.paintcursor && !enable) { WM_paint_cursor_end(wm, settings->imapaint.paintcursor); settings->imapaint.paintcursor = NULL; + paint_cursor_delete_textures(); } else if (enable) paint_cursor_start(C, image_paint_poll); @@ -820,6 +821,9 @@ void ED_space_image_paint_update(wmWindowManager *wm, ToolSettings *settings) paint_cursor_start_explicit(&imapaint->paint, wm, image_paint_poll); } + else { + paint_cursor_delete_textures(); + } } /************************ grab clone operator ************************/ diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index 6c13f6efb74..607edcab9f8 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -86,6 +86,7 @@ void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data); int paint_poll(struct bContext *C); void paint_cursor_start(struct bContext *C, int (*poll)(struct bContext *C)); void paint_cursor_start_explicit(struct Paint *p, struct wmWindowManager *wm, int (*poll)(struct bContext *C)); +void paint_cursor_delete_textures(void); /* paint_vertex.c */ int weight_paint_poll(struct bContext *C); diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 122dbae6129..c3f1e38b663 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -2062,6 +2062,8 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op) /* weight paint spesific */ mesh_octree_table(NULL, NULL, NULL, 'e'); mesh_mirrtopo_table(NULL, 'e'); + + paint_cursor_delete_textures(); } else { ob->mode |= mode_flag; @@ -2684,6 +2686,8 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op) if (me->editflag & ME_EDIT_PAINT_FACE_SEL) { BKE_mesh_flush_select_from_polys(me); } + + paint_cursor_delete_textures(); } else { ob->mode |= mode_flag; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 53357b2616b..2a6b6d4b3d9 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -5039,6 +5039,8 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) ob->mode &= ~mode_flag; free_sculptsession(ob); + + paint_cursor_delete_textures(); } else { /* Enter sculptmode */ |