[Bf-blender-cvs] [fc8127d0702] soc-2019-openxr: (Disabled) code to open a DirectX window with the VR session

Julian Eisel noreply at git.blender.org
Thu Jun 13 23:29:08 CEST 2019


Commit: fc8127d0702ad7eb80bfce9c461e12a20724a9ba
Author: Julian Eisel
Date:   Thu Jun 13 23:20:18 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rBfc8127d0702ad7eb80bfce9c461e12a20724a9ba

(Disabled) code to open a DirectX window with the VR session

The window immediately crashes, hence keeping it disabled for now.

Not sure how much of this I'll leave in, for now this is mainly for
testing DirectX compatibility.

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

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IWindow.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Window.h
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index d68553eca0f..0dff8209966 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -203,6 +203,8 @@ extern GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle
 extern GHOST_ContextHandle GHOST_CreateDirectXContext(GHOST_SystemHandle systemhandle);
 #endif
 
+extern GHOST_ContextHandle GHOST_GetWindowContext(GHOST_WindowHandle windowhandle);
+
 /**
  * Returns the window user data.
  * \param windowhandle The handle to the window
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 52894a7c38d..cf65decf9c6 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -77,6 +77,8 @@ class GHOST_IWindow {
    */
   virtual GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) = 0;
 
+  virtual class GHOST_IContext *getDrawingContext() = 0;
+
   /**
    * Sets the title displayed in the title bar.
    * \param title The title to display in the title bar.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 1e9b8161239..73442ae6e01 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -136,6 +136,13 @@ GHOST_ContextHandle GHOST_CreateDirectXContext(GHOST_SystemHandle systemhandle)
 }
 #endif
 
+GHOST_ContextHandle GHOST_GetWindowContext(GHOST_WindowHandle windowhandle)
+{
+  GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
+
+  return (GHOST_ContextHandle)window->getDrawingContext();
+}
+
 GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
                                       const char *title,
                                       GHOST_TInt32 left,
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index 50a563453f6..a5673335eac 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -227,6 +227,11 @@ class GHOST_Window : public GHOST_IWindow {
    */
   virtual bool getModifiedState();
 
+  inline GHOST_IContext *getDrawingContext()
+  {
+    return (GHOST_IContext *)m_context;
+  }
+
   /**
    * Returns the type of drawing context used in this window.
    * \return The current type of drawing context.
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index def075bd47c..891d7d4027a 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -23,6 +23,7 @@
 
 #define _USE_MATH_DEFINES
 
+#include "GHOST_ContextD3D.h"
 #include "GHOST_WindowWin32.h"
 #include "GHOST_SystemWin32.h"
 #include "GHOST_DropTargetWin32.h"
@@ -724,6 +725,27 @@ GHOST_Context *GHOST_WindowWin32::newDrawingContext(GHOST_TDrawingContextType ty
 #  error  // must specify either core or compat at build time
 #endif
   }
+  else if (type == GHOST_kDrawingContextTypeD3D) {
+    GHOST_Context *context;
+
+    HWND wnd = CreateWindowA("STATIC",
+                             "BlenderD3D",
+                             WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+                             0,
+                             0,
+                             64,
+                             64,
+                             NULL,
+                             NULL,
+                             GetModuleHandle(NULL),
+                             NULL);
+
+    HDC mHDC = GetDC(wnd);
+
+    context = new GHOST_ContextD3D(false, wnd, mHDC);
+
+    return context;
+  }
 
   return NULL;
 }
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 5ed1be81bff..8f54c4579ca 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -109,6 +109,7 @@ int WM_window_pixels_x(const struct wmWindow *win);
 int WM_window_pixels_y(const struct wmWindow *win);
 void WM_window_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
 void WM_window_screen_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
+bool WM_window_is_non_opengl(const wmWindow *win);
 bool WM_window_is_fullscreen(struct wmWindow *win);
 
 void WM_windows_scene_data_sync(const ListBase *win_lb, struct Scene *scene) ATTR_NONNULL();
@@ -165,6 +166,7 @@ enum {
 struct wmWindow *WM_window_open(struct bContext *C, const struct rcti *rect);
 struct wmWindow *WM_window_open_temp(
     struct bContext *C, int x, int y, int sizex, int sizey, int type);
+struct wmWindow *WM_window_open_directx(struct bContext *C, const rcti *rect);
 void WM_window_set_dpi(wmWindow *win);
 
 bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 68d5d2cd4df..074d03de93b 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3534,6 +3534,17 @@ static void *xr_session_gpu_binding_context_create(eWM_xrGraphicsBinding graphic
   switch (graphics_lib) {
     case WM_XR_GRAPHICS_OPENGL:
       return WM_opengl_context_create();
+#  ifdef WIN32
+    case WM_XR_GRAPHICS_D3D11: {
+      wmWindowManager *wm = G_MAIN->wm.first;
+      for (wmWindow *win = wm->windows.first; win; win = win->next) {
+        if (GHOST_GetDrawingContextType(win->ghostwin)) {
+          return GHOST_GetWindowContext(win->ghostwin);
+        }
+      }
+      return NULL;
+    }
+#  endif
     default:
       return NULL;
   }
@@ -3561,6 +3572,12 @@ static int xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
     wm_xr_session_end(xr_context);
   }
   else {
+#  if defined(WIN32) && 0
+    rcti rect;
+    BLI_rcti_init(&rect, 20, 1000, 20, 1200);
+    wmWindow *win = WM_window_open_directx(C, &rect);
+#  endif
+
     wm_xr_graphics_context_bind_funcs(
         xr_context, xr_session_gpu_binding_context_create, xr_session_gpu_binding_context_destroy);
     wm_xr_session_start(xr_context);
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index a63726ae82d..46a1f99c5ca 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -549,7 +549,10 @@ static void wm_window_ensure_eventstate(wmWindow *win)
 }
 
 /* belongs to below */
