[Bf-blender-cvs] [b18f5a6a814] soc-2019-openxr: Pass graphics context data to OpenXR graphics bindings on Linux too

Julian Eisel noreply at git.blender.org
Wed Jun 19 17:31:20 CEST 2019


Commit: b18f5a6a814263d1dd497926059fa4003263cdf0
Author: Julian Eisel
Date:   Wed Jun 19 17:23:41 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rBb18f5a6a814263d1dd497926059fa4003263cdf0

Pass graphics context data to OpenXR graphics bindings on Linux too

Refactors function into a class, and make this class a friend of
GHOST_ContextGLX. That seems like a better way to access low level
graphics data for this specific case, rather than giving anyone access
via a getter.

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

M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_XR.cpp
M	intern/ghost/intern/GHOST_XRSession.cpp
M	intern/ghost/intern/GHOST_XR_intern.h
M	release/scripts/addons

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

diff --git a/intern/ghost/intern/GHOST_ContextGLX.h b/intern/ghost/intern/GHOST_ContextGLX.h
index ba8df7dac1b..69a7246a238 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -38,6 +38,9 @@
 #endif
 
 class GHOST_ContextGLX : public GHOST_Context {
+  /* XR code needs low level graphics data to send to OpenXR. */
+  friend class GHOST_XRGraphicsBinding;
+
  public:
   /**
    * Constructor.
diff --git a/intern/ghost/intern/GHOST_XR.cpp b/intern/ghost/intern/GHOST_XR.cpp
index d5376892ee7..0561df3809d 100644
--- a/intern/ghost/intern/GHOST_XR.cpp
+++ b/intern/ghost/intern/GHOST_XR.cpp
@@ -168,9 +168,9 @@ static void openxr_extensions_to_enable_get(const GHOST_XRContext *context,
                                             const OpenXRData *oxr,
                                             std::vector<const char *> &r_ext_names)
 {
-  assert(context->gpu_binding != GHOST_kXRGraphicsUnknown);
+  assert(context->gpu_binding_type != GHOST_kXRGraphicsUnknown);
 
-  const char *gpu_binding = openxr_ext_name_from_wm_gpu_binding(context->gpu_binding);
+  const char *gpu_binding = openxr_ext_name_from_wm_gpu_binding(context->gpu_binding_type);
   const static std::vector<std::string> try_ext; /* None yet */
 
   assert(gpu_binding);
@@ -238,7 +238,7 @@ GHOST_XRContext *GHOST_XR_context_create(const GHOST_XRContextCreateInfo *create
   puts("Done printing OpenXR layers/extensions.");
 #endif
 
-  xr_context->gpu_binding = openxr_graphics_extension_to_enable_get(oxr, create_info);
+  xr_context->gpu_binding_type = openxr_graphics_extension_to_enable_get(oxr, create_info);
 
   assert(xr_context->oxr.instance == XR_NULL_HANDLE);
   openxr_instance_create(xr_context);
@@ -287,13 +287,13 @@ void GHOST_XR_graphics_context_bind(GHOST_XRContext &xr_context)
 {
   assert(xr_context.gpu_ctx_bind_fn);
   xr_context.gpu_ctx = static_cast<GHOST_Context *>(
-      xr_context.gpu_ctx_bind_fn(xr_context.gpu_binding));
+      xr_context.gpu_ctx_bind_fn(xr_context.gpu_binding_type));
 }
 
 void GHOST_XR_graphics_context_unbind(GHOST_XRContext &xr_context)
 {
   if (xr_context.gpu_ctx_unbind_fn) {
-    xr_context.gpu_ctx_unbind_fn(xr_context.gpu_binding, xr_context.gpu_ctx);
+    xr_context.gpu_ctx_unbind_fn(xr_context.gpu_binding_type, xr_context.gpu_ctx);
   }
   xr_context.gpu_ctx = nullptr;
 }
diff --git a/intern/ghost/intern/GHOST_XRSession.cpp b/intern/ghost/intern/GHOST_XRSession.cpp
index f66214ed1c1..d975bc1874f 100644
--- a/intern/ghost/intern/GHOST_XRSession.cpp
+++ b/intern/ghost/intern/GHOST_XRSession.cpp
@@ -67,51 +67,52 @@ static void GHOST_XR_system_init(OpenXRData *oxr)
   xrGetSystem(oxr->instance, &system_info, &oxr->system_id);
 }
 
