[Bf-blender-cvs] [0732a9f1b29] master: GHOST/XR: enable X11-EGL context for OpenXR

Christian Rauch noreply at git.blender.org
Tue Jun 22 21:17:53 CEST 2021


Commit: 0732a9f1b292edfea6270c23466a40c69b0f99ac
Author: Christian Rauch
Date:   Wed Jun 16 11:42:02 2021 +0100
Branches: master
https://developer.blender.org/rB0732a9f1b292edfea6270c23466a40c69b0f99ac

GHOST/XR: enable X11-EGL context for OpenXR

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

M	intern/ghost/CMakeLists.txt
M	intern/ghost/intern/GHOST_IXrGraphicsBinding.h
M	intern/ghost/intern/GHOST_XrContext.cpp
M	intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
M	intern/ghost/intern/GHOST_Xr_openxr_includes.h

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

diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index 40d78a22e6f..1815a46591a 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -483,10 +483,12 @@ if(WITH_XR_OPENXR)
       shlwapi
     )
   elseif(UNIX AND NOT APPLE)
-    list(APPEND XR_PLATFORM_DEFINES
-      -DXR_OS_LINUX
-      -DXR_USE_PLATFORM_XLIB
-    )
+    list(APPEND XR_PLATFORM_DEFINES -DXR_OS_LINUX)
+    if (WITH_GL_EGL)
+      list(APPEND XR_PLATFORM_DEFINES -DXR_USE_PLATFORM_EGL)
+    else()
+      list(APPEND XR_PLATFORM_DEFINES -DXR_USE_PLATFORM_XLIB)
+    endif()
   endif()
 
   add_definitions(-DWITH_XR_OPENXR ${XR_PLATFORM_DEFINES})
diff --git a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
index e9e688b76ab..5508d34e96c 100644
--- a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
+++ b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
@@ -31,7 +31,11 @@ class GHOST_IXrGraphicsBinding {
  public:
   union {
 #if defined(WITH_GHOST_X11)
+#  if defined(WITH_GL_EGL)
+    XrGraphicsBindingEGLMNDX egl;
+#  else
     XrGraphicsBindingOpenGLXlibKHR glx;
+#  endif
 #elif defined(WIN32)
     XrGraphicsBindingOpenGLWin32KHR wgl;
     XrGraphicsBindingD3D11KHR d3d11;
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index daad0b8190a..f057e679d56 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -420,6 +420,11 @@ void GHOST_XrContext::getExtensionsToEnable(
     r_ext_names.push_back(gpu_binding);
   }
 
+#if defined(WITH_GL_EGL)
+  assert(openxr_extension_is_available(m_oxr->extensions, XR_MNDX_EGL_ENABLE_EXTENSION_NAME));
+  r_ext_names.push_back(XR_MNDX_EGL_ENABLE_EXTENSION_NAME);
+#endif
+
   for (const std::string_view &ext : try_ext) {
     if (openxr_extension_is_available(m_oxr->extensions, ext)) {
       r_ext_names.push_back(ext.data());
diff --git a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
index 30a2a238ccd..a4b605876fd 100644
--- a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
+++ b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
@@ -22,7 +22,9 @@
 #include <list>
 #include <sstream>
 
-#if defined(WITH_GHOST_X11)
+#if defined(WITH_GL_EGL)
+#  include "GHOST_ContextEGL.h"
+#elif defined(WITH_GHOST_X11)
 #  include "GHOST_ContextGLX.h"
 #elif defined(WIN32)
 #  include "GHOST_ContextD3D.h"
@@ -66,7 +68,9 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
                                 XrSystemId system_id,
                                 std::string *r_requirement_info) const override
   {
-#if defined(WITH_GHOST_X11)
+#if defined(WITH_GL_EGL)
+    GHOST_ContextEGL &ctx_gl = static_cast<GHOST_ContextEGL &>(ghost_ctx);
+#elif defined(WITH_GHOST_X11)
     GHOST_ContextGLX &ctx_gl = static_cast<GHOST_ContextGLX &>(ghost_ctx);
 #else
     GHOST_ContextWGL &ctx_gl = static_cast<GHOST_ContextWGL &>(ghost_ctx);
@@ -106,6 +110,15 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
   void initFromGhostContext(GHOST_Context &ghost_ctx) override
   {
 #if defined(WITH_GHOST_X11)
+#if defined(WITH_GL_EGL)
+    GHOST_ContextEGL &ctx_egl = static_cast<GHOST_ContextEGL &>(ghost_ctx);
+
+    oxr_binding.egl.type = XR_TYPE_GRAPHICS_BINDING_EGL_MNDX;
+    oxr_binding.egl.getProcAddress = eglGetProcAddress;
+    oxr_binding.egl.display = ctx_egl.getDisplay();
+    oxr_binding.egl.config = ctx_egl.getConfig();
+    oxr_binding.egl.context = ctx_egl.getContext();
+#else
     GHOST_ContextGLX &ctx_glx = static_cast<GHOST_ContextGLX &>(ghost_ctx);
     XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx.m_display, ctx_glx.m_fbconfig);
 
@@ -117,6 +130,7 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
     oxr_binding.glx.visualid = visual_info->visualid;
 
     XFree(visual_info);
+#endif
 #elif defined(WIN32)
     GHOST_ContextWGL &ctx_wgl = static_cast<GHOST_ContextWGL &>(ghost_ctx);
 
diff --git a/intern/ghost/intern/GHOST_Xr_openxr_includes.h b/intern/ghost/intern/GHOST_Xr_openxr_includes.h
index d1deaeb0d1a..72e38097a97 100644
--- a/intern/ghost/intern/GHOST_Xr_openxr_includes.h
+++ b/intern/ghost/intern/GHOST_Xr_openxr_includes.h
@@ -42,7 +42,13 @@
 #  include <d3d12.h>
 #endif
 #ifdef WITH_GHOST_X11
-#  include <GL/glxew.h>
+#  ifdef WITH_GL_EGL
+/* TODO: Why do we have to create this typedef manually? */
+typedef void (* (*PFNEGLGETPROCADDRESSPROC)(const char *procname))(void);
+#    include <GL/eglew.h>
+#  else
+#    include <GL/glxew.h>
+#  endif
 #endif
 
 #include <openxr/openxr.h>



More information about the Bf-blender-cvs mailing list