GHOST/XR: enable X11-EGL context for OpenXR

This commit is contained in:
Christian Rauch 2021-06-16 11:42:02 +01:00
parent 87833f8f95
commit 0732a9f1b2
5 changed files with 38 additions and 7 deletions

View File

@ -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})

View File

@ -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;

View File

@ -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());

View File

@ -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);

View File

@ -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>