[Bf-blender-cvs] [436bfc71dd5] temp-select-pick: Reorder OpenGL functions

Campbell Barton noreply at git.blender.org
Wed Mar 8 15:39:45 CET 2017


Commit: 436bfc71dd561f1fa8be8d21546f51fecb972035
Author: Campbell Barton
Date:   Thu Mar 9 01:41:53 2017 +1100
Branches: temp-select-pick
https://developer.blender.org/rB436bfc71dd561f1fa8be8d21546f51fecb972035

Reorder OpenGL functions

Also clear depth with exact value

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

M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/gpu/intern/gpu_select_pick.c

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

diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index 6237c9588ca..2fe09cb1d0a 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -1230,6 +1230,9 @@ static int mixed_bones_object_selectbuffer(
 		}
 	}
 
+	use_cycle = true ;
+	do_nearest = false ;
+
 	if (r_do_nearest) {
 		*r_do_nearest = do_nearest;
 	}
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 0b333c2643b..7aad484f1bb 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -47,7 +47,7 @@
 
 #include "gpu_select_private.h"
 
-/* #define DEBUG_PRINT */
+#define DEBUG_PRINT
 
 /* Alloc number for depths */
 #define ALLOC_DEPTHS 200
@@ -55,6 +55,10 @@
 /* Z-depth of cleared depth buffer */
 #define DEPTH_MAX 1.0
 
