[Bf-blender-cvs] [4de50d75723] master: GPU_select: utility function to finalize selection

Campbell Barton noreply at git.blender.org
Tue Feb 27 10:13:23 CET 2018


Commit: 4de50d757233009ccd5db8538fd036a62ce58648
Author: Campbell Barton
Date:   Tue Feb 27 20:16:53 2018 +1100
Branches: master
https://developer.blender.org/rB4de50d757233009ccd5db8538fd036a62ce58648

GPU_select: utility function to finalize selection

Needed for depth picking in 2.8

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

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

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

diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h
index cf5b8bf7d8f..53f480bccd7 100644
--- a/source/blender/gpu/GPU_select.h
+++ b/source/blender/gpu/GPU_select.h
@@ -47,6 +47,7 @@ enum {
 
 void GPU_select_begin(unsigned int *buffer, unsigned int bufsize, const struct rcti *input, char mode, int oldhits);
 bool GPU_select_load_id(unsigned int id);
+void GPU_select_finalize(void);
 unsigned int GPU_select_end(void);
 bool GPU_select_query_check_active(void);
 
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 632b0cfee1b..e2837d96b0f 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -149,6 +149,29 @@ bool GPU_select_load_id(unsigned int id)
 	}
 }
 
+/**
+ * Needed when GL context of #GPU_select_end
+ * can't be used to finalize selection operations
+ * (because of context changes).
+ */
+void GPU_select_finalize(void)
+{
+	if (!g_select_state.select_is_active)
+		return;
+
+	switch (g_select_state.algorithm) {
+		case ALGO_GL_LEGACY:
+		case ALGO_GL_QUERY:
+		{
+			break;
+		}
+		default:  /* ALGO_GL_PICK */
+		{
+			gpu_select_pick_finalize();
+		}
+	}
+}
+
 /**
  * Cleanup and flush selection results to buffer.
  * Return number of hits and hits in buffer.
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 0a77420fa25..d7a3ad07558 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -526,6 +526,19 @@ bool gpu_select_pick_load_id(unsigned int id)
 	return true;
 }
 
+ /**
+  * (Optional), call before 'gpu_select_pick_end' if GL context is not kept.
+  * is not compatible with regular select case.
+  * */
+void gpu_select_pick_finalize(void)
+{
+	GPUPickState *ps = &g_pick_state;
+	if (ps->gl.is_init) {
+		/* force finishing last pass */
+		gpu_select_pick_load_id(ps->gl.prev_id);
+	}
+}
+
 unsigned int gpu_select_pick_end(void)
 {
 	GPUPickState *ps = &g_pick_state;
@@ -535,10 +548,7 @@ unsigned int gpu_select_pick_end(void)
 #endif
 
 	if (ps->is_cached == false) {
-		if (ps->gl.is_init) {
-			/* force finishing last pass */
-			gpu_select_pick_load_id(ps->gl.prev_id);
-		}
+		gpu_select_pick_finalize();
 
 		glPopAttrib();
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
diff --git a/source/blender/gpu/intern/gpu_select_private.h b/source/blender/gpu/intern/gpu_select_private.h
index 8935bd7b253..8368aaa9edc 100644
--- a/source/blender/gpu/intern/gpu_select_private.h
+++ b/source/blender/gpu/intern/gpu_select_private.h
@@ -35,6 +35,7 @@
 /* gpu_select_pick */
 void gpu_select_pick_begin(unsigned int (*buffer)[4], unsigned int bufsize, const rcti *input, char mode);
 bool gpu_select_pick_load_id(unsigned int id);
+void gpu_select_pick_finalize(void);
 unsigned int gpu_select_pick_end(void);
 
 void gpu_select_pick_cache_begin(void);



More information about the Bf-blender-cvs mailing list