Blender  V2.93
Typedefs | Enumerations | Functions | Variables
wm_xr_session.c File Reference
#include "BKE_context.h"
#include "BKE_main.h"
#include "BKE_scene.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "DEG_depsgraph.h"
#include "DNA_camera_types.h"
#include "DRW_engine.h"
#include "GHOST_C-api.h"
#include "GPU_viewport.h"
#include "MEM_guardedalloc.h"
#include "WM_api.h"
#include "WM_types.h"
#include "wm_surface.h"
#include "wm_window.h"
#include "wm_xr_intern.h"

Go to the source code of this file.

Typedefs

typedef enum wmXrSessionStateEvent wmXrSessionStateEvent
 

Enumerations

enum  wmXrSessionStateEvent { SESSION_STATE_EVENT_NONE = 0 , SESSION_STATE_EVENT_START , SESSION_STATE_EVENT_RESET_TO_BASE_POSE , SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE }
 

Functions

static void wm_xr_session_exit_cb (void *customdata)
 
static void wm_xr_session_begin_info_create (wmXrData *xr_data, GHOST_XrSessionBeginInfo *r_begin_info)
 
void wm_xr_session_toggle (wmWindowManager *wm, wmWindow *session_root_win, wmXrSessionExitFn session_exit_fn)
 
bool WM_xr_session_exists (const wmXrData *xr)
 
void WM_xr_session_base_pose_reset (wmXrData *xr)
 
bool WM_xr_session_is_ready (const wmXrData *xr)
 
static void wm_xr_session_base_pose_calc (const Scene *scene, const XrSessionSettings *settings, GHOST_XrPose *r_base_pose)
 
static void wm_xr_session_draw_data_populate (wmXrData *xr_data, Scene *scene, Depsgraph *depsgraph, wmXrDrawData *r_draw_data)
 
static wmWindowwm_xr_session_root_window_or_fallback_get (const wmWindowManager *wm, const wmXrRuntimeData *runtime_data)
 
static void wm_xr_session_scene_and_evaluated_depsgraph_get (Main *bmain, const wmWindowManager *wm, Scene **r_scene, Depsgraph **r_depsgraph)
 
static bool wm_xr_session_draw_data_needs_reset_to_base_pose (const wmXrSessionState *state, const XrSessionSettings *settings)
 
static wmXrSessionStateEvent wm_xr_session_state_to_event (const wmXrSessionState *state, const XrSessionSettings *settings)
 
void wm_xr_session_draw_data_update (const wmXrSessionState *state, const XrSessionSettings *settings, const GHOST_XrDrawViewInfo *draw_view, wmXrDrawData *draw_data)
 
void wm_xr_session_state_update (const XrSessionSettings *settings, const wmXrDrawData *draw_data, const GHOST_XrDrawViewInfo *draw_view, wmXrSessionState *state)
 
wmXrSessionStateWM_xr_session_state_handle_get (const wmXrData *xr)
 
bool WM_xr_session_state_viewer_pose_location_get (const wmXrData *xr, float r_location[3])
 
bool WM_xr_session_state_viewer_pose_rotation_get (const wmXrData *xr, float r_rotation[4])
 
bool WM_xr_session_state_viewer_pose_matrix_info_get (const wmXrData *xr, float r_viewmat[4][4], float *r_focal_len)
 
XR-Session Surface

A wmSurface is used to manage drawing of the VR viewport. It's created and destroyed with the session.

static void wm_xr_session_surface_draw (bContext *C)
 Call Ghost-XR to draw a frame. More...
 
bool wm_xr_session_surface_offscreen_ensure (wmXrSurfaceData *surface_data, const GHOST_XrDrawViewInfo *draw_view)
 
static void wm_xr_session_surface_free_data (wmSurface *surface)
 
static wmSurfacewm_xr_session_surface_create (void)
 
void * wm_xr_session_gpu_binding_context_create (void)
 
void wm_xr_session_gpu_binding_context_destroy (GHOST_ContextHandle UNUSED(context))
 

Variables

static wmSurfaceg_xr_surface = NULL
 
static CLG_LogRef LOG = {"wm.xr"}
 

Typedef Documentation

◆ wmXrSessionStateEvent

Enumeration Type Documentation

◆ wmXrSessionStateEvent

Enumerator
SESSION_STATE_EVENT_NONE 
SESSION_STATE_EVENT_START 
SESSION_STATE_EVENT_RESET_TO_BASE_POSE 
SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE 

Definition at line 205 of file wm_xr_session.c.

Function Documentation

◆ wm_xr_session_base_pose_calc()

static void wm_xr_session_base_pose_calc ( const Scene scene,
const XrSessionSettings settings,
GHOST_XrPose *  r_base_pose 
)
static

◆ WM_xr_session_base_pose_reset()

void WM_xr_session_base_pose_reset ( wmXrData xr)

◆ wm_xr_session_begin_info_create()

static void wm_xr_session_begin_info_create ( wmXrData xr_data,
GHOST_XrSessionBeginInfo *  r_begin_info 
)
static

Definition at line 65 of file wm_xr_session.c.

References wm_xr_session_exit_cb().

Referenced by wm_xr_session_toggle().

◆ wm_xr_session_draw_data_needs_reset_to_base_pose()

static bool wm_xr_session_draw_data_needs_reset_to_base_pose ( const wmXrSessionState state,
const XrSessionSettings settings 
)
static

◆ wm_xr_session_draw_data_populate()

static void wm_xr_session_draw_data_populate ( wmXrData xr_data,
Scene scene,
Depsgraph depsgraph,
wmXrDrawData r_draw_data 
)
static

◆ wm_xr_session_draw_data_update()

void wm_xr_session_draw_data_update ( const wmXrSessionState state,
const XrSessionSettings settings,
const GHOST_XrDrawViewInfo *  draw_view,
wmXrDrawData draw_data 
)

