diff options
Diffstat (limited to 'intern/ghost/intern/GHOST_XrGraphicsBinding.cpp')
-rw-r--r-- | intern/ghost/intern/GHOST_XrGraphicsBinding.cpp | 124 |
1 files changed, 78 insertions, 46 deletions
diff --git a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp index aa230bf8deb..6a7eb25925a 100644 --- a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp +++ b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp @@ -8,17 +8,16 @@ #include <list> #include <sstream> -#if defined(WITH_GL_EGL) +#if defined(WITH_GHOST_X11) # include "GHOST_ContextEGL.h" -# if defined(WITH_GHOST_X11) -# include "GHOST_SystemX11.h" -# endif -# if defined(WITH_GHOST_WAYLAND) -# include "GHOST_SystemWayland.h" -# endif -#elif defined(WITH_GHOST_X11) # include "GHOST_ContextGLX.h" -#elif defined(WIN32) +# include "GHOST_SystemX11.h" +#endif +#if defined(WITH_GHOST_WAYLAND) +# include "GHOST_ContextEGL.h" +# include "GHOST_SystemWayland.h" +#endif +#if defined(WIN32) # include "GHOST_ContextD3D.h" # include "GHOST_ContextWGL.h" # include "GHOST_SystemWin32.h" @@ -61,19 +60,30 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding { XrSystemId system_id, std::string *r_requirement_info) const override { -#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 + int gl_major_version, gl_minor_version; +#if defined(WIN32) GHOST_ContextWGL &ctx_gl = static_cast<GHOST_ContextWGL &>(ghost_ctx); + gl_major_version = ctx_gl.m_contextMajorVersion; + gl_minor_version = ctx_gl.m_contextMinorVersion; +#elif defined(WITH_GHOST_X11) || defined(WITH_GHOST_WAYLAND) + if (dynamic_cast<GHOST_ContextEGL *>(&ghost_ctx)) { + GHOST_ContextEGL &ctx_gl = static_cast<GHOST_ContextEGL &>(ghost_ctx); + gl_major_version = ctx_gl.m_contextMajorVersion; + gl_minor_version = ctx_gl.m_contextMinorVersion; + } +# if defined(WITH_GHOST_X11) + else { + GHOST_ContextGLX &ctx_gl = static_cast<GHOST_ContextGLX &>(ghost_ctx); + gl_major_version = ctx_gl.m_contextMajorVersion; + gl_minor_version = ctx_gl.m_contextMinorVersion; + } +# endif #endif static PFN_xrGetOpenGLGraphicsRequirementsKHR s_xrGetOpenGLGraphicsRequirementsKHR_fn = nullptr; // static XrInstance s_instance = XR_NULL_HANDLE; XrGraphicsRequirementsOpenGLKHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR}; - const XrVersion gl_version = XR_MAKE_VERSION( - ctx_gl.m_contextMajorVersion, ctx_gl.m_contextMinorVersion, 0); + const XrVersion gl_version = XR_MAKE_VERSION(gl_major_version, gl_minor_version, 0); /* Although it would seem reasonable that the proc address would not change if the instance was * the same, in testing, repeated calls to #xrGetInstanceProcAddress() with the same instance @@ -112,45 +122,67 @@ 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); - - if (dynamic_cast<const GHOST_SystemX11 *const>(ctx_egl.m_system)) { - 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(); - } +#if defined(WITH_GHOST_X11) || defined(WITH_GHOST_WAYLAND) + /* WAYLAND/X11 may be dynamically selected at load time but both may also be + * supported at compile time individually. + * Without `is_ctx_egl` & `is_wayland` preprocessor checks become an unmanageable soup. */ + const bool is_ctx_egl = dynamic_cast<GHOST_ContextEGL *>(&ghost_ctx) != nullptr; + if (is_ctx_egl) { + GHOST_ContextEGL &ctx_egl = static_cast<GHOST_ContextEGL &>(ghost_ctx); + const bool is_wayland = ( +# if defined(WITH_GHOST_WAYLAND) + dynamic_cast<const GHOST_SystemWayland *const>(ctx_egl.m_system) != nullptr # else - GHOST_ContextGLX &ctx_glx = static_cast<GHOST_ContextGLX &>(ghost_ctx); - XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx.m_display, ctx_glx.m_fbconfig); + false +# endif + ); + + if (is_wayland) { +# if defined(WITH_GHOST_WAYLAND) + /* #GHOST_SystemWayland */ + oxr_binding.wl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR; + oxr_binding.wl.display = (struct wl_display *)ctx_egl.m_nativeDisplay; +# else + GHOST_ASSERT(false, "Unexpected State: logical error, unreachable!"); +# endif /* !WITH_GHOST_WAYLAND */ + } + else { /* `!is_wayland` */ +# if defined(WITH_GHOST_X11) + /* #GHOST_SystemX11. */ + 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_ASSERT(false, "Unexpected State: built with only WAYLAND and no System found!"); +# endif /* !WITH_GHOST_X11 */ + } + } + else { /* `!is_ctx_egl` */ +# if defined(WITH_GHOST_X11) + GHOST_ContextGLX &ctx_glx = static_cast<GHOST_ContextGLX &>(ghost_ctx); + XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx.m_display, ctx_glx.m_fbconfig); - oxr_binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR; - oxr_binding.glx.xDisplay = ctx_glx.m_display; - oxr_binding.glx.glxFBConfig = ctx_glx.m_fbconfig; - oxr_binding.glx.glxDrawable = ctx_glx.m_window; - oxr_binding.glx.glxContext = ctx_glx.m_context; - oxr_binding.glx.visualid = visual_info->visualid; + oxr_binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR; + oxr_binding.glx.xDisplay = ctx_glx.m_display; + oxr_binding.glx.glxFBConfig = ctx_glx.m_fbconfig; + oxr_binding.glx.glxDrawable = ctx_glx.m_window; + oxr_binding.glx.glxContext = ctx_glx.m_context; + oxr_binding.glx.visualid = visual_info->visualid; - XFree(visual_info); -# endif + XFree(visual_info); +# else + GHOST_ASSERT(false, "Unexpected State: built without X11 and no EGL context is available!"); +# endif /* !WITH_GHOST_X11 */ + } #elif defined(WIN32) GHOST_ContextWGL &ctx_wgl = static_cast<GHOST_ContextWGL &>(ghost_ctx); oxr_binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR; oxr_binding.wgl.hDC = ctx_wgl.m_hDC; oxr_binding.wgl.hGLRC = ctx_wgl.m_hGLRC; -#endif - -#if defined(WITH_GHOST_WAYLAND) - GHOST_ContextEGL &ctx_wl_egl = static_cast<GHOST_ContextEGL &>(ghost_ctx); - if (dynamic_cast<const GHOST_SystemWayland *const>(ctx_wl_egl.m_system)) { - oxr_binding.wl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR; - oxr_binding.wl.display = (struct wl_display *)ctx_wl_egl.m_nativeDisplay; - } -#endif +#endif /* WIN32 */ /* Generate a frame-buffer to use for blitting into the texture. */ glGenFramebuffers(1, &m_fbo); |