[Bf-blender-cvs] [b3e9ef19247] master: Fix building WITH_GHOST_WAYLAND, WITH_OPENXR (without X11)

Campbell Barton noreply at git.blender.org
Tue Sep 13 02:43:08 CEST 2022


Commit: b3e9ef1924783f3684f6e0c1b4cd588191340adf
Author: Campbell Barton
Date:   Tue Sep 13 10:35:22 2022 +1000
Branches: master
https://developer.blender.org/rBb3e9ef1924783f3684f6e0c1b4cd588191340adf

Fix building WITH_GHOST_WAYLAND, WITH_OPENXR (without X11)

The pre-processor blocks contained un-balanced braces, causing a syntax
error when building with WAYLAND but not X11.

Use the same number of opening & closing braces in each pre-processor
block so changes aren't as likely to break other platforms.

Also assert when unexpected states are reached.

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

M	intern/ghost/intern/GHOST_XrGraphicsBinding.cpp

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

diff --git a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
index 267d19dcecb..6a7eb25925a 100644
--- a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
+++ b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
@@ -123,27 +123,44 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
   void initFromGhostContext(GHOST_Context &ghost_ctx) override
   {
 #if defined(WITH_GHOST_X11) || defined(WITH_GHOST_WAYLAND)
-    if (dynamic_cast<GHOST_ContextEGL *>(&ghost_ctx)) {
+    /* 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
+          false
+#  endif
+      );
 
+      if (is_wayland) {
 #  if defined(WITH_GHOST_WAYLAND)
-      if (dynamic_cast<const GHOST_SystemWayland *const>(ctx_egl.m_system)) {
+        /* #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
-#  endif
+      else { /* `!is_wayland` */
 #  if defined(WITH_GHOST_X11)
-      {
-        /* SystemX11. */
+        /* #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 {
+    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);
 
@@ -155,7 +172,9 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
       oxr_binding.glx.visualid = visual_info->visualid;
 
       XFree(visual_info);
-#  endif
+#  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);
@@ -163,7 +182,7 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
     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
+#endif /* WIN32 */
 
     /* Generate a frame-buffer to use for blitting into the texture. */
     glGenFramebuffers(1, &m_fbo);



More information about the Bf-blender-cvs mailing list