From 0732a9f1b292edfea6270c23466a40c69b0f99ac Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Wed, 16 Jun 2021 11:42:02 +0100 Subject: GHOST/XR: enable X11-EGL context for OpenXR --- intern/ghost/CMakeLists.txt | 10 ++++++---- intern/ghost/intern/GHOST_IXrGraphicsBinding.h | 4 ++++ intern/ghost/intern/GHOST_XrContext.cpp | 5 +++++ intern/ghost/intern/GHOST_XrGraphicsBinding.cpp | 18 ++++++++++++++++-- intern/ghost/intern/GHOST_Xr_openxr_includes.h | 8 +++++++- 5 files changed, 38 insertions(+), 7 deletions(-) (limited to 'intern/ghost') 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 #include -#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_ctx); +#elif defined(WITH_GHOST_X11) GHOST_ContextGLX &ctx_gl = static_cast(ghost_ctx); #else GHOST_ContextWGL &ctx_gl = static_cast(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_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_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_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 #endif #ifdef WITH_GHOST_X11 -# include +# ifdef WITH_GL_EGL +/* TODO: Why do we have to create this typedef manually? */ +typedef void (* (*PFNEGLGETPROCADDRESSPROC)(const char *procname))(void); +# include +# else +# include +# endif #endif #include -- cgit v1.2.3