[Bf-blender-cvs] [505a19ed75b] master: Cleanup: Split up Window-Manager VR file (and related changes)

Julian Eisel noreply at git.blender.org
Sat Apr 4 18:56:08 CEST 2020


Commit: 505a19ed75b2829a561475ab4acc075b715a8499
Author: Julian Eisel
Date:   Sat Apr 4 02:17:49 2020 +0200
Branches: master
https://developer.blender.org/rB505a19ed75b2829a561475ab4acc075b715a8499

Cleanup: Split up Window-Manager VR file (and related changes)

Splits up wm_xr.c into multiple files in their own folder:
source/blender/windowmanager/xr. So this matches how the message bus and
gizmo code have their own folder and files.

This allows better structuring and should make the code scale better.
I rather do this early on than to wait until we end up with a single,
huge file.

Also improves a bit how data is prepared and updated for drawing.

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

M	source/blender/windowmanager/CMakeLists.txt
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_window.c
D	source/blender/windowmanager/intern/wm_xr.c
M	source/blender/windowmanager/wm.h
M	source/blender/windowmanager/wm_surface.h
A	source/blender/windowmanager/xr/intern/wm_xr.c
A	source/blender/windowmanager/xr/intern/wm_xr_draw.c
A	source/blender/windowmanager/xr/intern/wm_xr_intern.h
A	source/blender/windowmanager/xr/intern/wm_xr_session.c
A	source/blender/windowmanager/xr/wm_xr.h

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

diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index a1b67216f1a..90ff7bb8f85 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -191,8 +191,18 @@ endif()
 
 if(WITH_XR_OPENXR)
   add_definitions(-DWITH_XR_OPENXR)
+
+  list(APPEND INC
+    xr
+  )
+
   list(APPEND SRC
-    intern/wm_xr.c
+    xr/intern/wm_xr.c
+    xr/intern/wm_xr_draw.c
+    xr/intern/wm_xr_session.c
+
+    xr/wm_xr.h
+    xr/intern/wm_xr_intern.h
   )
 endif()
 
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index e9d2ee9c662..54e6735175d 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -55,6 +55,9 @@
 #include "wm_draw.h"
 #include "wm_event_system.h"
 #include "wm_window.h"
+#ifdef WITH_XR_OPENXR
+#  include "wm_xr.h"
+#endif
 
 #include "BKE_undo_system.h"
 #include "ED_screen.h"
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index f8e020b00d0..6d25874da45 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -106,6 +106,9 @@
 #include "wm_event_types.h"
 #include "wm_files.h"
 #include "wm_window.h"
+#ifdef WITH_XR_OPENXR
+#  include "wm_xr.h"
+#endif
 
 #define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)")
 
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 699f618f956..a83432e0248 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -65,6 +65,9 @@
 #include "wm_platform_support.h"
 #include "wm_window.h"
 #include "wm_window_private.h"
