diff options
Diffstat (limited to 'source/blender/windowmanager/xr/intern')
5 files changed, 57 insertions, 55 deletions
diff --git a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c index 8903305adb4..076f279ccbb 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_actionmap.c @@ -85,9 +85,6 @@ static XrActionMapBinding *wm_xr_actionmap_binding_find_except(XrActionMapItem * return NULL; } -/** - * Ensure unique name among all action map bindings. - */ void WM_xr_actionmap_binding_ensure_unique(XrActionMapItem *ami, XrActionMapBinding *amb) { char name[MAX_NAME]; @@ -118,7 +115,6 @@ void WM_xr_actionmap_binding_ensure_unique(XrActionMapItem *ami, XrActionMapBind static XrActionMapBinding *wm_xr_actionmap_binding_copy(XrActionMapBinding *amb_src) { XrActionMapBinding *amb_dst = MEM_dupallocN(amb_src); - amb_dst->prev = amb_dst->next = NULL; return amb_dst; @@ -198,10 +194,6 @@ static void wm_xr_actionmap_item_properties_free(XrActionMapItem *ami) } } -/** - * Similar to #wm_xr_actionmap_item_properties_set() - * but checks for the #eXrActionType and #wmOperatorType having changed. - */ void WM_xr_actionmap_item_properties_update_ot(XrActionMapItem *ami) { switch (ami->type) { @@ -278,9 +270,6 @@ static XrActionMapItem *wm_xr_actionmap_item_find_except(XrActionMap *actionmap, return NULL; } -/** - * Ensure unique name among all action map items. - */ void WM_xr_actionmap_item_ensure_unique(XrActionMap *actionmap, XrActionMapItem *ami) { char name[MAX_NAME]; @@ -308,25 +297,29 @@ void WM_xr_actionmap_item_ensure_unique(XrActionMap *actionmap, XrActionMapItem BLI_strncpy(ami->name, name, MAX_NAME); } -static XrActionMapItem *wm_xr_actionmap_item_copy(XrActionMapItem *ami) +static XrActionMapItem *wm_xr_actionmap_item_copy(XrActionMapItem *ami_src) { - XrActionMapItem *amin = MEM_dupallocN(ami); - - amin->prev = amin->next = NULL; + XrActionMapItem *ami_dst = MEM_dupallocN(ami_src); + ami_dst->prev = ami_dst->next = NULL; - if (amin->op_properties) { - amin->op_properties_ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr"); - WM_operator_properties_create(amin->op_properties_ptr, amin->op); + BLI_listbase_clear(&ami_dst->bindings); + LISTBASE_FOREACH (XrActionMapBinding *, amb, &ami_src->bindings) { + XrActionMapBinding *amb_new = wm_xr_actionmap_binding_copy(amb); + BLI_addtail(&ami_dst->bindings, amb_new); + } - amin->op_properties = IDP_CopyProperty(amin->op_properties); - amin->op_properties_ptr->data = amin->op_properties; + if (ami_dst->op_properties) { + ami_dst->op_properties_ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr"); + WM_operator_properties_create(ami_dst->op_properties_ptr, ami_dst->op); + ami_dst->op_properties = IDP_CopyProperty(ami_src->op_properties); + ami_dst->op_properties_ptr->data = ami_dst->op_properties; } else { - amin->op_properties = NULL; - amin->op_properties_ptr = NULL; + ami_dst->op_properties = NULL; + ami_dst->op_properties_ptr = NULL; } - return amin; + return ami_dst; } XrActionMapItem *WM_xr_actionmap_item_add_copy(XrActionMap *actionmap, XrActionMapItem *ami_src) @@ -411,9 +404,6 @@ static XrActionMap *wm_xr_actionmap_find_except(wmXrRuntimeData *runtime, return NULL; } -/** - * Ensure unique name among all action maps. - */ void WM_xr_actionmap_ensure_unique(wmXrRuntimeData *runtime, XrActionMap *actionmap) { char name[MAX_NAME]; @@ -444,10 +434,9 @@ void WM_xr_actionmap_ensure_unique(wmXrRuntimeData *runtime, XrActionMap *action static XrActionMap *wm_xr_actionmap_copy(XrActionMap *am_src) { XrActionMap *am_dst = MEM_dupallocN(am_src); - am_dst->prev = am_dst->next = NULL; - BLI_listbase_clear(&am_dst->items); + BLI_listbase_clear(&am_dst->items); LISTBASE_FOREACH (XrActionMapItem *, ami, &am_src->items) { XrActionMapItem *ami_new = wm_xr_actionmap_item_copy(ami); BLI_addtail(&am_dst->items, ami_new); diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c index 72d88bb3043..5d0163af5e1 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c @@ -139,12 +139,6 @@ static void wm_xr_draw_viewport_buffers_to_active_framebuffer( GPU_viewport_draw_to_screen_ex(vp->viewport, 0, &rect, draw_view->expects_srgb_buffer, true); } -/** - * \brief Draw a viewport for a single eye. - * - * This is the main viewport drawing function for VR sessions. It's assigned to Ghost-XR as a - * callback (see GHOST_XrDrawViewFunc()) and executed for each view (read: eye). - */ void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata) { wmXrDrawData *draw_data = customdata; diff --git a/source/blender/windowmanager/xr/intern/wm_xr_intern.h b/source/blender/windowmanager/xr/intern/wm_xr_intern.h index 7de1f254224..e2368901757 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_intern.h +++ b/source/blender/windowmanager/xr/intern/wm_xr_intern.h @@ -213,6 +213,11 @@ void wm_xr_session_draw_data_update(wmXrSessionState *state, const XrSessionSettings *settings, const GHOST_XrDrawViewInfo *draw_view, wmXrDrawData *draw_data); +/** + * Update information that is only stored for external state queries. E.g. for Python API to + * request the current (as in, last known) viewer pose. + * Controller data and action sets will be updated separately via wm_xr_session_actions_update(). + */ void wm_xr_session_state_update(const XrSessionSettings *settings, const wmXrDrawData *draw_data, const GHOST_XrDrawViewInfo *draw_view, @@ -230,9 +235,16 @@ void wm_xr_session_controller_data_populate(const wmXrAction *grip_action, void wm_xr_session_controller_data_clear(wmXrSessionState *state); /* wm_xr_draw.c */ + void wm_xr_pose_to_mat(const GHOST_XrPose *pose, float r_mat[4][4]); void wm_xr_pose_scale_to_mat(const GHOST_XrPose *pose, float scale, float r_mat[4][4]); void wm_xr_pose_to_imat(const GHOST_XrPose *pose, float r_imat[4][4]); void wm_xr_pose_scale_to_imat(const GHOST_XrPose *pose, float scale, float r_imat[4][4]); +/** + * \brief Draw a viewport for a single eye. + * + * This is the main viewport drawing function for VR sessions. It's assigned to Ghost-XR as a + * callback (see GHOST_XrDrawViewFunc()) and executed for each view (read: eye). + */ void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata); void wm_xr_draw_controllers(const struct bContext *C, struct ARegion *region, void *customdata); diff --git a/source/blender/windowmanager/xr/intern/wm_xr_operators.c b/source/blender/windowmanager/xr/intern/wm_xr_operators.c index f3470edf2f7..c503f5d4fee 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_operators.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_operators.c @@ -553,7 +553,7 @@ static int wm_xr_navigation_grab_modal(bContext *C, wmOperator *op, const wmEven wm_xr_navigation_grab_bimanual_state_update(actiondata, data); - /* Note: KM_PRESS and KM_RELEASE are the only two values supported by XR events during event + /* NOTE: #KM_PRESS and #KM_RELEASE are the only two values supported by XR events during event * dispatching (see #wm_xr_session_action_states_interpret()). For modal XR operators, modal * handling starts when an input is "pressed" (action state exceeds the action threshold) and * ends when the input is "released" (state falls below the threshold). */ diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index 3224869b04a..bad735ee598 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -30,6 +30,7 @@ #include "BLI_math.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "DNA_camera_types.h" #include "DNA_space_types.h" @@ -154,10 +155,6 @@ void wm_xr_session_toggle(wmWindowManager *wm, } } -/** - * Check if the XR-Session was triggered. - * If an error happened while trying to start a session, this returns false too. - */ bool WM_xr_session_exists(const wmXrData *xr) { return xr->runtime && xr->runtime->context && xr->runtime->session_state.is_started; @@ -168,9 +165,6 @@ void WM_xr_session_base_pose_reset(wmXrData *xr) xr->runtime->session_state.force_reset_to_base_pose = true; } -/** - * Check if the session is running, according to the OpenXR definition. - */ bool WM_xr_session_is_ready(const wmXrData *xr) { return WM_xr_session_exists(xr) && GHOST_XrSessionIsRunning(xr->runtime->context); @@ -250,10 +244,9 @@ wmWindow *wm_xr_session_root_window_or_fallback_get(const wmWindowManager *wm, * It's important that the VR session follows some existing window, otherwise it would need to have * an own depsgraph, which is an expense we should avoid. */ -static void wm_xr_session_scene_and_evaluated_depsgraph_get(Main *bmain, - const wmWindowManager *wm, - Scene **r_scene, - Depsgraph **r_depsgraph) +static void wm_xr_session_scene_and_depsgraph_get(const wmWindowManager *wm, + Scene **r_scene, + Depsgraph **r_depsgraph) { const wmWindow *root_win = wm_xr_session_root_window_or_fallback_get(wm, wm->xr.runtime); @@ -263,7 +256,6 @@ static void wm_xr_session_scene_and_evaluated_depsgraph_get(Main *bmain, Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer); BLI_assert(scene && view_layer && depsgraph); - BKE_scene_graph_evaluated_ensure(depsgraph, bmain); *r_scene = scene; *r_depsgraph = depsgraph; } @@ -354,11 +346,6 @@ void wm_xr_session_draw_data_update(wmXrSessionState *state, } } -/** - * Update information that is only stored for external state queries. E.g. for Python API to - * request the current (as in, last known) viewer pose. - * Controller data and action sets will be updated separately via wm_xr_session_actions_update(). - */ void wm_xr_session_state_update(const XrSessionSettings *settings, const wmXrDrawData *draw_data, const GHOST_XrDrawViewInfo *draw_view, @@ -1314,7 +1301,6 @@ void wm_xr_session_controller_data_clear(wmXrSessionState *state) static void wm_xr_session_surface_draw(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); - Main *bmain = CTX_data_main(C); wmXrDrawData draw_data; if (!WM_xr_session_is_ready(&wm->xr)) { @@ -1323,12 +1309,32 @@ static void wm_xr_session_surface_draw(bContext *C) Scene *scene; Depsgraph *depsgraph; - wm_xr_session_scene_and_evaluated_depsgraph_get(bmain, wm, &scene, &depsgraph); + wm_xr_session_scene_and_depsgraph_get(wm, &scene, &depsgraph); + /* Might fail when force-redrawing windows with #WM_redraw_windows(), which is done on file + * writing for example. */ + // BLI_assert(DEG_is_fully_evaluated(depsgraph)); wm_xr_session_draw_data_populate(&wm->xr, scene, depsgraph, &draw_data); GHOST_XrSessionDrawViews(wm->xr.runtime->context, &draw_data); - GPU_framebuffer_restore(); + /* There's no active framebuffer if the session was cancelled (exception while drawing views). */ + if (GPU_framebuffer_active_get()) { + GPU_framebuffer_restore(); + } +} + +static void wm_xr_session_do_depsgraph(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + if (!WM_xr_session_is_ready(&wm->xr)) { + return; + } + + Scene *scene; + Depsgraph *depsgraph; + wm_xr_session_scene_and_depsgraph_get(wm, &scene, &depsgraph); + BKE_scene_graph_evaluated_ensure(depsgraph, CTX_data_main(C)); } bool wm_xr_session_surface_offscreen_ensure(wmXrSurfaceData *surface_data, @@ -1439,6 +1445,7 @@ static wmSurface *wm_xr_session_surface_create(void) data->controller_art = MEM_callocN(sizeof(*(data->controller_art)), "XrControllerRegionType"); surface->draw = wm_xr_session_surface_draw; + surface->do_depsgraph = wm_xr_session_do_depsgraph; surface->free_data = wm_xr_session_surface_free_data; surface->activate = DRW_xr_drawing_begin; surface->deactivate = DRW_xr_drawing_end; |