-static void *openxr_graphics_binding_create(const GHOST_XRContext *xr_context,
-                                            GHOST_Context *ghost_ctx)
-{
-  static union {
+class GHOST_XRGraphicsBinding {
+ public:
+  union {
 #if defined(WITH_X11)
     XrGraphicsBindingOpenGLXlibKHR glx;
 #elif defined(WIN32)
     XrGraphicsBindingOpenGLWin32KHR wgl;
     XrGraphicsBindingD3D11KHR d3d11;
 #endif
-  } binding;
-
-  memset(&binding, 0, sizeof(binding));
+  } oxr_binding;
 
-  switch (xr_context->gpu_binding) {
-    case GHOST_kXRGraphicsOpenGL: {
+  void initFromGhostContext(GHOST_TGraphicsBinding type, GHOST_Context *ghost_ctx)
+  {
+    switch (type) {
+      case GHOST_kXRGraphicsOpenGL: {
 #if defined(WITH_X11)
-      binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
+        GHOST_ContextGLX *ctx_glx = static_cast<GHOST_ContextGLX *>(ghost_ctx);
+
+        oxr_binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
+        oxr_binding.glx.xDisplay = ctx_glx->m_display;
 #elif defined(WIN32)
-      GHOST_ContextWGL *ctx_wgl = static_cast<GHOST_ContextWGL *>(ghost_ctx);
-      GHOST_ContextWGL::Info info = ctx_wgl->getInfo();
+        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;
+        oxr_binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
+        oxr_binding.wgl.hDC = info.hDC;
+        oxr_binding.wgl.hGLRC = info.hGLRC;
 #endif
 
-      break;
-    }
+        break;
+      }
 #ifdef WIN32
-    case GHOST_kXRGraphicsD3D11: {
-      GHOST_ContextD3D *ctx_d3d = static_cast<GHOST_ContextD3D *>(ghost_ctx);
+      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();
+        oxr_binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
+        oxr_binding.d3d11.device = ctx_d3d->getDevice();
 
-      break;
-    }
+        break;
+      }
 #endif
-    default:
-      assert(false);
+      default:
+        assert(false);
+    }
   }
-
-  return &binding;
-}
+};
 
 void GHOST_XR_session_start(GHOST_XRContext *xr_context)
 {
@@ -138,11 +139,13 @@ void GHOST_XR_session_start(GHOST_XRContext *xr_context)
         "GHOST_XR_session_start()).\n");
     return;
   }
+  xr_context->gpu_binding = new GHOST_XRGraphicsBinding();
+  xr_context->gpu_binding->initFromGhostContext(xr_context->gpu_binding_type, xr_context->gpu_ctx);
 
   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, xr_context->gpu_ctx);
+  create_info.next = &xr_context->gpu_binding->oxr_binding;
 
   xrCreateSession(oxr->instance, &create_info, &oxr->session);
 }
diff --git a/intern/ghost/intern/GHOST_XR_intern.h b/intern/ghost/intern/GHOST_XR_intern.h
index fd5ed1e6e00..12162d59939 100644
--- a/intern/ghost/intern/GHOST_XR_intern.h
+++ b/intern/ghost/intern/GHOST_XR_intern.h
@@ -40,7 +40,8 @@ typedef struct GHOST_XRContext {
   OpenXRData oxr;
 
   /** Active graphics binding type. */
-  GHOST_TGraphicsBinding gpu_binding;
+  GHOST_TGraphicsBinding gpu_binding_type;
+  class GHOST_XRGraphicsBinding *gpu_binding;
   /** Function to retrieve (possibly create) a graphics context */
   GHOST_XRGraphicsContextBindFn gpu_ctx_bind_fn;
   /** Function to release (possibly free) a graphics context */
diff --git a/release/scripts/addons b/release/scripts/addons
index a5a236df5f6..6cad544cb30 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit a5a236df5f6630ea17958e3006070ef609c6a4b8
+Subproject commit 6cad544cb30364ac14954a9c050d83c6fcbe50dd



More information about the Bf-blender-cvs mailing list