[Bf-blender-cvs] [9fcf81b6423] temp-select-pick: Various minor changes, add back old multi-pass select

Campbell Barton noreply at git.blender.org
Wed Mar 8 19:20:24 CET 2017


Commit: 9fcf81b642319fd6c5902463515630f402d403fa
Author: Campbell Barton
Date:   Thu Mar 9 05:23:28 2017 +1100
Branches: temp-select-pick
https://developer.blender.org/rB9fcf81b642319fd6c5902463515630f402d403fa

Various minor changes, add back old multi-pass select

===================================================================

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_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

===================================================================

diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index 7d9d65b66d1..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, VIEW3D_SELECT_PICK_SORT_NEAREST);
+	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);
@@ -322,7 +322,7 @@ static EditBone *get_nearest_editbonepoint(
 		}
 	}
 
-	const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_SORT_NEAREST : VIEW3D_SELECT_PICK_SORT_ALL);
+	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);
diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
index 8480d06276a..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, VIEW3D_SELECT_PICK_SORT_NEAREST);
+	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_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 662e584e077..af6f37d937c 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -304,9 +304,12 @@ bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], con
 #define MAXPICKBUF      (4 * MAXPICKELEMS)
 
 enum {
+	/* all elements in the region, ignore depth */
 	VIEW3D_SELECT_ALL = 0,
-	VIEW3D_SELECT_PICK_SORT_ALL = 1,
-	VIEW3D_SELECT_PICK_SORT_NEAREST = 2,
+	/* pick also depth sorts (only for small regions!) */
+	VIEW3D_SELECT_PICK_ALL = 1,
+	/* sorts and only returns visible objects (only for small regions!) */
+	VIEW3D_SELECT_PICK_NEAREST = 2,
 };
 
 int view3d_opengl_select(
diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c
index 183ed830f04..bc42717b69f 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_radius(&rect, mval, 12);
 
-	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_SORT_NEAREST);
+	hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST);
 
 	/* does startelem exist? */
 	ml = mb->editelems->first;
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 6237c9588ca..222d2d8d6c5 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1236,7 +1236,7 @@ static int mixed_bones_object_selectbuffer(
 
 	do_nearest = do_nearest && !enumerate;
 
-	const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_SORT_NEAREST : VIEW3D_SELECT_PICK_SORT_ALL);
+	const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL);
 	int hits = 0;
 
 	/* we _must_ end cache before return, use 'goto finally' */