◆ WM_xr_session_exists()

bool WM_xr_session_exists ( const wmXrData xr)

Check if the XR-Session was triggered. If an error happened while trying to start a session, this returns false too.

Definition at line 99 of file wm_xr_session.c.

References wmXrRuntimeData::context, wmXrSessionState::is_started, wmXrData::runtime, and wmXrRuntimeData::session_state.

Referenced by WM_xr_session_is_ready(), and wm_xr_session_toggle().

◆ wm_xr_session_exit_cb()

static void wm_xr_session_exit_cb ( void *  customdata)
static

◆ wm_xr_session_gpu_binding_context_create()

void* wm_xr_session_gpu_binding_context_create ( void  )

◆ wm_xr_session_gpu_binding_context_destroy()

void wm_xr_session_gpu_binding_context_destroy ( GHOST_ContextHandle   UNUSEDcontext)

◆ WM_xr_session_is_ready()

bool WM_xr_session_is_ready ( const wmXrData xr)

◆ wm_xr_session_root_window_or_fallback_get()

static wmWindow* wm_xr_session_root_window_or_fallback_get ( const wmWindowManager wm,
const wmXrRuntimeData runtime_data 
)
static

◆ wm_xr_session_scene_and_evaluated_depsgraph_get()

static void wm_xr_session_scene_and_evaluated_depsgraph_get ( Main bmain,
const wmWindowManager wm,
Scene **  r_scene,
Depsgraph **  r_depsgraph 
)
static

Get the scene and depsgraph shown in the VR session's root window (the window the session was started from) if still available. If it's not available, use some fallback window.

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.

Definition at line 187 of file wm_xr_session.c.

References BKE_scene_get_depsgraph(), BKE_scene_graph_evaluated_ensure(), BLI_assert, depsgraph, wmXrData::runtime, scene, WM_window_get_active_scene(), WM_window_get_active_view_layer(), wm_xr_session_root_window_or_fallback_get(), and wmWindowManager::xr.

Referenced by wm_xr_session_surface_draw().

◆ WM_xr_session_state_handle_get()

wmXrSessionState* WM_xr_session_state_handle_get ( const wmXrData xr)

Definition at line 333 of file wm_xr_session.c.

References NULL, wmXrData::runtime, and wmXrRuntimeData::session_state.

◆ wm_xr_session_state_to_event()

static wmXrSessionStateEvent wm_xr_session_state_to_event ( const wmXrSessionState state,
const XrSessionSettings settings 
)
static

◆ wm_xr_session_state_update()

void wm_xr_session_state_update ( const XrSessionSettings settings,
const wmXrDrawData draw_data,
const GHOST_XrDrawViewInfo *  draw_view,
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.

Definition at line 293 of file wm_xr_session.c.

References wmXrDrawData::base_pose, XrSessionSettings::base_pose_object, XrSessionSettings::base_pose_type, copy_qt_qt(), copy_v3_v3(), DEFAULT_SENSOR_WIDTH, wmXrDrawData::eye_position_ofs, XrSessionSettings::flag, fov_to_focallength(), mul_qt_qtqt(), state, wm_xr_pose_to_viewmat(), and XR_SESSION_USE_POSITION_TRACKING.

Referenced by wm_xr_draw_view().

◆ WM_xr_session_state_viewer_pose_location_get()

bool WM_xr_session_state_viewer_pose_location_get ( const wmXrData xr,
float  r_location[3] 
)

◆ WM_xr_session_state_viewer_pose_matrix_info_get()

bool WM_xr_session_state_viewer_pose_matrix_info_get ( const wmXrData xr,
float  r_viewmat[4][4],
float r_focal_len 
)

◆ WM_xr_session_state_viewer_pose_rotation_get()

bool WM_xr_session_state_viewer_pose_rotation_get ( const wmXrData xr,
float  r_rotation[4] 
)

◆ wm_xr_session_surface_create()

static wmSurface* wm_xr_session_surface_create ( void  )
static

◆ wm_xr_session_surface_draw()

static void wm_xr_session_surface_draw ( bContext C)
static

Call Ghost-XR to draw a frame.

Draw callback for the XR-session surface. It's expected to be called on each main loop iteration and tells Ghost-XR to submit a new frame by drawing its views. Note that for drawing each view, wm_xr_draw_view() will be called through Ghost-XR (see GHOST_XrDrawViewFunc()).

Definition at line 391 of file wm_xr_session.c.

References C, wmXrRuntimeData::context, CTX_data_main(), CTX_wm_manager(), wmSurface::customdata, depsgraph, g_xr_surface, GPU_offscreen_unbind(), wmXrSurfaceData::offscreen, wmXrData::runtime, scene, wm_xr_session_draw_data_populate(), wm_xr_session_scene_and_evaluated_depsgraph_get(), and wmWindowManager::xr.

Referenced by wm_xr_session_surface_create().

◆ wm_xr_session_surface_free_data()

static void wm_xr_session_surface_free_data ( wmSurface surface)
static

◆ wm_xr_session_surface_offscreen_ensure()

bool wm_xr_session_surface_offscreen_ensure ( wmXrSurfaceData surface_data,
const GHOST_XrDrawViewInfo *  draw_view 
)

◆ wm_xr_session_toggle()

void wm_xr_session_toggle ( wmWindowManager wm,
wmWindow session_root_win,
wmXrSessionExitFn  session_exit_fn 
)

Variable Documentation

◆ g_xr_surface

wmSurface* g_xr_surface = NULL
static

◆ LOG

CLG_LogRef LOG = {"wm.xr"}
static

Definition at line 48 of file wm_xr_session.c.

Referenced by wm_xr_session_surface_offscreen_ensure().