+#ifdef WITH_XR_OPENXR
+#  include "wm_xr.h"
+#endif
 
 #include "ED_anim_api.h"
 #include "ED_fileselect.h"
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
deleted file mode 100644
index be0c8b4798b..00000000000
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ /dev/null
@@ -1,737 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup wm
- *
- * \name Window-Manager XR API
- *
- * Implements Blender specific functionality for the GHOST_Xr API.
- */
-
-#include "BKE_context.h"
-#include "BKE_global.h"
-#include "BKE_idprop.h"
-#include "BKE_main.h"
-#include "BKE_object.h"
-#include "BKE_report.h"
-#include "BKE_screen.h"
-
-#include "BLI_ghash.h"
-#include "BLI_math_geom.h"
-#include "BLI_math_matrix.h"
-
-#include "CLG_log.h"
-
-#include "DNA_camera_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_xr_types.h"
-
-#include "DRW_engine.h"
-
-#include "ED_view3d.h"
-#include "ED_view3d_offscreen.h"
-
-#include "GHOST_C-api.h"
-
-#include "GPU_context.h"
-#include "GPU_draw.h"
-#include "GPU_matrix.h"
-#include "GPU_viewport.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "UI_interface.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "wm.h"
-#include "wm_surface.h"
-#include "wm_window.h"
-
-struct wmXrRuntimeData *wm_xr_runtime_data_create(void);
-void wm_xr_runtime_data_free(struct wmXrRuntimeData **runtime);
-void wm_xr_draw_view(const GHOST_XrDrawViewInfo *, void *);
-void *wm_xr_session_gpu_binding_context_create(void);
-void wm_xr_session_gpu_binding_context_destroy(GHOST_ContextHandle);
-wmSurface *wm_xr_session_surface_create(void);
-void wm_xr_pose_to_viewmat(const GHOST_XrPose *pose, float r_viewmat[4][4]);
-
-/* -------------------------------------------------------------------- */
-
-typedef struct wmXrSessionState {
-  bool is_started;
-
-  /** Last known viewer pose (centroid of eyes, in world space) stored for queries. */
-  GHOST_XrPose viewer_pose;
-  /** The last known view matrix, calculated from above's viewer pose. */
-  float viewer_viewmat[4][4];
-  float focal_len;
-
-  /** Copy of XrSessionSettings.flag created on the last draw call, stored to detect changes. */
-  int prev_settings_flag;
-  /** Copy of wmXrDrawData.eye_position_ofs. */
-  float prev_eye_position_ofs[3];
-
-  bool is_view_data_set;
-} wmXrSessionState;
-
-typedef struct wmXrRuntimeData {
-  GHOST_XrContextHandle context;
-
-  /* Although this struct is internal, RNA gets a handle to this for state information queries. */
-  wmXrSessionState session_state;
-  wmXrSessionExitFn exit_fn;
-} wmXrRuntimeData;
-
-typedef struct wmXrDrawData {
-  /** The pose (location + rotation) to which eye deltas will be applied to when drawing (world
-   * space). With positional tracking enabled, it should be the same as the base pose, when
-   * disabled it also contains a location delta from the moment the option was toggled. */
-  GHOST_XrPose base_pose;
-  float eye_position_ofs[3]; /* Local/view space. */
-} wmXrDrawData;
-
-typedef struct {
-  GPUOffScreen *offscreen;
-  GPUViewport *viewport;
-} wmXrSurfaceData;
-
-typedef struct {
-  wmWindowManager *wm;
-} wmXrErrorHandlerData;
-
-/* -------------------------------------------------------------------- */
-
-static wmSurface *g_xr_surface = NULL;
-static CLG_LogRef LOG = {"wm.xr"};
-
-/* -------------------------------------------------------------------- */
-/** \name XR-Context
- *
- * All XR functionality is accessed through a #GHOST_XrContext handle.
- * The lifetime of this context also determines the lifetime of the OpenXR instance, which is the
- * representation of the OpenXR runtime connection within the application.
- *
- * \{ */
-
-static void wm_xr_error_handler(const GHOST_XrError *error)
-{
-  wmXrErrorHandlerData *handler_data = error->customdata;
-  wmWindowManager *wm = handler_data->wm;
-
-  BKE_reports_clear(&wm->reports);
-  WM_report(RPT_ERROR, error->user_message);
-  WM_report_banner_show();
-
-  if (wm->xr.runtime) {
-    /* Just play safe and destroy the entire runtime data, including context. */
-    wm_xr_runtime_data_free(&wm->xr.runtime);
-  }
-}
-
-bool wm_xr_init(wmWindowManager *wm)
-{
-  if (wm->xr.runtime && wm->xr.runtime->context) {
-    return true;
-  }
-  static wmXrErrorHandlerData error_customdata;
-
-  /* Set up error handling */
-  error_customdata.wm = wm;
-  GHOST_XrErrorHandler(wm_xr_error_handler, &error_customdata);
-
-  {
-    const GHOST_TXrGraphicsBinding gpu_bindings_candidates[] = {
-        GHOST_kXrGraphicsOpenGL,
-#ifdef WIN32
-        GHOST_kXrGraphicsD3D11,
-#endif
-    };
-    GHOST_XrContextCreateInfo create_info = {
-        .gpu_binding_candidates = gpu_bindings_candidates,
-        .gpu_binding_candidates_count = ARRAY_SIZE(gpu_bindings_candidates),
-    };
-    GHOST_XrContextHandle context;
-
-    if (G.debug & G_DEBUG_XR) {
-      create_info.context_flag |= GHOST_kXrContextDebug;
-    }
-    if (G.debug & G_DEBUG_XR_TIME) {
-      create_info.context_flag |= GHOST_kXrContextDebugTime;
-    }
-
-    if (!(context = GHOST_XrContextCreate(&create_info))) {
-      return false;
-    }
-
-    /* Set up context callbacks */
-    GHOST_XrGraphicsContextBindFuncs(context,
-                                     wm_xr_session_gpu_binding_context_create,
-                                     wm_xr_session_gpu_binding_context_destroy);
-    GHOST_XrDrawViewFunc(context, wm_xr_draw_view);
-
-    if (!wm->xr.runtime) {
-      wm->xr.runtime = wm_xr_runtime_data_create();
-      wm->xr.runtime->context = context;
-    }
-  }
-  BLI_assert(wm->xr.runtime && wm->xr.runtime->context);
-
-  return true;
-}
-
-void wm_xr_exit(wmWindowManager *wm)
-{
-  if (wm->xr.runtime != NULL) {
-    wm_xr_runtime_data_free(&wm->xr.runtime);
-  }
-  if (wm->xr.session_settings.shading.prop) {
-    IDP_FreeProperty(wm->xr.session_settings.shading.prop);
-    wm->xr.session_settings.shading.prop = NULL;
-  }
-}
-
-bool wm_xr_events_handle(wmWindowManager *wm)
-{
-  if (wm->xr.runtime && wm->xr.runtime->context) {
-    return GHOST_XrEventsHandle(wm->xr.runtime->context);
-  }
-  return false;
-}
-
-/** \} */ /* XR-Context */
-
-/* -------------------------------------------------------------------- */
-/** \name XR Runtime Data
- *
- * \{ */
-
-wmXrRuntimeData *wm_xr_runtime_data_create(void)
-{
-  wmXrRuntimeData *runtime = MEM_callocN(sizeof(*runtime), __func__);
-  return runtime;
-}
-
-void wm_xr_runtime_data_free(wmXrRuntimeData **runtime)
-{
-  /* Note that this function may be called twice, because of an indirect recursion: If a session is
-   * running while WM-XR calls this function, calling GHOST_XrContextDestroy() will call this
-   * again, because it's also set as the session exit callback. So NULL-check and NULL everything
-   * that is freed here. */
-
-  /* We free all runtime XR data here, so if the context is still alive, destroy it. */
-  if ((*runtime)->context != NULL) {
-    GHOST_XrContextHandle context = (*runtime)->context;
-    /* Prevent recursive GHOST_XrContextDestroy() call by NULL'ing the context pointer before the
-     * first call, see comment above. */
-    (*runtime)->context = NULL;
-    GHOST_XrContextDestroy(context);
-  }
-  MEM_SAFE_FREE(*runtime);
-}
-
-static void wm_xr_base_pose_calc(const Scene *scene,
-                                 const XrSessionSettings *settings,
-                                 GHOST_XrPose *r_base_pose)
-{
-  const Object *base_pose_object = ((settings->base_pose_type == XR_BASE_POSE_OBJECT) &&
-                                    settings->base_pose_object) ?
-               

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list