@@ -2590,7 +2590,7 @@ static void lattice_circle_select(ViewContext *vc, const bool select, const int
 
 
 /* NOTE: pose-bone case is copied from editbone case... */
-static short pchan_circle_doSelectJoint(void *userData, bPoseChannel *pchan, const float screen_co[2])
+static bool pchan_circle_doSelectJoint(void *userData, bPoseChannel *pchan, const float screen_co[2])
 {
 	CircleSelectUserData *data = userData;
 
@@ -2668,7 +2668,7 @@ static void pose_circle_select(ViewContext *vc, const bool select, const int mva
 	}
 }
 
-static short armature_circle_doSelectJoint(void *userData, EditBone *ebone, const float screen_co[2], short head)
+static bool armature_circle_doSelectJoint(void *userData, EditBone *ebone, const float screen_co[2], bool head)
 {
 	CircleSelectUserData *data = userData;
 
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 3635f44d974..aff8c58eed6 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -1180,7 +1180,12 @@ int view3d_opengl_select(
 	rcti rect;
 	int hits;
 	const bool use_obedit_skip = (scene->obedit != NULL) && (vc->obedit == NULL);
-	const bool is_new_select = GPU_select_query_check_active();
+	const bool is_pick_select = true;
+	const bool do_passes = (
+	        (is_pick_select == false) &&
+	        (select_mode == GPU_SELECT_PICK_NEAREST) &&
+	        GPU_select_query_check_active());
+
 	char gpu_select_mode;
 
 	/* case not a border select */
@@ -1192,14 +1197,24 @@ int view3d_opengl_select(
 		rect = *input;
 	}
 
-	if (is_new_select && select_mode == VIEW3D_SELECT_PICK_SORT_NEAREST) {
-		gpu_select_mode = GPU_SELECT_PICK_SORT_NEAREST;
-	}
-	else if (is_new_select && select_mode == VIEW3D_SELECT_PICK_SORT_ALL) {
-		gpu_select_mode = GPU_SELECT_PICK_SORT_ALL;
+	if (is_pick_select) {
+		if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST) {
+			gpu_select_mode = GPU_SELECT_PICK_NEAREST;
+		}
+		else if (is_pick_select && select_mode == VIEW3D_SELECT_PICK_ALL) {
+			gpu_select_mode = GPU_SELECT_PICK_ALL;
+		}
+		else {
+			gpu_select_mode = GPU_SELECT_ALL;
+		}
 	}
 	else {
-		gpu_select_mode = GPU_SELECT_ALL;
+		if (do_passes) {
+			gpu_select_mode = GPU_SELECT_NEAREST_FIRST_PASS;
+		}
+		else {
+			gpu_select_mode = GPU_SELECT_ALL;
+		}
 	}
 
 	/* Re-use cache (rect must be smaller then the cached)
@@ -1229,6 +1244,15 @@ int view3d_opengl_select(
 	view3d_select_loop(vc, scene, v3d, ar, use_obedit_skip);
 
 	hits = GPU_select_end();
+	
+	/* second pass, to get the closest object to camera */
+	if (do_passes) {
+		GPU_select_begin(buffer, bufsize, &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
+
+		view3d_select_loop(vc, scene, v3d, ar, use_obedit_skip);
+
+		GPU_select_end();
+	}
 
 	G.f &= ~G_PICKSEL;
 	view3d_winmatrix_set(ar, v3d, NULL);
diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h
index a890cab2e48..cf5b8bf7d8f 100644
--- a/source/blender/gpu/GPU_select.h
+++ b/source/blender/gpu/GPU_select.h
@@ -41,8 +41,8 @@ enum {
 	GPU_SELECT_NEAREST_FIRST_PASS       = 2,
 	GPU_SELECT_NEAREST_SECOND_PASS      = 3,
 	/* gpu_select_pick */
-	GPU_SELECT_PICK_SORT_ALL           = 4,
-	GPU_SELECT_PICK_SORT_NEAREST       = 5,
+	GPU_SELECT_PICK_ALL           = 4,
+	GPU_SELECT_PICK_NEAREST       = 5,
 };
 
 void GPU_select_begin(unsigned int *buffer, unsigned int bufsize, const struct rcti *input, char mode, int oldhits);
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 928f325393d..8596d21e85a 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -79,16 +79,16 @@ void GPU_select_begin(unsigned int *buffer, unsigned int bufsize, const rcti *in
 	g_select_state.use_gpu_select = GPU_select_query_check_active();
 	g_select_state.mode = mode;
 
-	if (!g_select_state.use_gpu_select) {
-		g_select_state.algorithm = ALGO_GL_LEGACY;
-	}
-	else if (ELEM(g_select_state.mode, GPU_SELECT_PICK_SORT_ALL, GPU_SELECT_PICK_SORT_NEAREST)) {
+	if (ELEM(g_select_state.mode, GPU_SELECT_PICK_ALL, GPU_SELECT_PICK_NEAREST)) {
 		g_select_state.algorithm = ALGO_GL_PICK;
 	}
+	else if (!g_select_state.use_gpu_select) {
+		g_select_state.algorithm = ALGO_GL_LEGACY;
+	}
 	else {
 		g_select_state.algorithm = ALGO_GL_QUERY;
 	}
-
+	printf("%d~\n", g_select_state.algorithm);
 	switch (g_select_state.algorithm) {
 		case ALGO_GL_LEGACY:
 		{
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 23531c1d4fd..19c430a0f1d 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -261,14 +261,14 @@ typedef struct GPUPickState {
 
 	/* Pickign methods */
 	union {
-		/* GPU_SELECT_PICK_SORT_ALL */
+		/* GPU_SELECT_PICK_ALL */
 		struct {
 			DepthID *hits;
 			unsigned int hits_len;
 			unsigned int hits_len_alloc;
 		} all;
 
-		/* GPU_SELECT_PICK_SORT_NEAREST */
+		/* GPU_SELECT_PICK_NEAREST */
 		struct {
 			unsigned int *rect_id;
 		} nearest;
@@ -307,7 +307,7 @@ void gpu_select_pick_begin(
 		/* Without this orthographic mode doesn't give enough precision between objects */
 		glEnable(GL_DEPTH_TEST);
 
-		if (mode == GPU_SELECT_PICK_SORT_ALL) {
+		if (mode == GPU_SELECT_PICK_ALL) {
 			glDepthMask(GL_TRUE);
 			glDepthFunc(GL_NOTEQUAL);
 		}
@@ -364,7 +364,7 @@ void gpu_select_pick_begin(
 		BLI_assert(ps->gl.rect_depth_test == NULL);
 	}
 
-	if (mode == GPU_SELECT_PICK_SORT_ALL) {
+	if (mode == GPU_SELECT_PICK_ALL) {
 		ps->all.hits = MEM_mallocN(sizeof(*ps->all.hits) * ALLOC_DEPTHS, __func__);
 		ps->all.hits_len = 0;
 		ps->all.hits_len_alloc = ALLOC_DEPTHS;
@@ -476,7 +476,7 @@ bool gpu_select_pick_load_id(unsigned int id)
 		/* perform initial check since most cases the array remains unchanged  */
 
 		bool do_pass = false;
-		if (g_pick_state.mode == GPU_SELECT_PICK_SORT_ALL) {
+		if (g_pick_state.mode == GPU_SELECT_PICK_ALL) {
 			if (depth_buf_rect_depth_any(ps->gl.rect_depth_test, rect_len)) {
 				ps->gl.rect_depth_test->id = ps->gl.prev_id;
 				gpu_select_load_id_pass_all(ps->gl.rect_depth_test);
@@ -500,7 +500,7 @@ bool gpu_select_pick_load_id(unsigned int id)
 
 			SWAP(DepthBufCache *, ps->gl.rect_depth, ps->gl.rect_depth_test);
 
-			if (g_pick_state.mode == GPU_SELECT_PICK_S

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list