[Bf-blender-cvs] [9d29373b06e] soc-2019-openxr: Init OpenXR graphics bindings with valid graphics context (Win only)

Julian Eisel noreply at git.blender.org
Wed Jun 19 13:23:51 CEST 2019


Commit: 9d29373b06e8312bdcbc93232a1d18e6d90d65a1
Author: Julian Eisel
Date:   Wed Jun 19 12:18:35 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB9d29373b06e8312bdcbc93232a1d18e6d90d65a1

Init OpenXR graphics bindings with valid graphics context (Win only)

Will do this for Linux in a separate commit.

Also fixes a stupid mistake from previous commit on lazy-creation of XR
context.

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

M	intern/ghost/intern/GHOST_ContextD3D.cpp
M	intern/ghost/intern/GHOST_ContextD3D.h
M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h
M	intern/ghost/intern/GHOST_XRSession.cpp
M	release/scripts/addons
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/intern/ghost/intern/GHOST_ContextD3D.cpp b/intern/ghost/intern/GHOST_ContextD3D.cpp
index 2f3e28a28b2..2c4a5860ed9 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.cpp
+++ b/intern/ghost/intern/GHOST_ContextD3D.cpp
@@ -383,3 +383,8 @@ static void drawTestTriangle(ID3D11Device *m_device,
   m_device_ctx->Draw(std::size(vertices), 0);
 }
 #endif
+
+ID3D11Device *GHOST_ContextD3D::getDevice()
+{
+  return m_device.Get();
+}
diff --git a/intern/ghost/intern/GHOST_ContextD3D.h b/intern/ghost/intern/GHOST_ContextD3D.h
index 9f067fa23ce..2a28d03c9b5 100644
--- a/intern/ghost/intern/GHOST_ContextD3D.h
+++ b/intern/ghost/intern/GHOST_ContextD3D.h
@@ -113,6 +113,8 @@ class GHOST_ContextD3D : public GHOST_Context {
     return true;
   }
 
+  ID3D11Device *getDevice();
+
  private:
   friend class SharedOpenGLContext;
 
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index a3d5d6f7edf..62e17359d71 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -730,3 +730,8 @@ GHOST_TSuccess GHOST_ContextWGL::releaseNativeHandles()
 
   return success;
 }
+
+GHOST_ContextWGL::Info GHOST_ContextWGL::getInfo()
+{
+  return Info{m_hDC, m_hGLRC};
+}
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h b/intern/ghost/intern/GHOST_ContextWGL.h
index af7619e3806..ed230591912 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -101,6 +101,15 @@ class GHOST_ContextWGL : public GHOST_Context {
 
   GHOST_TSuccess setDefaultFramebufferSize(GHOST_TUns32 width, GHOST_TUns32 height);
 
+  /**
+   * Helper to get low level system specific info out of the context.
+   */
+  struct Info {
+    HDC hDC;
+    HGLRC hGLRC;
+  };
+  Info getInfo();
+
  private:
   int choose_pixel_format(bool stereoVisual, bool needAlpha);
   int choose_pixel_format_arb(bool stereoVisual, bool needAlpha);
diff --git a/intern/ghost/intern/GHOST_XRSession.cpp b/intern/ghost/intern/GHOST_XRSession.cpp
index bf36732aa89..f66214ed1c1 100644
--- a/intern/ghost/intern/GHOST_XRSession.cpp
+++ b/intern/ghost/intern/GHOST_XRSession.cpp
@@ -23,6 +23,12 @@
 #include <cstring>
 
 #include "GHOST_C-api.h"
+#if defined(WITH_X11)
+#  include "GHOST_ContextGLX.h"
+#elif defined(WIN32)
+#  include "GHOST_ContextWGL.h"
+#  include "GHOST_ContextD3D.h"
+#endif
 
 #include "GHOST_XR_intern.h"
 
@@ -62,7 +68,7 @@ static void GHOST_XR_system_init(OpenXRData *oxr)
 }
 
 static void *openxr_graphics_binding_create(const GHOST_XRContext *xr_context,
-                                            GHOST_ContextHandle /*ghost_context*/)
+                                            GHOST_Context *ghost_ctx)
 {
   static union {
 #if defined(WITH_X11)
@@ -80,14 +86,22 @@ static void *openxr_graphics_binding_create(const GHOST_XRContext *xr_context,
 #if defined(WITH_X11)
       binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
 #elif defined(WIN32)
+      GHOST_ContextWGL *ctx_wgl = static_cast<GHOST_ContextWGL *>(ghost_ctx);
+      GHOST_ContextWGL::Info info = ctx_wgl->getInfo();
+
       binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
+      binding.wgl.hDC = info.hDC;
+      binding.wgl.hGLRC = info.hGLRC;
 #endif
 
       break;
     }
 #ifdef WIN32
     case GHOST_kXRGraphicsD3D11: {
+      GHOST_ContextD3D *ctx_d3d = static_cast<GHOST_ContextD3D *>(ghost_ctx);
+
       binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
+      binding.d3d11.device = ctx_d3d->getDevice();
 
       break;
     }
@@ -128,8 +142,7 @@ void GHOST_XR_session_start(GHOST_XRContext *xr_context)
   XrSessionCreateInfo create_info{};
   create_info.type = XR_TYPE_SESSION_CREATE_INFO;
   create_info.systemId = oxr->system_id;
-  create_info.next = openxr_graphics_binding_create(xr_context,
-                                                    (GHOST_ContextHandle)xr_context->gpu_ctx);
+  create_info.next = openxr_graphics_binding_create(xr_context, xr_context->gpu_ctx);
 
   xrCreateSession(oxr->instance, &create_info, &oxr->session);
 }
diff --git a/release/scripts/addons b/release/scripts/addons
index 6cad544cb30..a5a236df5f6 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 6cad544cb30364ac14954a9c050d83c6fcbe50dd
+Subproject commit a5a236df5f6630ea17958e3006070ef609c6a4b8
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 73f371a392d..7debf2ce5c6 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3665,24 +3665,23 @@ static bool wm_xr_ensure_context(wmWindowManager *wm)
 static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
 {
   wmWindowManager *wm = CTX_wm_manager(C);
-  struct GHOST_XRContext *xr_context = wm->xr_context;
 
   /* Lazy-create xr context - tries to dynlink to the runtime, reading active_runtime.json. */
   if (wm_xr_ensure_context(wm) == false) {
     return OPERATOR_CANCELLED;
   }
-
-  if (GHOST_XR_session_is_running(xr_context)) {
-    GHOST_XR_session_end(xr_context);
+  if (GHOST_XR_session_is_running(wm->xr_context)) {
+    GHOST_XR_session_end(wm->xr_context);
   }
   else {
 #  if defined(WIN32)
     xr_session_window_create(C);
 #  endif
 
-    GHOST_XR_graphics_context_bind_funcs(
-        xr_context, xr_session_gpu_binding_context_create, xr_session_gpu_binding_context_destroy);
-    GHOST_XR_session_start(xr_context);
+    GHOST_XR_graphics_context_bind_funcs(wm->xr_context,
+                                         xr_session_gpu_binding_context_create,
+                                         xr_session_gpu_binding_context_destroy);
+    GHOST_XR_session_start(wm->xr_context);
   }
   return OPERATOR_FINISHED;
 }



More information about the Bf-blender-cvs mailing list