-static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wmWindow *win)
+static void wm_window_ghostwindow_add(wmWindowManager *wm,
+                                      const char *title,
+                                      wmWindow *win,
+                                      GHOST_TDrawingContextType context_type)
 {
   GHOST_WindowHandle ghostwin;
   GHOST_GLSettings glSettings = {0};
@@ -578,14 +581,22 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
                                 win->sizex,
                                 win->sizey,
                                 (GHOST_TWindowState)win->windowstate,
-                                GHOST_kDrawingContextTypeOpenGL,
+                                context_type,
                                 glSettings);
 
   if (ghostwin) {
     GHOST_RectangleHandle bounds;
 
-    GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(ghostwin);
-    win->gpuctx = GPU_context_create(default_fb);
+    if (context_type == GHOST_kDrawingContextTypeOpenGL) {
+      GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(ghostwin);
+      win->gpuctx = GPU_context_create(default_fb);
+    }
+    else {
+      GHOST_ContextHandle *gl_context = WM_opengl_context_create();
+      WM_opengl_context_activate(gl_context);
+      win->gpuctx = GPU_context_create(0);
+      // wm_window_reset_drawable();
+    }
 
     /* needed so we can detect the graphics card below */
     GPU_init();
@@ -637,23 +648,11 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
   }
 }
 
-/**
- * Initialize #wmWindow without ghostwin, open these and clear.
- *
- * window size is read from window, if 0 it uses prefsize
- * called in #WM_check, also inits stuff after file read.
- *
- * \warning
- * After running, 'win->ghostwin' can be NULL in rare cases
- * (where OpenGL driver fails to create a context for eg).
- * We could remove them with #wm_window_ghostwindows_remove_invalid
- * but better not since caller may continue to use.
- * Instead, caller needs to handle the error case and cleanup.
- */
-void wm_window_ghostwindows_ensure(wmWindowManager *wm)
+static void wm_window_ghostwindow_ensure(wmWindowManager *wm,
+                                         wmWindow *win,
+                                         GHOST_TDrawingContextType context_type)
 {
   wmKeyMap *keymap;
-  wmWindow *win;
 
   BLI_assert(G.background == false);
 
@@ -684,57 +683,77 @@ void wm_window_ghostwindows_ensure(wmWindowManager *wm)
 #endif
   }
 
-  for (win = wm->windows.first; win; win = win->next) {
-    if (win->ghostwin == NULL) {
-      if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) {
-        win->posx = wm_init_state.start_x;
-        win->posy = wm_init_state.start_y;
-        win->sizex = wm_init_state.size_x;
-        win->sizey = wm_init_state.size_y;
-
-        if (wm_init_state.override_flag & WIN_OVERRIDE_GEOM) {
-          win->windowstate = GHOST_kWindowStateNormal;
-          wm_init_state.override_flag &= ~WIN_OVERRIDE_GEOM;
-        }
-        else {
-          win->windowstate = GHOST_WINDOW_STATE_DEFAULT;
-        }
-      }
+  if (win->ghostwin == NULL) {
+    if ((win->sizex == 0) || (wm_init_state.override_flag & WIN_OVERRIDE_GEOM)) {
+      win->posx = wm_init_state.start_x;
+      win->posy = wm_init_state.start_y;
+      win->sizex = wm_init_state.size_x;
+      win->sizey = wm_init_state.size_y;
 
-      if (wm_init_state.override_flag & WIN_OVERRIDE_WINSTATE) {
-        win->windowstate = wm_init_state.windowstate;
-        wm_init_state.override_flag &= ~WIN_OVERRIDE_WINSTATE;
+      if (wm_init_state.override_flag & WIN_OVERRIDE_GEOM) {
+        win->windowstate = GHOST_kWindowStateNormal;
+        wm_init_state.override_flag &= ~WIN_OVERRIDE_GE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list