[Bf-blender-cvs] [3184460ff7f] master: 3D View: re-use select id buffer for circle select on cursor-motion
Campbell Barton
noreply at git.blender.org
Mon May 20 08:34:46 CEST 2019
Commit: 3184460ff7f4f660a70ec7a18a3a882eb2de57f8
Author: Campbell Barton
Date: Mon May 20 16:29:04 2019 +1000
Branches: master
https://developer.blender.org/rB3184460ff7f4f660a70ec7a18a3a882eb2de57f8
3D View: re-use select id buffer for circle select on cursor-motion
The new selection code was redrawing everything for each update.
Use the gestures wmGenericUserData to store the cache between
executions and ensure it's freed.
===================================================================
M source/blender/editors/space_view3d/view3d_select.c
===================================================================
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 414ae392399..b3b4910c525 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -232,6 +232,22 @@ static void editselect_buf_cache_free(struct EditSelectBuf_Cache *esel)
MEM_SAFE_FREE(esel->bases);
}
+static void editselect_buf_cache_free_voidp(void *esel_voidp)
+{
+ editselect_buf_cache_free(esel_voidp);
+ MEM_freeN(esel_voidp);
+}
+
+static void editselect_buf_cache_init_with_generic_userdata(wmGenericUserData *wm_userdata,
+ ViewContext *vc)
+{
+ struct EditSelectBuf_Cache *esel = MEM_callocN(sizeof(*esel), __func__);
+ wm_userdata->data = esel;
+ wm_userdata->free_fn = editselect_buf_cache_free_voidp;
+ wm_userdata->use_free = true;
+ editselect_buf_cache_init(esel, vc);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -775,9 +791,9 @@ static void do_lasso_select_mesh__doSelectFace(void *userData,
}
static bool do_lasso_select_mesh(ViewContext *vc,
+ wmGenericUserData *wm_userdata,
const int mcords[][2],
short moves,
- struct EditSelectBuf_Cache *esel,
const eSelectOp sel_op)
{
LassoSelectUserData data;
@@ -805,10 +821,11 @@ static bool do_lasso_select_mesh(ViewContext *vc,
const bool use_zbuf = !XRAY_FLAG_ENABLED(vc->v3d);
+ struct EditSelectBuf_Cache *esel = wm_userdata->data;
if (use_zbuf) {
- /* Lazy initialize. */
- if (esel->sel_id_ctx == NULL) {
- editselect_buf_cache_init(esel, vc);
+ if (wm_userdata->data == NULL) {
+ editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc);
+ esel = wm_userdata->data;
const uint buffer_len = EDBM_select_id_context_elem_len(esel->sel_id_ctx);
esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
}
@@ -1091,11 +1108,11 @@ static void do_lasso_select_meshobject__doSelectVert(void *userData,
}
}
static bool do_lasso_select_paintvert(ViewContext *vc,
+ wmGenericUserData *wm_userdata,
const int mcords[][2],
short moves,
const eSelectOp sel_op)
{
- struct EditSelectBuf_Cache esel = {NULL};
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
Object *ob = vc->obact;
Mesh *me = ob->data;
@@ -1113,15 +1130,20 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
BLI_lasso_boundbox(&rect, mcords, moves);
+ struct EditSelectBuf_Cache *esel = wm_userdata->data;
if (use_zbuf) {
- editselect_buf_cache_init(&esel, vc);
-
- const uint buffer_len = EDBM_select_id_context_elem_len(esel.sel_id_ctx);
- esel.select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ if (wm_userdata->data == NULL) {
+ editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc);
+ esel = wm_userdata->data;
+ const uint buffer_len = EDBM_select_id_context_elem_len(esel->sel_id_ctx);
+ esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ }
}
if (use_zbuf) {
- changed |= edbm_backbuf_check_and_select_verts_obmode(me, &esel, sel_op);
+ if (esel->select_bitmap != NULL) {
+ changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
+ }
}
else {
LassoSelectUserData data;
@@ -1136,8 +1158,6 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
changed |= data.is_changed;
}
- editselect_buf_cache_free(&esel);
-
if (changed) {
if (SEL_OP_CAN_DESELECT(sel_op)) {
BKE_mesh_mselect_validate(me);
@@ -1149,6 +1169,7 @@ static bool do_lasso_select_paintvert(ViewContext *vc,
return changed;
}
static bool do_lasso_select_paintface(ViewContext *vc,
+ wmGenericUserData *wm_userdata,
const int mcords[][2],
short moves,
const eSelectOp sel_op)
@@ -1169,13 +1190,16 @@ static bool do_lasso_select_paintface(ViewContext *vc,
BLI_lasso_boundbox(&rect, mcords, moves);
- {
- struct EditSelectBuf_Cache esel = {NULL};
- editselect_buf_cache_init(&esel, vc);
- const uint buffer_len = EDBM_select_id_context_elem_len(esel.sel_id_ctx);
- esel.select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
- changed |= edbm_backbuf_check_and_select_faces_obmode(me, &esel, sel_op);
- editselect_buf_cache_free(&esel);
+ struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ if (esel == NULL) {
+ editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc);
+ esel = wm_userdata->data;
+ const uint buffer_len = EDBM_select_id_context_elem_len(esel->sel_id_ctx);
+ esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect);
+ }
+
+ if (esel->select_bitmap) {
+ changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
}
if (changed) {
@@ -1224,12 +1248,15 @@ static bool view3d_lasso_select(
Object *ob = CTX_data_active_object(C);
bool changed_multi = false;
+ wmGenericUserData wm_userdata_buf = {0};
+ wmGenericUserData *wm_userdata = &wm_userdata_buf;
+
if (vc->obedit == NULL) { /* Object Mode */
if (BKE_paint_select_face_test(ob)) {
- changed_multi |= do_lasso_select_paintface(vc, mcords, moves, sel_op);
+ changed_multi |= do_lasso_select_paintface(vc, wm_userdata, mcords, moves, sel_op);
}
else if (BKE_paint_select_vert_test(ob)) {
- changed_multi |= do_lasso_select_paintvert(vc, mcords, moves, sel_op);
+ changed_multi |= do_lasso_select_paintvert(vc, wm_userdata, mcords, moves, sel_op);
}
else if (ob &&
(ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) {
@@ -1246,17 +1273,13 @@ static bool view3d_lasso_select(
}
}
else { /* Edit Mode */
-
- /* TODO(campbell): cache selection buffer between executions. */
- struct EditSelectBuf_Cache esel = {NULL};
-
FOREACH_OBJECT_IN_MODE_BEGIN (vc->view_layer, vc->v3d, ob->type, ob->mode, ob_iter) {
ED_view3d_viewcontext_init_object(vc, ob_iter);
bool changed = false;
switch (vc->obedit->type) {
case OB_MESH:
- changed = do_lasso_select_mesh(vc, mcords, moves, &esel, sel_op);
+ changed = do_lasso_select_mesh(vc, wm_userdata, mcords, moves, sel_op);
break;
case OB_CURVE:
case OB_SURF:
@@ -1283,9 +1306,10 @@ static bool view3d_lasso_select(
}
}
FOREACH_OBJECT_IN_MODE_END;
-
- editselect_buf_cache_free(&esel);
}
+
+ WM_generic_user_data_free(wm_userdata);
+
return changed_multi;
}
@@ -2467,7 +2491,10 @@ static void do_paintvert_box_select__doSelectVert(void *userData,
data->is_changed = true;
}
}
-static bool do_paintvert_box_select(ViewContext *vc, const rcti *rect, const eSelectOp sel_op)
+static bool do_paintvert_box_select(ViewContext *vc,
+ wmGenericUserData *wm_userdata,
+ const rcti *rect,
+ const eSelectOp sel_op)
{
const bool use_zbuf = !XRAY_ENABLED(vc->v3d);
@@ -2487,12 +2514,16 @@ static bool do_paintvert_box_select(ViewContext *vc, const rcti *rect, const eSe
/* pass */
}
else if (use_zbuf) {
- struct EditSelectBuf_Cache esel = {NULL};
- editselect_buf_cache_init(&esel, vc);
- const uint buffer_len = EDBM_select_id_context_elem_len(esel.sel_id_ctx);
- esel.select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
- changed |= edbm_backbuf_check_and_select_verts_obmode(me, &esel, sel_op);
- editselect_buf_cache_free(&esel);
+ struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ if (wm_userdata->data == NULL) {
+ editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc);
+ esel = wm_userdata->data;
+ const uint buffer_len = EDBM_select_id_context_elem_len(esel->sel_id_ctx);
+ esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
+ }
+ if (esel->select_bitmap != NULL) {
+ changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op);
+ }
}
else {
BoxSelectUserData data;
@@ -2516,7 +2547,10 @@ static bool do_paintvert_box_select(ViewContext *vc, const rcti *rect, const eSe
return changed;
}
-static bool do_paintface_box_select(ViewContext *vc, const rcti *rect, int sel_op)
+static bool do_paintface_box_select(ViewContext *vc,
+ wmGenericUserData *wm_userdata,
+ const rcti *rect,
+ int sel_op)
{
Object *ob = vc->obact;
Mesh *me;
@@ -2535,12 +2569,16 @@ static bool do_paintface_box_select(ViewContext *vc, const rcti *rect, int sel_o
/* pass */
}
else {
- struct EditSelectBuf_Cache esel = {NULL};
- editselect_buf_cache_init(&esel, vc);
- const uint buffer_len = EDBM_select_id_context_elem_len(esel.sel_id_ctx);
- esel.select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
- changed |= edbm_backbuf_check_and_select_faces_obmode(me, &esel, sel_op);
- editselect_buf_cache_free(&esel);
+ struct EditSelectBuf_Cache *esel = wm_userdata->data;
+ if (wm_userdata->data == NULL) {
+ editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc);
+ esel = wm_userdata->data;
+ const uint buffer_len = EDBM_select_id_context_elem_len(esel->sel_id_ctx);
+ esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect);
+ }
+ if (esel->select_bitmap != NULL) {
+ changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op);
+ }
}
if (chang
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list