Commit: 75f8284545412375f3cfb8f276ac6e511bc07cb7
Author: Clément Foucault
Date:   Fri Feb 23 16:42:51 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rB75f8284545412375f3cfb8f276ac6e511bc07cb7

GPU: Clear Batches VAOs upon window context switchs.

This way all windows can display the preset batches correctly.

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

M       source/blender/gpu/GPU_batch.h
M       source/blender/gpu/intern/gpu_batch_presets.c
M       source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
index 5807af7b359..fda24018150 100644
--- a/source/blender/gpu/GPU_batch.h
+++ b/source/blender/gpu/GPU_batch.h
@@ -32,6 +32,7 @@
 #define __GPU_BATCH_H__
 
 #include "../../../intern/gawain/gawain/gwn_batch.h"
+#include "../../../intern/gawain/gawain/gwn_batch_private.h"
 
 struct rctf;
 
@@ -65,6 +66,7 @@ Gwn_Batch *GPU_batch_preset_sphere(int lod) 
ATTR_WARN_UNUSED_RESULT;
 Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT;
 
 void gpu_batch_presets_init(void);
+void gpu_batch_presets_reset(void);
 void gpu_batch_presets_exit(void);
 
 #endif  /* __GPU_BATCH_H__ */
diff --git a/source/blender/gpu/intern/gpu_batch_presets.c 
b/source/blender/gpu/intern/gpu_batch_presets.c
index 21d6906083a..950f1a2dab3 100644
--- a/source/blender/gpu/intern/gpu_batch_presets.c
+++ b/source/blender/gpu/intern/gpu_batch_presets.c
@@ -193,6 +193,17 @@ void gpu_batch_presets_init(void)
        g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16);
 }
 
+void gpu_batch_presets_reset(void)
+{
+       /* Reset vao caches for these every time we switch opengl context.
+        * This way they will draw correctly for each window. */
+       gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_low);
+       gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_med);
+       gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_high);
+       gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_wire_low);
+       gwn_batch_vao_cache_clear(g_presets_3d.batch.sphere_wire_med);
+}
+
 void gpu_batch_presets_exit(void)
 {
        GWN_batch_discard(g_presets_3d.batch.sphere_low);
diff --git a/source/blender/windowmanager/intern/wm_window.c 
b/source/blender/windowmanager/intern/wm_window.c
index a7baf92e9a0..1ae2ff14efd 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -79,6 +79,7 @@
 
 #include "PIL_time.h"
 
+#include "GPU_batch.h"
 #include "GPU_draw.h"
 #include "GPU_extensions.h"
 #include "GPU_init_exit.h"
@@ -381,6 +382,7 @@ void wm_window_close(bContext *C, wmWindowManager *wm, 
wmWindow *win)
                }
 
                if (tmpwin) {
+                       gpu_batch_presets_reset();
                        immDeactivate();
                }
 
@@ -1028,6 +1030,7 @@ void wm_window_make_drawable(wmWindowManager *wm, 
wmWindow *win)
                        printf("%s: set drawable %d\n", __func__, win->winid);
                }
 
+               gpu_batch_presets_reset();
                immDeactivate();
                GHOST_ActivateWindowDrawingContext(win->ghostwin);
                GWN_context_active_set(win->gwnctx);
@@ -1049,6 +1052,7 @@ void wm_window_reset_drawable(void)
        wmWindow *win = wm->windrawable;
 
        if (BLI_thread_is_main() && win && win->ghostwin) {
+               gpu_batch_presets_reset();
                immDeactivate();
                GHOST_ActivateWindowDrawingContext(win->ghostwin);
                GWN_context_active_set(win->gwnctx);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to