+/* ----------------------------------------------------------------------------
+ * SubRectStride
+ */
+
 /* For looping over a sub-region of a rect, could be moved into 'rct.c'*/
 typedef struct SubRectStride {
 	unsigned int start;     /* start here */
@@ -87,6 +91,13 @@ static void rect_subregion_stride_calc(const rcti *src, const rcti *dst, SubRect
 	r_sub->skip = src_x - dst_x;
 }
 
+/* ----------------------------------------------------------------------------
+ * DepthBufCache
+ *
+ * Result of reading glReadPixels,
+ * use for both cache and non-cached storage.
+ */
+
 /* store result of glReadPixels */
 typedef struct DepthBufCache {
 	struct DepthBufCache *next, *prev;
@@ -112,8 +123,8 @@ static bool depth_buf_subrect_equal(
 	const float *prev = rect_src->buf + sub_rect->start;
 	const float *curr = rect_dst->buf + sub_rect->start;
 	for (unsigned int i = 0; i < sub_rect->span_len; i++) {
-		const float *prev_end = prev + sub_rect->span;
-		for (; prev < prev_end; prev++, curr++) {
+		const float *curr_end = curr + sub_rect->span;
+		for (; curr < curr_end; prev++, curr++) {
 			if (*prev != *curr) {
 				return false;
 			}
@@ -124,6 +135,12 @@ static bool depth_buf_subrect_equal(
 	return true;
 }
 
+/* ----------------------------------------------------------------------------
+ * DepthID
+ *
+ * Internal structure for storing hits.
+ */
+
 typedef struct DepthID {
 	unsigned int id;
 	float depth;
@@ -240,13 +257,28 @@ void gpu_select_pick_begin(
 
 	/* Restrict OpenGL operations for when we don't have cache */
 	if (ps->is_cached == false) {
+
+		glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT);
+		/* disable writing to the framebuffer */
+		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+
+		/* Without this orthographic mode doesn't give enough precision between objects */
+		glEnable(GL_DEPTH_TEST);
+		glDepthMask(GL_TRUE);
+
+		if (mode == GPU_SELECT_PICK_SORT_ALL) {
+			glDepthFunc(GL_ALWAYS);
+		}
+		else {
+			glDepthFunc(GL_LEQUAL);
+		}
+
 		float viewport[4];
+		glGetFloatv(GL_SCISSOR_BOX, viewport);
 
 		ps->src.clip_rect = *input;
 		ps->src.rect_len = rect_len;
 
-		glGetFloatv(GL_SCISSOR_BOX, viewport);
-
 		ps->gl.clip_readpixels[0] = viewport[0];
 		ps->gl.clip_readpixels[1] = viewport[1];
 		ps->gl.clip_readpixels[2] = BLI_rcti_size_x(&ps->src.clip_rect);
@@ -254,13 +286,10 @@ void gpu_select_pick_begin(
 
 		glViewport(UNPACK4(ps->gl.clip_readpixels));
 
-		glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT);
-		/* disable writing to the framebuffer */
-		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
 		/* It's possible we don't want to clear depth buffer,
 		 * so existing elements are masked by current z-buffer. */
-		glClear(GL_DEPTH_BUFFER_BIT);
+		/* glClear(GL_DEPTH_BUFFER_BIT); */
+		glClearDepth((float)DEPTH_MAX);
 
 		/* scratch buffer (read new values here) */
 		ps->gl.rect_depth_test = depth_buf_malloc(rect_len);
@@ -275,17 +304,6 @@ void gpu_select_pick_begin(
 
 		ps->gl.is_init = false;
 		ps->gl.prev_id = 0;
-
-		if (mode == GPU_SELECT_PICK_SORT_ALL) {
-			glEnable(GL_DEPTH_TEST);
-			glDepthMask(GL_TRUE);
-			glDepthFunc(GL_ALWAYS);
-		}
-		else {
-			glEnable(GL_DEPTH_TEST);
-			glDepthMask(GL_TRUE);
-			glDepthFunc(GL_LEQUAL);
-		}
 	}
 	else {
 		/* Using cache (ps->is_cached == true) */
@@ -311,10 +329,10 @@ void gpu_select_pick_begin(
  * Given 2x depths, we know are different - update the depth information
  * use for both cached/uncached depth buffers.
  */
-static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const DepthBufCache *rect_depth_test)
+static void gpu_select_load_id_pass(const DepthBufCache *rect_prev, const DepthBufCache *rect_curr)
 {
 	GPUPickState *ps = &g_pick_state;
-	const unsigned int prev_id = rect_depth_test->id;
+	const unsigned int id = rect_curr->id;
 	if (g_pick_state.mode == GPU_SELECT_PICK_SORT_ALL) {
 		/* find the best depth for this pass and store in 'all.hits' */
 		float depth_best = DEPTH_MAX;
@@ -327,8 +345,8 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const Depth
 		} ((void)0)
 
 		if (ps->is_cached == false) {
-			const float *prev = rect_depth->buf;
-			const float *curr = rect_depth_test->buf;
+			const float *prev = rect_prev->buf;
+			const float *curr = rect_curr->buf;
 			BLI_assert(ps->src.rect_len == ps->dst.rect_len);
 			const unsigned int rect_len = ps->src.rect_len;
 			for (unsigned int i = 0; i < rect_len; i++, curr++, prev++) {
@@ -337,11 +355,11 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const Depth
 		}
 		else {
 			/* same as above but different rect sizes */
-			const float *prev = rect_depth->buf + ps->cache.sub_rect.start;
-			const float *curr = rect_depth_test->buf + ps->cache.sub_rect.start;
+			const float *prev = rect_prev->buf + ps->cache.sub_rect.start;
+			const float *curr = rect_curr->buf + ps->cache.sub_rect.start;
 			for (unsigned int i = 0; i < ps->cache.sub_rect.span_len; i++) {
-				const float *prev_end = prev + ps->cache.sub_rect.span;
-				for (; prev < prev_end; prev++, curr++) {
+				const float *curr_end = curr + ps->cache.sub_rect.span;
+				for (; curr < curr_end; prev++, curr++) {
 					EVAL_TEST();
 				}
 				prev += ps->cache.sub_rect.skip;
@@ -357,22 +375,22 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const Depth
 			ps->all.hits = MEM_reallocN(ps->all.hits, ps->all.hits_len_alloc * sizeof(*ps->all.hits));
 		}
 		DepthID *d = &ps->all.hits[ps->all.hits_len++];
-		d->id = prev_id;
+		d->id = id;
 		d->depth = depth_best;
 	}
 	else {
 		/* keep track each pixels ID in 'nearest.rect_id' */
-		if (prev_id != SELECT_ID_NONE) {
+		if (id != SELECT_ID_NONE) {
 			unsigned int *id_ptr = ps->nearest.rect_id;
 
 #define EVAL_TEST() \
 			if (*curr != *prev) { \
-				*id_ptr = prev_id; \
+				*id_ptr = id; \
 			} ((void)0)
 
 			if (ps->is_cached == false) {
-				const float *prev = rect_depth->buf;
-				const float *curr = rect_depth_test->buf;
+				const float *prev = rect_prev->buf;
+				const float *curr = rect_curr->buf;
 				BLI_assert(ps->src.rect_len == ps->dst.rect_len);
 				const unsigned int rect_len = ps->src.rect_len;
 				for (unsigned int i = 0; i < rect_len; i++, curr++, prev++, id_ptr++) {
@@ -381,11 +399,11 @@ static void gpu_select_load_id_pass(const DepthBufCache *rect_depth, const Depth
 			}
 			else {
 				/* same as above but different rect sizes */
-				const float *prev = rect_depth->buf + ps->cache.sub_rect.start;
-				const float *curr = rect_depth_test->buf + ps->cache.sub_rect.start;
+				const float *prev = rect_prev->buf + ps->cache.sub_rect.start;
+				const float *curr = rect_curr->buf + ps->cache.sub_rect.start;
 				for (unsigned int i = 0; i < ps->cache.sub_rect.span_len; i++) {
-					const float *prev_end = prev + ps->cache.sub_rect.span;
-					for (; prev < prev_end; prev++, curr++, id_ptr++) {
+					const float *curr_end = curr + ps->cache.sub_rect.span;
+					for (; curr < curr_end; prev++, curr++, id_ptr++) {
 						EVAL_TEST();
 					}
 					prev += ps->cache.sub_rect.skip;
@@ -443,6 +461,7 @@ unsigned int gpu_select_pick_end(void)
 
 		glPopAttrib();
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+		glDepthRange(0.0, 1.0);
 	}
 
 	/* assign but never free directly since it may be in cache */




More information about the Bf-blender-cvs mailing list