diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-10-11 02:30:16 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-10-11 02:30:16 +0400 |
commit | 03602dc158de1a2fa7d88c91b0323aaaabb2c246 (patch) | |
tree | 0671cbea32cf28e2f646ed21be7784a6960163e6 /source/blender/editors/mesh | |
parent | ecc5eb59c64ac8fd14ac3adc43d05499e88e81d9 (diff) |
use BLI_bitmap for editmesh selection buffer to save some memory.
Diffstat (limited to 'source/blender/editors/mesh')
-rw-r--r-- | source/blender/editors/mesh/editmesh_select.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 4d512fab1c0..094e9f0f72b 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -31,6 +31,7 @@ #include "MEM_guardedalloc.h" +#include "BLI_bitmap.h" #include "BLI_listbase.h" #include "BLI_linklist.h" #include "BLI_linklist_stack.h" @@ -184,7 +185,12 @@ void EDBM_automerge(Scene *scene, Object *obedit, bool update, const char hflag) unsigned int bm_solidoffs = 0, bm_wireoffs = 0, bm_vertoffs = 0; /* set in drawobject.c ... for colorindices */ /* facilities for border select and circle select */ -static char *selbuf = NULL; +static BLI_bitmap *selbuf = NULL; + +static BLI_bitmap *edbm_backbuf_alloc(const int size) +{ + return BLI_BITMAP_NEW(size, "selbuf"); +} /* reads rect, and builds selection array for quick lookup */ /* returns if all is OK */ @@ -205,28 +211,31 @@ bool EDBM_backbuf_border_init(ViewContext *vc, short xmin, short ymin, short xma dr = buf->rect; /* build selection lookup */ - selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); + selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); a = (xmax - xmin + 1) * (ymax - ymin + 1); while (a--) { - if (*dr > 0 && *dr <= bm_vertoffs) - selbuf[*dr] = 1; + if (*dr > 0 && *dr <= bm_vertoffs) { + BLI_BITMAP_SET(selbuf, *dr); + } dr++; } IMB_freeImBuf(buf); return true; } -int EDBM_backbuf_check(unsigned int index) +bool EDBM_backbuf_check(unsigned int index) { /* odd logic, if selbuf is NULL we assume no zbuf-selection is enabled * and just ignore the depth buffer, this is error prone since its possible * code doesn't set the depth buffer by accident, but leave for now. - Campbell */ - if (selbuf == NULL) return 1; + if (selbuf == NULL) + return true; if (index > 0 && index <= bm_vertoffs) - return selbuf[index]; - return 0; + return BLI_BITMAP_GET_BOOL(selbuf, index); + + return false; } void EDBM_backbuf_free(void) @@ -286,11 +295,13 @@ bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short edbm_mask_lasso_px_cb, &lasso_mask_data); /* build selection lookup */ - selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); + selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); a = (xmax - xmin + 1) * (ymax - ymin + 1); while (a--) { - if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) selbuf[*dr] = 1; + if (*dr > 0 && *dr <= bm_vertoffs && *dr_mask == true) { + BLI_BITMAP_SET(selbuf, *dr); + } dr++; dr_mask++; } IMB_freeImBuf(buf); @@ -326,12 +337,14 @@ bool EDBM_backbuf_circle_init(ViewContext *vc, short xs, short ys, short rads) dr = buf->rect; /* build selection lookup */ - selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf"); + selbuf = edbm_backbuf_alloc(bm_vertoffs + 1); radsq = rads * rads; for (yc = -rads; yc <= rads; yc++) { for (xc = -rads; xc <= rads; xc++, dr++) { if (xc * xc + yc * yc < radsq) { - if (*dr > 0 && *dr <= bm_vertoffs) selbuf[*dr] = 1; + if (*dr > 0 && *dr <= bm_vertoffs) { + BLI_BITMAP_SET(selbuf, *dr); + } } } } |