Commit: b6fb1d07a2f43413cbe3158f536618c2a931ed5f
Author: Clément Foucault
Date:   Fri Feb 9 20:34:14 2018 +0100
Branches: temp-drawcontext
https://developer.blender.org/rBb6fb1d07a2f43413cbe3158f536618c2a931ed5f

WM: Add offscreen context functions.

Windows are drawn in order on one thread, the main thread. If the drawmanager 
is called the context is changed. wm_window_reset_drawable() function to reset 
the current window context to resume drawing.

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

M       source/blender/windowmanager/WM_api.h
M       source/blender/windowmanager/intern/wm_window.c
M       source/blender/windowmanager/wm_window.h

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

diff --git a/source/blender/windowmanager/WM_api.h 
b/source/blender/windowmanager/WM_api.h
index 7a66cc04014..835e28457f2 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -116,6 +116,10 @@ struct bScreen *WM_window_get_active_screen(const struct 
wmWindow *win) ATTR_NON
 void            WM_window_set_active_screen(struct wmWindow *win, struct 
WorkSpace *workspace, struct bScreen *screen) ATTR_NONNULL(1);
 bool WM_window_is_temp_screen(const struct wmWindow *win) 
ATTR_WARN_UNUSED_RESULT;
 
+void *WM_context_create(void);
+void WM_context_dispose(void *context);
+void WM_context_activate(void *context);
+
 /* defines for 'type' WM_window_open_temp */
 enum {
        WM_WINDOW_RENDER = 1,
diff --git a/source/blender/windowmanager/intern/wm_window.c 
b/source/blender/windowmanager/intern/wm_window.c
index 0e07b66996d..6c26b87b04c 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -95,6 +95,8 @@
 
 /* the global to talk to ghost */
 static GHOST_SystemHandle g_system = NULL;
+/* Active window */
+static GHOST_WindowHandle g_active_window = NULL;
 
 typedef enum WinOverrideFlag {
        WIN_OVERRIDE_GEOM     = (1 << 0),
@@ -492,6 +494,8 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, 
const char *title, wm
 #endif
                                      GHOST_kDrawingContextTypeOpenGL,
                                      glSettings);
+
+       g_active_window = ghostwin;
        
        if (ghostwin) {
                GHOST_RectangleHandle bounds;
@@ -1022,6 +1026,7 @@ void wm_window_make_drawable(wmWindowManager *wm, 
wmWindow *win)
 
                immDeactivate();
                GHOST_ActivateWindowDrawingContext(win->ghostwin);
+               g_active_window = win->ghostwin;
                immActivate();
 
                /* this can change per window */
@@ -1029,6 +1034,19 @@ void wm_window_make_drawable(wmWindowManager *wm, 
wmWindow *win)
        }
 }
 
+/* Reset active the current window opengl drawing context. */
+void wm_window_reset_drawable(void)
+{
+       if (BLI_thread_is_main()) {
+               immDeactivate();
+               GHOST_ActivateWindowDrawingContext(g_active_window);
+               immActivate();
+       }
+       else {
+               /* TODO unbind the context (set context to NULL) */
+       }
+}
+
 /* called by ghost, here we handle events for windows themselves or send to 
event system */
 /* mouse coordinate converversion happens here */
 static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr 
C_void_ptr)
@@ -2022,3 +2040,20 @@ void wm_window_IME_end(wmWindow *win)
        win->ime_data = NULL;
 }
 #endif  /* WITH_INPUT_IME */
+
+/* ****** direct opengl context management ****** */
+
+void *WM_context_create(void)
+{
+       return GHOST_CreateOffscreenContext(g_system);
+}
+
+void WM_context_dispose(void *context)
+{
+       GHOST_DisposeOffscreenContext(g_system, (GHOST_ContextHandle)context);
+}
+
+void WM_context_activate(void *context)
+{
+       GHOST_ActivateOffscreenContext((GHOST_ContextHandle)context);
+}
diff --git a/source/blender/windowmanager/wm_window.h 
b/source/blender/windowmanager/wm_window.h
index 0264955a4c5..652cefb1a54 100644
--- a/source/blender/windowmanager/wm_window.h
+++ b/source/blender/windowmanager/wm_window.h
@@ -58,6 +58,7 @@ void          wm_window_process_events        (const bContext 
*C);
 void           wm_window_process_events_nosleep(void);
 
 void           wm_window_make_drawable(wmWindowManager *wm, wmWindow *win);
+void           wm_window_reset_drawable(void);
 
 void           wm_window_raise                 (wmWindow *win);
 void           wm_window_lower                 (wmWindow *win);

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

Reply via email to