diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-03-08 21:17:55 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-03-08 22:22:02 +0300 |
commit | 45b764e95b9e34cb17dece1cd37eb80dafa1924f (patch) | |
tree | eb5507c581ae586a20b4585693b694859827fa00 /source/blender/editors/armature | |
parent | 817e975dee27640947bf7d083db39d1d70120385 (diff) |
3D View: new nethod of opengl selection
Intended to replace legacy GL_SELECT, without the limitations of
sample queries which can't access depth information.
This commit adds VIEW3D_SELECT_PICK_NEAREST and VIEW3D_SELECT_PICK_ALL
which access the depth buffers to detect whats under the pointer,
so initial selection is always the closest item.
The performance of this method depends a lot on the OpenGL
implementations glReadPixels.
Since reading depth can be slow, buffers are cached for object picking
so selecting re-uses depth data, performing 1 draw instead of 3
(for 24, 18, 10 px regions, picking with many items under the pointer).
Occlusion queries draw twice when picking nearest,
so worst case 6x draw calls per selection.
Even with these improvements occlusion queries is faster on AMD hardware.
Depth selection is disabled by default, toggle option under select method.
May enable by default if this works well on different hardware.
Reviewed as D2543
Diffstat (limited to 'source/blender/editors/armature')
-rw-r--r-- | source/blender/editors/armature/armature_select.c | 32 | ||||
-rw-r--r-- | source/blender/editors/armature/editarmature_sketch.c | 2 |
2 files changed, 28 insertions, 6 deletions
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index ec0f193e780..3a0d07c02ee 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -177,7 +177,7 @@ void *get_nearest_bone(bContext *C, const int xy[2], bool findunsel) rect.xmin = rect.xmax = xy[0]; rect.ymin = rect.ymax = xy[1]; - hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, true); + hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); if (hits > 0) return get_bone_from_selectbuffer(vc.scene, vc.scene->basact, buffer, hits, findunsel, true); @@ -279,7 +279,7 @@ void ARMATURE_OT_select_linked(wmOperatorType *ot) /* note that BONE ROOT only gets drawn for root bones (or without IK) */ static EditBone *get_nearest_editbonepoint( ViewContext *vc, const int mval[2], - ListBase *edbo, bool findunsel, int *r_selmask) + ListBase *edbo, bool findunsel, bool use_cycle, int *r_selmask) { bArmature *arm = (bArmature *)vc->obedit->data; EditBone *ebone_next_act = arm->act_edbone; @@ -290,6 +290,7 @@ static EditBone *get_nearest_editbonepoint( unsigned int hitresult, besthitresult = BONESEL_NOSEL; int i, mindep = 5; short hits; + static int last_mval[2] = {-100, -100}; /* find the bone after the current active bone, so as to bump up its chances in selection. * this way overlapping bones will cycle selection state as with objects. */ @@ -303,12 +304,33 @@ static EditBone *get_nearest_editbonepoint( ebone_next_act = NULL; } + bool do_nearest = false; + + /* define if we use solid nearest select or not */ + if (use_cycle) { + if (vc->v3d->drawtype > OB_WIRE) { + do_nearest = true; + if (len_manhattan_v2v2_int(mval, last_mval) < 3) { + do_nearest = false; + } + } + copy_v2_v2_int(last_mval, mval); + } + else { + if (vc->v3d->drawtype > OB_WIRE) { + do_nearest = true; + } + } + + const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL); + + /* TODO: select larger region first (so we can use GPU_select_cache) */ BLI_rcti_init_pt_radius(&rect, mval, 5); + hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); - hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, true); if (hits == 0) { BLI_rcti_init_pt_radius(&rect, mval, 12); - hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, true); + hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode); } /* See if there are any selected bones in this group */ if (hits > 0) { @@ -434,7 +456,7 @@ bool ED_armature_select_pick(bContext *C, const int mval[2], bool extend, bool d return true; } - nearBone = get_nearest_editbonepoint(&vc, mval, arm->edbo, true, &selmask); + nearBone = get_nearest_editbonepoint(&vc, mval, arm->edbo, true, true, &selmask); if (nearBone) { if (!extend && !deselect && !toggle) { diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c index 8690072ca85..bba486bc65c 100644 --- a/source/blender/editors/armature/editarmature_sketch.c +++ b/source/blender/editors/armature/editarmature_sketch.c @@ -1909,7 +1909,7 @@ static bool sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], c BLI_rcti_init_pt_radius(&rect, mval, 5); - hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, true); + hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST); if (hits > 0) { int besthitresult = -1; |