GPU_select: utility function to finalize selection
authorCampbell Barton <ideasman42@gmail.com>
Tue, 27 Feb 2018 09:16:53 +0000 (20:16 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 27 Feb 2018 09:16:53 +0000 (20:16 +1100)
Needed for depth picking in 2.8

source/blender/gpu/GPU_select.h
source/blender/gpu/intern/gpu_select.c
source/blender/gpu/intern/gpu_select_pick.c
source/blender/gpu/intern/gpu_select_private.h

index cf5b8bf7d8f07e44f437cb4e7cbc81ea5d4b4e5c..53f480bccd79f0957888f1c95bfc8fe4f0376103 100644 (file)
@@ -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);
 
index 632b0cfee1b687de4fbb84abb98253432cfaa23b..e2837d96b0f62f9e2cf1e9bf8459327e8e023f6b 100644 (file)
@@ -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.
index 0a77420fa25773624b39990878be269c1661167e..d7a3ad075584865614ad082b818dd2d245ed7daf 100644 (file)
@@ -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);
index 8935bd7b25326b5799f09185f5a90e1e31a7246b..8368aaa9edcc5a71b9337400ee94cd21e465a9d6 100644 (file)
@@ -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);