Blender V5.3
GHOST_XrContext.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <algorithm>
12#include <cassert>
13#include <sstream>
14#include <string>
15#include <string_view>
16
17#include "BLI_string.hh"
18#include "BLI_string_ref.hh"
19#include "BLI_vector.hh"
20
21#include "GHOST_Types.hh"
22#include "GHOST_XrException.hh"
23#include "GHOST_XrSession.hh"
24#include "GHOST_Xr_intern.hh"
25
26#include "GHOST_XrContext.hh"
27
29 XrInstance instance = XR_NULL_HANDLE;
30 XrInstanceProperties instance_properties = {};
31
32 std::vector<XrExtensionProperties> extensions;
33 std::vector<XrApiLayerProperties> layers;
34
35 static PFN_xrCreateDebugUtilsMessengerEXT s_xrCreateDebugUtilsMessengerEXT_fn;
36 static PFN_xrDestroyDebugUtilsMessengerEXT s_xrDestroyDebugUtilsMessengerEXT_fn;
37
38 XrDebugUtilsMessengerEXT debug_messenger = XR_NULL_HANDLE;
39};
40
41PFN_xrCreateDebugUtilsMessengerEXT OpenXRInstanceData::s_xrCreateDebugUtilsMessengerEXT_fn =
42 nullptr;
43PFN_xrDestroyDebugUtilsMessengerEXT OpenXRInstanceData::s_xrDestroyDebugUtilsMessengerEXT_fn =
44 nullptr;
45
46GHOST_XrErrorHandlerFn GHOST_XrContext::s_error_handler = nullptr;
47void *GHOST_XrContext::s_error_handler_customdata = nullptr;
48
49/* -------------------------------------------------------------------- */
52
53GHOST_XrContext::GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
54 : oxr_(std::make_unique<OpenXRInstanceData>()),
55 debug_(create_info->context_flag & GHOST_kXrContextDebug),
56 debug_time_(create_info->context_flag & GHOST_kXrContextDebugTime)
57{
58}
59
61{
62 /* Destroy session data first. Otherwise xrDestroyInstance will implicitly do it, before the
63 * session had a chance to do so explicitly. */
64 session_ = nullptr;
65
66 if (oxr_->debug_messenger != XR_NULL_HANDLE) {
67 assert(oxr_->s_xrDestroyDebugUtilsMessengerEXT_fn != nullptr);
68 oxr_->s_xrDestroyDebugUtilsMessengerEXT_fn(oxr_->debug_messenger);
69 }
70 if (oxr_->instance != XR_NULL_HANDLE) {
71 CHECK_XR_ASSERT(xrDestroyInstance(oxr_->instance));
72 oxr_->instance = XR_NULL_HANDLE;
73 }
74}
75
76void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
77{
78 initApiLayers();
79 initExtensions();
80 printSDKVersion();
81 printAvailableAPILayersAndExtensionsInfo();
82
83 /* Multiple graphics binding extensions can be enabled, but only one will actually be used
84 * (determined later on). */
85 const std::vector<GHOST_TXrGraphicsBinding> graphics_binding_types =
86 determineGraphicsBindingTypesToEnable(create_info);
87
88 assert(oxr_->instance == XR_NULL_HANDLE);
89 createOpenXRInstance(graphics_binding_types);
90 storeInstanceProperties();
91
92 /* Multiple bindings may be enabled. Now that we know the runtime in use, settle for one. */
93 gpu_binding_type_ = determineGraphicsBindingTypeToUse(graphics_binding_types, create_info);
94
95 printInstanceInfo();
96 initDebugMessenger();
97}
98
99void GHOST_XrContext::createOpenXRInstance(
100 const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types)
101{
102 XrInstanceCreateInfo create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
103
104 blender::STRNCPY(create_info.applicationInfo.applicationName, "Blender");
105
106 /* Explicitly target OpenXR API version 1.0. Note that the API_VERSION_1_0 macro is only
107 * available in 1.1+ SDKs. For 1.0 SDKs, target the current SDK version. */
108#ifdef XR_API_VERSION_1_0
109 create_info.applicationInfo.apiVersion = XR_API_VERSION_1_0;
110#else
111 create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
112#endif
113
114 getAPILayersToEnable(enabled_layers_);
115 getExtensionsToEnable(graphics_binding_types, enabled_extensions_);
116 create_info.enabledApiLayerCount = enabled_layers_.size();
117 create_info.enabledApiLayerNames = enabled_layers_.data();
118 create_info.enabledExtensionCount = enabled_extensions_.size();
119 create_info.enabledExtensionNames = enabled_extensions_.data();
120 printExtensionsAndAPILayersToEnable();
121
122 CHECK_XR(xrCreateInstance(&create_info, &oxr_->instance),
123 "Failed to create OpenXR instance, check active OpenXR runtime.");
124}
125
126void GHOST_XrContext::storeInstanceProperties()
127{
128 const std::map<std::string, GHOST_TXrOpenXRRuntimeID> runtime_map = {
129 {"Monado(XRT) by Collabora et al", OPENXR_RUNTIME_MONADO},
130 {"Oculus", OPENXR_RUNTIME_OCULUS},
131 {"SteamVR/OpenXR", OPENXR_RUNTIME_STEAMVR},
132 {"Windows Mixed Reality Runtime", OPENXR_RUNTIME_WMR},
133 {"Varjo OpenXR Runtime", OPENXR_RUNTIME_VARJO}};
134 decltype(runtime_map)::const_iterator runtime_map_iter;
135
136 oxr_->instance_properties.type = XR_TYPE_INSTANCE_PROPERTIES;
137 CHECK_XR(xrGetInstanceProperties(oxr_->instance, &oxr_->instance_properties),
138 "Failed to get OpenXR runtime information. Do you have an active runtime set up?");
139
140 runtime_map_iter = runtime_map.find(oxr_->instance_properties.runtimeName);
141 if (runtime_map_iter != runtime_map.end()) {
142 runtime_id_ = runtime_map_iter->second;
143 }
144}
145 /* Create, Initialize and Destruct */
147
148/* -------------------------------------------------------------------- */
151
152void GHOST_XrContext::printSDKVersion()
153{
154 const XrVersion sdk_version = XR_CURRENT_API_VERSION;
155
157 "OpenXR SDK Version: %u.%u.%u",
158 XR_VERSION_MAJOR(sdk_version),
159 XR_VERSION_MINOR(sdk_version),
160 XR_VERSION_PATCH(sdk_version));
161}
162
163void GHOST_XrContext::printInstanceInfo()
164{
165 assert(oxr_->instance != XR_NULL_HANDLE);
166
168 "Connected to OpenXR runtime: %s (Version %u.%u.%u)",
169 oxr_->instance_properties.runtimeName,
170 XR_VERSION_MAJOR(oxr_->instance_properties.runtimeVersion),
171 XR_VERSION_MINOR(oxr_->instance_properties.runtimeVersion),
172 XR_VERSION_PATCH(oxr_->instance_properties.runtimeVersion));
173}
174
175void GHOST_XrContext::printAvailableAPILayersAndExtensionsInfo()
176{
177 CLOG_INFO(LOG_GHOST_XR, "Available OpenXR API-layers/extensions:");
178 for (const XrApiLayerProperties &layer_info : oxr_->layers) {
179 CLOG_INFO(LOG_GHOST_XR, "Layer: %s", layer_info.layerName);
180 }
181 for (const XrExtensionProperties &ext_info : oxr_->extensions) {
182 CLOG_INFO(LOG_GHOST_XR, "Extension: %s", ext_info.extensionName);
183 }
184}
185
186void GHOST_XrContext::printExtensionsAndAPILayersToEnable()
187{
188 for (const char *layer_name : enabled_layers_) {
189 CLOG_INFO(LOG_GHOST_XR, "Enabling OpenXR API-Layer: %s", layer_name);
190 }
191 for (const char *ext_name : enabled_extensions_) {
192 CLOG_INFO(LOG_GHOST_XR, "Enabling OpenXR Extension: %s", ext_name);
193 }
194}
195
196static XrBool32 debug_messenger_func(XrDebugUtilsMessageSeverityFlagsEXT /*messageSeverity*/,
197 XrDebugUtilsMessageTypeFlagsEXT /*messageTypes*/,
198 const XrDebugUtilsMessengerCallbackDataEXT *callbackData,
199 void * /*user_data*/)
200{
201 CLOG_INFO(LOG_GHOST_XR, "OpenXR Debug Message: %s", callbackData->message);
202 return XR_FALSE; /* OpenXR spec suggests always returning false. */
203}
204
205void GHOST_XrContext::initDebugMessenger()
206{
207 XrDebugUtilsMessengerCreateInfoEXT create_info = {XR_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
208
209 /* Extension functions need to be obtained through xrGetInstanceProcAddr(). */
210 if (XR_FAILED(xrGetInstanceProcAddr(
211 oxr_->instance,
212 "xrCreateDebugUtilsMessengerEXT",
213 (PFN_xrVoidFunction *)&oxr_->s_xrCreateDebugUtilsMessengerEXT_fn)) ||
214 XR_FAILED(xrGetInstanceProcAddr(
215 oxr_->instance,
216 "xrDestroyDebugUtilsMessengerEXT",
217 (PFN_xrVoidFunction *)&oxr_->s_xrDestroyDebugUtilsMessengerEXT_fn)))
218 {
219 oxr_->s_xrCreateDebugUtilsMessengerEXT_fn = nullptr;
220 oxr_->s_xrDestroyDebugUtilsMessengerEXT_fn = nullptr;
221
223 "Could not use XR_EXT_debug_utils to enable debug prints. Not a fatal error, "
224 "continuing without the messenger.");
225 return;
226 }
227
228 create_info.messageSeverities = XR_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
229 XR_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
230 XR_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
231 XR_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
232 create_info.messageTypes = XR_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
233 XR_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT |
234 XR_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT;
235 create_info.userCallback = debug_messenger_func;
236
237 if (XR_FAILED(oxr_->s_xrCreateDebugUtilsMessengerEXT_fn(
238 oxr_->instance, &create_info, &oxr_->debug_messenger)))
239 {
241 "Failed to create OpenXR debug messenger. Not a fatal error, continuing without the "
242 "messenger.");
243 return;
244 }
245}
246 /* Debug Printing */
248
249/* -------------------------------------------------------------------- */
252
254{
255 GHOST_XrError error;
256
257 error.user_message = exception->msg_.data();
258 error.customdata = s_error_handler_customdata;
259
260 XrInstance instance = getInstance();
261 if (instance) {
262 char error_string_buf[XR_MAX_RESULT_STRING_SIZE];
263 xrResultToString(instance, static_cast<XrResult>(exception->result_), error_string_buf);
265 "%s (OpenXR error: %s, value: %i)",
266 error.user_message,
267 error_string_buf,
268 exception->result_);
269 }
270 else {
272 LOG_GHOST_XR, "%s (OpenXR error value: %i)", error.user_message, exception->result_);
273 }
274
275 /* Potentially destroys GHOST_XrContext */
276 s_error_handler(&error);
277}
278
279void GHOST_XrContext::setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata)
280{
281 s_error_handler = handler_fn;
282 s_error_handler_customdata = customdata;
283}
284 /* Error handling */
286
287/* -------------------------------------------------------------------- */
290
294void GHOST_XrContext::initExtensionsEx(std::vector<XrExtensionProperties> &extensions,
295 const char *layer_name)
296{
297 uint32_t extension_count = 0;
298
299 /* Get count for array creation/init first. */
300 CHECK_XR(xrEnumerateInstanceExtensionProperties(layer_name, 0, &extension_count, nullptr),
301 "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
302
303 if (extension_count == 0) {
304 /* Extensions are optional, can successfully exit. */
305 return;
306 }
307
308 for (uint32_t i = 0; i < extension_count; i++) {
309 XrExtensionProperties ext = {XR_TYPE_EXTENSION_PROPERTIES};
310 extensions.push_back(ext);
311 }
312
313 /* Actually get the extensions. */
314 CHECK_XR(xrEnumerateInstanceExtensionProperties(
315 layer_name, extension_count, &extension_count, extensions.data()),
316 "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
317}
318
319void GHOST_XrContext::initExtensions()
320{
321 initExtensionsEx(oxr_->extensions, nullptr);
322}
323
324void GHOST_XrContext::initApiLayers()
325{
326 uint32_t layer_count = 0;
327
328 /* Get count for array creation/init first. */
329 CHECK_XR(xrEnumerateApiLayerProperties(0, &layer_count, nullptr),
330 "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
331
332 if (layer_count == 0) {
333 /* Layers are optional, can safely exit. */
334 return;
335 }
336
337 oxr_->layers = std::vector<XrApiLayerProperties>(layer_count);
338 for (XrApiLayerProperties &layer : oxr_->layers) {
339 layer.type = XR_TYPE_API_LAYER_PROPERTIES;
340 }
341
342 /* Actually get the layers. */
343 CHECK_XR(xrEnumerateApiLayerProperties(layer_count, &layer_count, oxr_->layers.data()),
344 "Failed to query OpenXR runtime information. Do you have an active runtime set up?");
345 for (const XrApiLayerProperties &layer : oxr_->layers) {
346 /* Each layer may have own extensions. */
347 initExtensionsEx(oxr_->extensions, layer.layerName);
348 }
349}
350
351static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> &layers_info,
352 const std::string &layer_name)
353{
354 for (const XrApiLayerProperties &layer_info : layers_info) {
355 if (layer_info.layerName == layer_name) {
356 return true;
357 }
358 }
359
360 return false;
361}
362
364 const std::vector<XrExtensionProperties> &extensions_info,
365 const std::string_view &extension_name)
366{
367 for (const XrExtensionProperties &ext_info : extensions_info) {
368 if (ext_info.extensionName == extension_name) {
369 return true;
370 }
371 }
372
373 return false;
374}
375
379void GHOST_XrContext::getAPILayersToEnable(std::vector<const char *> &r_ext_names)
380{
381 static std::vector<std::string> try_layers;
382
383 try_layers.clear();
384
385 if (isDebugMode()) {
386 try_layers.push_back("XR_APILAYER_LUNARG_core_validation");
387 }
388
389 r_ext_names.reserve(try_layers.size());
390
391 for (const std::string &layer : try_layers) {
392 if (openxr_layer_is_available(oxr_->layers, layer)) {
393 r_ext_names.push_back(layer.data());
394 }
395 }
396}
397
403 GHOST_TXrGraphicsBinding binding)
404{
406
407 switch (binding) {
408 case GHOST_kXrGraphicsOpenGL:
409#ifdef WITH_OPENGL_BACKEND
410 extension_names.append(XR_KHR_OPENGL_ENABLE_EXTENSION_NAME);
411#endif
412 break;
413
414 case GHOST_kXrGraphicsVulkan:
415#ifdef WITH_VULKAN_BACKEND
416 extension_names.append(XR_KHR_VULKAN_ENABLE_EXTENSION_NAME);
417 extension_names.append(XR_KHR_VULKAN_ENABLE2_EXTENSION_NAME);
418#endif
419 break;
420
421 case GHOST_kXrGraphicsMetal:
422#ifdef WITH_METAL_BACKEND
423 extension_names.append(XR_KHR_METAL_ENABLE_EXTENSION_NAME);
424#endif
425 break;
426
427#ifdef WIN32
428# ifdef WITH_OPENGL_BACKEND
429 case GHOST_kXrGraphicsOpenGLD3D11:
430# endif
431# ifdef WITH_VULKAN_BACKEND
432 case GHOST_kXrGraphicsVulkanD3D11:
433# endif
434 extension_names.append(XR_KHR_D3D11_ENABLE_EXTENSION_NAME);
435 break;
436#endif
437 case GHOST_kXrGraphicsUnknown:
438 assert(!"Could not identify graphics binding to choose.");
439 break;
440 }
441
442 return extension_names;
443}
444
448void GHOST_XrContext::getExtensionsToEnable(
449 const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
450 std::vector<const char *> &r_ext_names)
451{
452 std::vector<std::string_view> try_ext;
453
454 /* Try enabling debug extension. */
455 if (isDebugMode()) {
456 try_ext.push_back(XR_EXT_DEBUG_UTILS_EXTENSION_NAME);
457 }
458
459 /* Interaction profile extensions. */
460 try_ext.push_back(XR_EXT_HP_MIXED_REALITY_CONTROLLER_EXTENSION_NAME);
461 try_ext.push_back(XR_HTC_VIVE_COSMOS_CONTROLLER_INTERACTION_EXTENSION_NAME);
462#ifdef XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME
463 try_ext.push_back(XR_HTC_VIVE_FOCUS3_CONTROLLER_INTERACTION_EXTENSION_NAME);
464#endif
465 try_ext.push_back(XR_HTCX_VIVE_TRACKER_INTERACTION_EXTENSION_NAME);
466 try_ext.push_back(XR_HUAWEI_CONTROLLER_INTERACTION_EXTENSION_NAME);
467
468 /* Controller model extension. */
469 try_ext.push_back(XR_MSFT_CONTROLLER_MODEL_EXTENSION_NAME);
470
471 /* Varjo quad view extension. */
472 try_ext.push_back(XR_VARJO_QUAD_VIEWS_EXTENSION_NAME);
473
474 /* Varjo foveated extension. */
475 try_ext.push_back(XR_VARJO_FOVEATED_RENDERING_EXTENSION_NAME);
476
477 /* Meta/Facebook passthrough extension. */
478 try_ext.push_back(XR_FB_PASSTHROUGH_EXTENSION_NAME);
479
480 /* Multi-vendor local floor extension. */
481 try_ext.push_back(XR_EXT_LOCAL_FLOOR_EXTENSION_NAME);
482
483 r_ext_names.reserve(try_ext.size() + graphics_binding_types.size());
484
485 /* Add graphics binding extensions (may be multiple ones, we'll settle for one to use later, once
486 * we have more info about the runtime). */
487 for (GHOST_TXrGraphicsBinding type : graphics_binding_types) {
488 blender::Vector<blender::StringRefNull> extension_names = openxr_ext_names_from_wm_gpu_binding(
489 type);
490 if (extension_names.size() == 1) {
491 r_ext_names.push_back(extension_names.first().c_str());
492 }
493 else {
494 for (blender::StringRefNull extension_name : extension_names) {
495 try_ext.push_back(extension_name);
496 }
497 }
498 }
499
500#if defined(WITH_GHOST_X11)
501 if (openxr_extension_is_available(oxr_->extensions, XR_MNDX_EGL_ENABLE_EXTENSION_NAME)) {
502 /* Use EGL if that backend is available. */
503 r_ext_names.push_back(XR_MNDX_EGL_ENABLE_EXTENSION_NAME);
504 }
505#endif
506
507 for (const std::string_view &ext : try_ext) {
508 if (openxr_extension_is_available(oxr_->extensions, ext)) {
509 r_ext_names.push_back(ext.data());
510 }
511 }
512}
513
518std::vector<GHOST_TXrGraphicsBinding> GHOST_XrContext::determineGraphicsBindingTypesToEnable(
519 const GHOST_XrContextCreateInfo *create_info)
520{
521 std::vector<GHOST_TXrGraphicsBinding> result;
522 assert(create_info->gpu_binding_candidates != nullptr);
523 assert(create_info->gpu_binding_candidates_count > 0);
524
525 for (uint32_t i = 0; i < create_info->gpu_binding_candidates_count; i++) {
526 assert(create_info->gpu_binding_candidates[i] != GHOST_kXrGraphicsUnknown);
527 blender::Vector<blender::StringRefNull> extension_names = openxr_ext_names_from_wm_gpu_binding(
528 create_info->gpu_binding_candidates[i]);
529 /* Vulkan has 2 extensions if any of these are available we should select the binding. */
530 for (blender::StringRefNull extension_name : extension_names) {
531 if (openxr_extension_is_available(oxr_->extensions, extension_name)) {
532 result.push_back(create_info->gpu_binding_candidates[i]);
533 break;
534 }
535 }
536 }
537
538 if (result.empty()) {
539 throw GHOST_XrException("No supported graphics binding found.");
540 }
541
542 return result;
543}
544
545GHOST_TXrGraphicsBinding GHOST_XrContext::determineGraphicsBindingTypeToUse(
546 const std::vector<GHOST_TXrGraphicsBinding> &enabled_types,
547 const GHOST_XrContextCreateInfo *create_info)
548{
549 /* Return the first working type. */
550 for (GHOST_TXrGraphicsBinding type : enabled_types) {
551#ifdef WIN32
552 /* The SteamVR OpenGL backend currently fails for NVIDIA GPU's. Disable it and allow falling
553 * back to the DirectX one. */
554 if ((runtime_id_ == OPENXR_RUNTIME_STEAMVR) && (type == GHOST_kXrGraphicsOpenGL) &&
555 ((create_info->context_flag & GHOST_kXrContextGpuNVIDIA) != 0))
556 {
557 continue;
558 }
559#else
560 ((void)create_info);
561#endif
562
563 assert(type != GHOST_kXrGraphicsUnknown);
564 return type;
565 }
566
567 throw GHOST_XrException("Failed to determine a graphics binding to use.");
568}
569 /* OpenXR API-Layers and Extensions */
571
572/* -------------------------------------------------------------------- */
577
578void GHOST_XrContext::startSession(const GHOST_XrSessionBeginInfo *begin_info)
579{
580 custom_funcs_.session_create_fn = begin_info->create_fn;
581 custom_funcs_.session_exit_fn = begin_info->exit_fn;
582 custom_funcs_.session_exit_customdata = begin_info->exit_customdata;
583
584 if (session_ == nullptr) {
585 session_ = std::make_unique<GHOST_XrSession>(*this);
586 }
587 session_->start();
588}
589
591{
592 if (session_) {
593 if (session_->isRunning()) {
594 session_->requestEnd();
595 }
596 else {
597 session_ = nullptr;
598 }
599 }
600}
601
603{
604 return session_ && session_->isRunning();
605}
606
607void GHOST_XrContext::drawSessionViews(void *draw_customdata)
608{
609 session_->draw(draw_customdata);
610}
611
615void GHOST_XrContext::handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle)
616{
617 if (session_ && session_->handleStateChangeEvent(lifecycle) == GHOST_XrSession::SESSION_DESTROY)
618 {
619 session_ = nullptr;
620 }
621}
622 /* Session Management */
624
625/* -------------------------------------------------------------------- */
630
632{
633 return session_.get();
634}
635
637{
638 return session_.get();
639}
640
641void GHOST_XrContext::setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn,
642 GHOST_XrGraphicsContextUnbindFn unbind_fn)
643{
644 if (session_) {
645 session_->unbindGraphicsContext();
646 }
647 custom_funcs_.gpu_ctx_bind_fn = bind_fn;
648 custom_funcs_.gpu_ctx_unbind_fn = unbind_fn;
649}
650
651void GHOST_XrContext::setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn)
652{
653 custom_funcs_.draw_view_fn = draw_view_fn;
654}
655
657 GHOST_XrPassthroughEnabledFn passthrough_enabled_fn)
658{
659 custom_funcs_.passthrough_enabled_fn = passthrough_enabled_fn;
660}
661
663 GHOST_XrDisablePassthroughFn disable_passthrough_fn)
664{
665 custom_funcs_.disable_passthrough_fn = disable_passthrough_fn;
666}
667
669{
670 /* Must only be called after the session was started */
671 assert(session_);
672 return session_->needsUpsideDownDrawing();
673}
674 /* Public Accessors and Mutators */
676
677/* -------------------------------------------------------------------- */
680
682{
683 return runtime_id_;
684}
685
687{
688 return custom_funcs_;
689}
690
691GHOST_TXrGraphicsBinding GHOST_XrContext::getGraphicsBindingType() const
692{
693 return gpu_binding_type_;
694}
695
697{
698 return oxr_->instance;
699}
700
702{
703 return debug_;
704}
705
707{
708 return debug_time_;
709}
710
711bool GHOST_XrContext::isExtensionEnabled(const char *ext) const
712{
713 bool contains = std::find(enabled_extensions_.begin(), enabled_extensions_.end(), ext) !=
714 enabled_extensions_.end();
715 return contains;
716}
717 /* Ghost Internal Accessors and Mutators */
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
static XrBool32 debug_messenger_func(XrDebugUtilsMessageSeverityFlagsEXT, XrDebugUtilsMessageTypeFlagsEXT, const XrDebugUtilsMessengerCallbackDataEXT *callbackData, void *)
static blender::Vector< blender::StringRefNull > openxr_ext_names_from_wm_gpu_binding(GHOST_TXrGraphicsBinding binding)
Return a list of extension names where at least one must be available to use a graphics binding.
static bool openxr_layer_is_available(const std::vector< XrApiLayerProperties > &layers_info, const std::string &layer_name)
static bool openxr_extension_is_available(const std::vector< XrExtensionProperties > &extensions_info, const std::string_view &extension_name)
GHOST_TXrOpenXRRuntimeID
@ OPENXR_RUNTIME_MONADO
@ OPENXR_RUNTIME_OCULUS
@ OPENXR_RUNTIME_STEAMVR
@ OPENXR_RUNTIME_WMR
@ OPENXR_RUNTIME_VARJO
CLG_LogRef * LOG_GHOST_XR
#define CHECK_XR_ASSERT(call)
#define CHECK_XR(call, error_msg)
XrInstance getInstance() const
void setDisablePassthroughFunc(GHOST_XrDisablePassthroughFn disable_passthrough_fn) override
GHOST_TXrOpenXRRuntimeID getOpenXRRuntimeID() const
void setGraphicsContextBindFuncs(GHOST_XrGraphicsContextBindFn bind_fn, GHOST_XrGraphicsContextUnbindFn unbind_fn) override
GHOST_TXrGraphicsBinding getGraphicsBindingType() const
void drawSessionViews(void *draw_customdata) override
void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle)
const GHOST_XrCustomFuncs & getCustomFuncs() const
void dispatchErrorMessage(const class GHOST_XrException *exception) const override
bool isDebugTimeMode() const
void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override
bool needsUpsideDownDrawing() const override
bool isSessionRunning() const override
void startSession(const GHOST_XrSessionBeginInfo *begin_info) override
void endSession() override
bool isExtensionEnabled(const char *ext) const
GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
bool isDebugMode() const
void initialize(const GHOST_XrContextCreateInfo *create_info)
static void setErrorHandler(GHOST_XrErrorHandlerFn handler_fn, void *customdata)
void setPassthroughEnabledFunc(GHOST_XrPassthroughEnabledFn passthrough_enabled_fn) override
GHOST_XrSession * getSession() override
GHOST_XrException(const char *msg, int result=0)
int64_t size() const
void append(const T &value)
const T & first() const
#define assert(assertion)
#define layer
char * STRNCPY(char(&dst)[N], const char *src)
unsigned int uint32_t
Definition BKE_text.h:81
XrDebugUtilsMessengerEXT debug_messenger
XrInstanceProperties instance_properties
std::vector< XrExtensionProperties > extensions
static PFN_xrDestroyDebugUtilsMessengerEXT s_xrDestroyDebugUtilsMessengerEXT_fn
std::vector< XrApiLayerProperties > layers
static PFN_xrCreateDebugUtilsMessengerEXT s_xrCreateDebugUtilsMessengerEXT_fn