[Bf-blender-cvs] [2e01eedd74] temp-select-pick: Cache depth buffer for reuse
Campbell Barton
noreply at git.blender.org
Tue Mar 7 16:20:30 CET 2017
Commit: 2e01eedd7487432d525cf20d01bee015fec01d98
Author: Campbell Barton
Date: Tue Mar 7 13:56:41 2017 +1100
Branches: temp-select-pick
https://developer.blender.org/rB2e01eedd7487432d525cf20d01bee015fec01d98
Cache depth buffer for reuse
===================================================================
M source/blender/editors/armature/armature_select.c
M source/blender/editors/armature/editarmature_sketch.c
M source/blender/editors/include/ED_view3d.h
M source/blender/editors/metaball/mball_edit.c
M source/blender/editors/space_view3d/view3d_intern.h
M source/blender/editors/space_view3d/view3d_select.c
M source/blender/editors/space_view3d/view3d_view.c
M source/blender/gpu/GPU_select.h
M source/blender/gpu/intern/gpu_select.c
M source/blender/gpu/intern/gpu_select_pick.c
M source/blender/gpu/intern/gpu_select_private.h
M source/blender/gpu/intern/gpu_select_sample_query.c
===================================================================
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index 7366270550..29883cf709 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, VIEW3D_SELECT_DEPTH_SORT_NEAREST);
+ hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_SORT_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;
@@ -304,9 +304,6 @@ static EditBone *get_nearest_editbonepoint(
ebone_next_act = NULL;
}
- BLI_rcti_init_pt_size(&rect, mval, 5);
-
- bool use_cycle = true;
bool do_nearest = false;
/* define if we use solid nearest select or not */
@@ -325,16 +322,19 @@ static EditBone *get_nearest_editbonepoint(
}
}
- const int select_mode = (do_nearest ? VIEW3D_SELECT_DEPTH_SORT_NEAREST : VIEW3D_SELECT_DEPTH_SORT_ALL);
+ const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_SORT_NEAREST : VIEW3D_SELECT_PICK_SORT_ALL);
+ /* TODO: select larger region first (so we can use GPU_select_cache) */
+ BLI_rcti_init_pt_size(&rect, mval, 5);
hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
+
if (hits == 0) {
BLI_rcti_init_pt_size(&rect, mval, 12);
hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
}
+
/* See if there are any selected bones in this group */
if (hits > 0) {
-
if (hits == 1) {
if (!(buffer[3] & BONESEL_NOSEL))
besthitresult = buffer[3];
@@ -456,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 e878e25e1b..412a78e435 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_size(&rect, mval, 5);
- hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_DEPTH_SORT_NEAREST);
+ hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_SORT_NEAREST);
if (hits > 0) {
int besthitresult = -1;
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 0148c757ed..662e584e07 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -305,11 +305,11 @@ bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], con
enum {
VIEW3D_SELECT_ALL = 0,
- VIEW3D_SELECT_DEPTH_SORT_ALL = 1,
- VIEW3D_SELECT_DEPTH_SORT_NEAREST = 2,
+ VIEW3D_SELECT_PICK_SORT_ALL = 1,
+ VIEW3D_SELECT_PICK_SORT_NEAREST = 2,
};
-short view3d_opengl_select(
+int view3d_opengl_select(
struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, const struct rcti *input,
int select_mode);
diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c
index 29e9f046a2..867f289b21 100644
--- a/source/blender/editors/metaball/mball_edit.c
+++ b/source/blender/editors/metaball/mball_edit.c
@@ -594,7 +594,7 @@ bool ED_mball_select_pick(bContext *C, const int mval[2], bool extend, bool dese
BLI_rcti_init_pt_size(&rect, mval, 12);
- hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_DEPTH_SORT_NEAREST);
+ hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_SORT_NEAREST);
/* does startelem exist? */
ml = mb->editelems->first;
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index b11f42bcfe..87b3d95cd4 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -241,7 +241,7 @@ void ED_view3d_smooth_view_force_finish(
struct bContext *C,
struct View3D *v3d, struct ARegion *ar);
-void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rctf *rect);
+void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rcti *rect);
void view3d_viewmatrix_set(Scene *scene, const View3D *v3d, RegionView3D *rv3d);
void fly_modal_keymap(struct wmKeyConfig *keyconf);
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index a636345bd1..6b2e057f59 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1181,19 +1181,19 @@ static bool selectbuffer_has_bones(const unsigned int *buffer, const unsigned in
}
/* utility function for mixed_bones_object_selectbuffer */
-static short selectbuffer_ret_hits_15(unsigned int *UNUSED(buffer), const short hits15)
+static int selectbuffer_ret_hits_15(unsigned int *UNUSED(buffer), const int hits15)
{
return hits15;
}
-static short selectbuffer_ret_hits_9(unsigned int *buffer, const short hits15, const short hits9)
+static int selectbuffer_ret_hits_9(unsigned int *buffer, const int hits15, const int hits9)
{
const int offs = 4 * hits15;
memcpy(buffer, buffer + offs, 4 * hits9 * sizeof(unsigned int));
return hits9;
}
-static short selectbuffer_ret_hits_5(unsigned int *buffer, const short hits15, const short hits9, const short hits5)
+static int selectbuffer_ret_hits_5(unsigned int *buffer, const int hits15, const int hits9, const int hits5)
{
const int offs = 4 * hits15 + 4 * hits9;
memcpy(buffer, buffer + offs, 4 * hits5 * sizeof(unsigned int));
@@ -1202,14 +1202,14 @@ static short selectbuffer_ret_hits_5(unsigned int *buffer, const short hits15, c
/* we want a select buffer with bones, if there are... */
/* so check three selection levels and compare */
-static short mixed_bones_object_selectbuffer(
+static int mixed_bones_object_selectbuffer(
ViewContext *vc, unsigned int *buffer, const int mval[2],
bool use_cycle, bool enumerate,
bool *r_do_nearest)
{
rcti rect;
int offs;
- short hits15, hits9 = 0, hits5 = 0;
+ int hits15, hits9 = 0, hits5 = 0;
bool has_bones15 = false, has_bones9 = false, has_bones5 = false;
static int last_mval[2] = {-100, -100};
bool do_nearest = false;
@@ -1237,47 +1237,56 @@ static short mixed_bones_object_selectbuffer(
do_nearest = do_nearest && !enumerate;
- const int select_mode = (do_nearest ? VIEW3D_SELECT_DEPTH_SORT_NEAREST : VIEW3D_SELECT_DEPTH_SORT_ALL);
+ const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_SORT_NEAREST : VIEW3D_SELECT_PICK_SORT_ALL);
+ int hits = 0;
- BLI_rcti_init(&rect, mval[0] - 14, mval[0] + 14, mval[1] - 14, mval[1] + 14);
+ /* we _must_ end cache before return, use 'goto finally' */
+ GPU_select_cache_begin();
+
+ BLI_rcti_init_pt_size(&rect, mval, 14);
hits15 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
- if (hits15 == 1 || GPU_select_query_check_active()) {
- // ^^^ for testing only
- return selectbuffer_ret_hits_15(buffer, hits15);
+ if (hits15 == 1) {
+ hits = selectbuffer_ret_hits_15(buffer, hits15);
+ goto finally;
}
else if (hits15 > 0) {
has_bones15 = selectbuffer_has_bones(buffer, hits15);
offs = 4 * hits15;
- BLI_rcti_init(&rect, mval[0] - 9, mval[0] + 9, mval[1] - 9, mval[1] + 9);
+ BLI_rcti_init_pt_size(&rect, mval, 9);
hits9 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode);
if (hits9 == 1) {
- return selectbuffer_ret_hits_9(buffer, hits15, hits9);
+ hits = selectbuffer_ret_hits_9(buffer, hits15, hits9);
+ goto finally;
}
else if (hits9 > 0) {
has_bones9 = selectbuffer_has_bones(buffer + offs, hits9);
offs += 4 * hits9;
- BLI_rcti_init(&rect, mval[0] - 5, mval[0] + 5, mval[1] - 5, mval[1] + 5);
+ BLI_rcti_init_pt_size(&rect, mval, 5);
hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode);
if (hits5 == 1) {
- return selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5);
+ hits = selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5);
+ goto finally;
}
else if (hits5 > 0) {
has_bones5 = selectbuffer_has_bones(buffer + offs, hits5);
}
}
- if (has_bones5) return selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5);
- else if (has_bones9) return selectbuffer_ret_hits_9(buffer, hits15, hits9);
- else if (has_bones15) return selectbuffer_ret_hits_15(buffer, hits15);
-
- if (hits5 > 0) return selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5);
- else if (hits9 > 0) return selectbuffer_ret_hits_9(buffer, hits15, hits9);
- else return selectbuffer_ret_hits_15(buffer, hits15);
+ if (has_bones5) { hits = selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5); goto finally; }
+ else if (has_bones9) { hits = selectbuffer_ret_hits_9(buffer, hits15, hits9); goto finally; }
+ else if (has_bones15) { hits = selectbuffer_ret_hits_15(buffer, hits15); goto finally; }
+
+ if (hits5 > 0) { hits = selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5); goto finally; }
+ else if (hits9 > 0) { hits = selectbuffer_ret_hits_9(buffer, hits15, hits9); goto finally;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list