-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime.cpp
More file actions
2372 lines (2046 loc) · 93.9 KB
/
Copy pathruntime.cpp
File metadata and controls
2372 lines (2046 loc) · 93.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Include platform headers
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <unknwn.h>
#include <windows.h>
#elif defined(__APPLE__)
#include <TargetConditionals.h>
#endif
// Include Vulkan headers before OpenXR if Vulkan support is enabled
#ifdef OX_OPENGL
#ifdef _WIN32
#include <GL/gl.h>
#elif defined(__APPLE__)
#include <OpenGL/gl.h>
#define GL_SILENCE_DEPRECATION
#else
#include <GL/gl.h>
#include <GL/glx.h>
#include <X11/Xlib.h>
#endif
#define XR_USE_GRAPHICS_API_OPENGL
#endif
#ifdef OX_VULKAN
#include <vulkan/vulkan.h>
#define XR_USE_GRAPHICS_API_VULKAN
#endif
#ifdef OX_METAL
#ifdef __APPLE__
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <Metal/Metal.h>
#define XR_USE_GRAPHICS_API_METAL
#define XR_KHR_metal_enable 1
#endif
#endif
#endif
#include <openxr/openxr.h>
#include <openxr/openxr_loader_negotiation.h>
#include <openxr/openxr_platform.h>
#include <dylib.hpp>
#ifdef OX_OPENGL
#include "graphics_opengl.hpp"
#endif // OX_OPENGL
#ifdef OX_VULKAN
#include "graphics_vulkan.hpp"
#endif // OX_VULKAN
#ifdef OX_METAL
#include "graphics_metal.hpp"
#endif // OX_METAL
#include <ox_driver.h>
#include <spdlog/spdlog.h>
#include <whereami.h>
#include <algorithm>
#include <array>
#include <atomic>
#include <cassert>
#include <chrono>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <memory>
#include <mutex>
#include <queue>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <vector>
#ifdef OX_OPENGL
namespace opengl = ox::client::opengl;
#endif
#ifdef OX_VULKAN
namespace vulkan = ox::client::vulkan;
#endif
#ifdef OX_METAL
namespace metal = ox::client::metal;
#endif
namespace fs = std::filesystem;
// Conditional defines for static builds (disable export attributes)
// Note: XRAPI_ATTR and XRAPI_CALL are already defined by OpenXR headers
#ifdef OX_BUILD_STATIC
#ifndef XRAPI_ATTR
#define XRAPI_ATTR
#endif
#ifndef XRAPI_CALL
#define XRAPI_CALL
#endif
#endif
// Graphics API enumeration
enum class GraphicsAPI { OpenGL, Vulkan, Metal };
// Export macro for Windows DLL
#ifdef _WIN32
#define RUNTIME_EXPORT __declspec(dllexport)
#else
#define RUNTIME_EXPORT __attribute__((visibility("default")))
#endif
// Forward declaration so LoadConfiguredDriver can call it
extern "C" RUNTIME_EXPORT int ox_set_driver(const OxDriver* driver);
namespace {
constexpr uint32_t kStereoViewCount = 2;
constexpr uint32_t kMaxInteractionProfiles = 8;
constexpr uint32_t kRuntimeMaxLayerCount = XR_MIN_COMPOSITION_LAYERS_SUPPORTED;
constexpr uint32_t kRuntimeMaxSwapchainSampleCount = 1;
constexpr uint32_t kRuntimeRecommendedSwapchainSampleCount = 1;
constexpr XrDuration kDefaultDisplayPeriodNanos = 11111111;
constexpr char kDefaultInteractionProfile[] = "/interaction_profiles/khr/simple_controller";
struct SessionGraphicsBinding {
void* bindingData = nullptr;
GraphicsAPI graphicsAPI = GraphicsAPI::OpenGL;
};
struct SessionData {
XrInstance instance = XR_NULL_HANDLE;
XrSessionState state = XR_SESSION_STATE_IDLE;
XrTime last_predicted_display_time = 0;
XrDuration predicted_display_period = kDefaultDisplayPeriodNanos;
XrTime last_end_frame_time = 0;
SessionGraphicsBinding graphics;
bool has_graphics_binding = false;
};
struct QueuedSessionStateEvent {
XrSession session = XR_NULL_HANDLE;
XrSessionState state = XR_SESSION_STATE_UNKNOWN;
XrTime timestamp = 0;
};
struct DeviceSnapshot {
std::array<OxDeviceState, OX_MAX_DEVICES> devices{};
uint32_t count = 0;
};
std::unique_ptr<OxDriver> g_driver;
std::unique_ptr<dylib::library> g_driver_library;
std::queue<QueuedSessionStateEvent> g_session_events;
std::mutex g_instance_mutex;
std::atomic<uint64_t> g_next_handle{1};
int64_t NowNanos() {
const auto now = std::chrono::steady_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
}
template <typename HandleType>
HandleType AllocateRuntimeHandle() {
return reinterpret_cast<HandleType>(g_next_handle.fetch_add(1, std::memory_order_relaxed));
}
fs::path ModuleDirectory() {
const int module_path_length = wai_getModulePath(nullptr, 0, nullptr);
if (module_path_length <= 0) {
return fs::current_path();
}
std::string module_path(static_cast<size_t>(module_path_length) + 1, '\0');
if (wai_getModulePath(module_path.data(), module_path_length, nullptr) != module_path_length) {
return fs::current_path();
}
module_path[static_cast<size_t>(module_path_length)] = '\0';
return fs::path(module_path.c_str()).parent_path();
}
std::string GetEnvVar(const char* name) {
#ifdef _WIN32
char* value = nullptr;
size_t size = 0;
if (_dupenv_s(&value, &size, name) == 0 && value) {
std::string result(value);
std::free(value);
return result;
}
if (value) std::free(value);
return {};
#else
const char* value = std::getenv(name);
return value ? value : "";
#endif
}
bool LoadConfiguredDriver() {
const std::string env_driver = GetEnvVar("OX_RUNTIME_DRIVER");
fs::path lib_path;
if (!env_driver.empty()) {
lib_path = fs::absolute(env_driver);
} else if (GetEnvVar("OX_USE_SIMULATOR") == "1") {
lib_path = ModuleDirectory() / "drivers/simulator/ox_driver";
} else {
lib_path = ModuleDirectory() / "ox_ipc_client";
}
const std::string lib_str = lib_path.string();
try {
auto lib = std::make_unique<dylib::library>(lib_str, dylib::decorations::os_default());
auto ox_driver_register = lib->get_function<int(OxDriver*)>("ox_driver_register");
OxDriver driver{};
if (!ox_driver_register || !ox_driver_register(&driver)) {
spdlog::error("Driver registration failed for {}", lib_str);
return false;
}
if (!ox_set_driver(&driver)) {
return false;
}
g_driver_library = std::move(lib);
spdlog::info("Loaded driver: {}", lib_str);
return true;
} catch (const std::exception& e) {
spdlog::error("Failed to load driver {}: {}", lib_str, e.what());
return false;
}
}
void UnloadDriver() {
if (g_driver && g_driver->shutdown) g_driver->shutdown();
g_driver.reset();
g_driver_library.reset();
}
XrDuration ComputeDisplayPeriodNanos(float refresh_rate_hz) {
if (refresh_rate_hz <= 0.0f) {
return kDefaultDisplayPeriodNanos;
}
return static_cast<XrDuration>(1000000000.0 / static_cast<double>(refresh_rate_hz));
}
std::vector<std::string> GetInteractionProfiles() {
std::vector<std::string> profiles;
if (g_driver && g_driver->get_interaction_profiles) {
const char* raw_profiles[kMaxInteractionProfiles] = {};
const uint32_t profile_count = std::min<uint32_t>(
g_driver->get_interaction_profiles(raw_profiles, kMaxInteractionProfiles), kMaxInteractionProfiles);
for (uint32_t index = 0; index < profile_count; ++index) {
if (raw_profiles[index] && raw_profiles[index][0] != '\0') {
profiles.emplace_back(raw_profiles[index]);
}
}
}
if (profiles.empty()) {
profiles.emplace_back(kDefaultInteractionProfile);
}
return profiles;
}
DeviceSnapshot CaptureDevices(int64_t predicted_time) {
DeviceSnapshot snapshot;
if (!g_driver || !g_driver->update_devices) {
return snapshot;
}
g_driver->update_devices(predicted_time, snapshot.devices.data(), &snapshot.count);
snapshot.count = std::min<uint32_t>(snapshot.count, OX_MAX_DEVICES);
return snapshot;
}
void QueueSessionStateChangeLocked(XrSession session, XrSessionState state) {
g_session_events.push({session, state, NowNanos()});
}
void NotifyDriverSessionState(XrSessionState state) {
if (g_driver && g_driver->on_session_state_changed) {
g_driver->on_session_state_changed(state);
}
}
} // namespace
extern "C" {
RUNTIME_EXPORT int ox_set_driver(const OxDriver* driver) {
if (!driver) {
UnloadDriver();
return 1;
}
if (!driver->initialize || !driver->is_device_connected || !driver->get_system_properties || !driver->update_view) {
spdlog::error("Driver missing required callbacks");
return 0;
}
if (!driver->initialize()) {
spdlog::error("Driver initialize() failed");
return 0;
}
UnloadDriver();
g_driver = std::make_unique<OxDriver>(*driver);
spdlog::info("Installed runtime driver");
return 1;
}
}
// Swapchain image data
struct SwapchainData {
std::vector<uint32_t> glTextureIds; // OpenGL texture IDs
#ifdef OX_VULKAN
std::vector<VkImage> vkImages; // Vulkan images
std::vector<VkDeviceMemory> vkImageMemory; // Vulkan image memory
VkDevice vkDevice = VK_NULL_HANDLE;
VkPhysicalDevice vkPhysicalDevice = VK_NULL_HANDLE;
VkQueue vkQueue = VK_NULL_HANDLE;
VkCommandPool vkCommandPool = VK_NULL_HANDLE;
#endif
#ifdef OX_METAL
std::vector<void*> metalTextures; // Metal textures (id<MTLTexture> as opaque pointers)
void* metalCommandQueue = nullptr; // Metal command queue (id<MTLCommandQueue> as opaque pointer)
#endif
uint32_t width;
uint32_t height;
int64_t format;
GraphicsAPI graphicsAPI; // Track which graphics API this swapchain uses
};
// Action space metadata
struct ActionSpaceData {
XrAction action;
XrPath subaction_path;
};
// Reference space metadata
struct ReferenceSpaceData {
XrReferenceSpaceType type;
XrPosef pose_in_reference_space;
};
// Action metadata
struct ActionData {
XrActionType type;
XrActionSet action_set;
std::string name;
std::vector<XrPath> subaction_paths;
};
// Path tracking - bidirectional mapping between paths and strings
// Action binding metadata - maps action to its bindings
struct ActionBinding {
XrPath binding_path; // The full binding path (e.g., /user/hand/left/input/trigger/value)
XrPath subaction_path; // Which hand (left/right) or XR_NULL_PATH for no subaction
std::vector<XrPath> profiles; // List of profiles that use this binding
};
static std::unordered_map<XrInstance, bool> g_instances;
static std::unordered_map<XrSession, SessionData> g_sessions;
static std::unordered_map<XrSpace, XrSession> g_spaces;
static std::unordered_map<XrSwapchain, SwapchainData> g_swapchains;
static std::array<std::vector<std::byte>, 2> g_submit_buffers;
static std::unordered_map<XrSpace, ActionSpaceData> g_action_spaces;
static std::unordered_map<XrSpace, ReferenceSpaceData> g_reference_spaces;
static std::unordered_map<XrAction, ActionData> g_actions;
static std::unordered_map<XrPath, std::string> g_path_to_string;
static std::unordered_map<std::string, XrPath> g_string_to_path;
static std::unordered_map<XrAction, std::vector<ActionBinding>> g_action_bindings;
static XrPath g_current_interaction_profile = XR_NULL_PATH;
static std::vector<std::string> g_suggested_profiles;
namespace {
std::string PathToStringLocked(XrPath path) {
auto it = g_path_to_string.find(path);
return it != g_path_to_string.end() ? it->second : std::string();
}
XrPath ExtractSubactionPathForBindingLocked(const ActionData& action, const std::string& binding_path) {
const size_t input_pos = binding_path.find("/input/");
const std::string binding_user_path =
input_pos != std::string::npos ? binding_path.substr(0, input_pos) : binding_path;
for (XrPath candidate : action.subaction_paths) {
const std::string candidate_path = PathToStringLocked(candidate);
if (!candidate_path.empty() && candidate_path == binding_user_path) {
return candidate;
}
}
return XR_NULL_PATH;
}
} // namespace
// Safe string copy helper - modern C++17+ replacement for strncpy
inline void safe_copy_string(char* dest, size_t dest_size, std::string_view src) {
if (dest_size == 0) return;
const size_t copy_len = std::min(src.size(), dest_size - 1);
std::copy_n(src.data(), copy_len, dest);
dest[copy_len] = '\0';
}
// Helper: Extract user path from full binding path
// "/user/hand/left/input/trigger/value" -> "/user/hand/left"
inline std::string ExtractUserPath(const std::string& full_path) {
size_t input_pos = full_path.find("/input/");
if (input_pos != std::string::npos) {
return full_path.substr(0, input_pos);
}
return full_path;
}
// Helper: Extract component path from full binding path
// "/user/hand/left/input/trigger/value" -> "/input/trigger/value"
inline std::string ExtractComponentPath(const std::string& full_path) {
size_t input_pos = full_path.find("/input/");
if (input_pos != std::string::npos) {
return full_path.substr(input_pos);
}
// For output paths like /output/haptic
size_t output_pos = full_path.find("/output/");
if (output_pos != std::string::npos) {
return full_path.substr(output_pos);
}
return full_path;
}
// Helper: Get instance from session
inline XrResult GetInstanceFromSession(XrSession session, XrInstance* instance) {
auto session_it = g_sessions.find(session);
if (session_it == g_sessions.end()) {
return XR_ERROR_HANDLE_INVALID;
}
*instance = session_it->second.instance;
return XR_SUCCESS;
}
// Helper: Check if a binding matches the profile and subaction
inline bool IsBindingMatch(const ActionBinding& binding, XrPath subaction_path) {
// Check if subaction path matches (or no subaction requested)
if (subaction_path != XR_NULL_PATH && binding.subaction_path != XR_NULL_PATH &&
binding.subaction_path != subaction_path) {
return false;
}
// Check if binding belongs to current interaction profile
if (g_current_interaction_profile != XR_NULL_PATH) {
bool profile_match = false;
for (const auto& profile : binding.profiles) {
if (profile == g_current_interaction_profile) {
profile_match = true;
break;
}
}
if (!profile_match) {
return false;
}
}
return true;
}
// Helper: Template for getting action state
template <typename StateType>
inline XrResult GetActionState(XrSession session, const XrActionStateGetInfo* getInfo, StateType* state) {
if (!state || !getInfo) {
return XR_ERROR_VALIDATION_FAILURE;
}
assert(g_driver);
if (!g_driver) {
return XR_ERROR_RUNTIME_FAILURE;
}
std::vector<ActionBinding> bindings;
XrTime predicted_time = 0;
{
std::lock_guard<std::mutex> lock(g_instance_mutex);
auto session_it = g_sessions.find(session);
if (session_it == g_sessions.end()) {
return XR_ERROR_HANDLE_INVALID;
}
auto action_it = g_actions.find(getInfo->action);
if (action_it == g_actions.end()) {
return XR_SUCCESS;
}
auto bindings_it = g_action_bindings.find(getInfo->action);
if (bindings_it == g_action_bindings.end()) {
return XR_SUCCESS;
}
bindings = bindings_it->second;
predicted_time = session_it->second.last_predicted_display_time;
}
auto resolved_value = state->currentState;
bool has_active_source = false;
for (const auto& binding : bindings) {
if (!IsBindingMatch(binding, getInfo->subactionPath)) {
continue;
}
std::string path_str;
{
std::lock_guard<std::mutex> lock(g_instance_mutex);
path_str = PathToStringLocked(binding.binding_path);
}
if (path_str.empty()) {
continue;
}
std::string user_path = ExtractUserPath(path_str);
std::string component_path = ExtractComponentPath(path_str);
auto value = state->currentState;
bool available = false;
if constexpr (std::is_same_v<StateType, XrActionStateBoolean>) {
if (!g_driver->get_input_state_bool) {
continue;
}
XrBool32 boolean_value = value ? XR_TRUE : XR_FALSE;
available = g_driver->get_input_state_bool(predicted_time, user_path.c_str(), component_path.c_str(),
&boolean_value) == XR_SUCCESS;
value = boolean_value ? XR_TRUE : XR_FALSE;
} else if constexpr (std::is_same_v<StateType, XrActionStateFloat>) {
if (g_driver->get_input_state_float) {
available = g_driver->get_input_state_float(predicted_time, user_path.c_str(), component_path.c_str(),
&value) == XR_SUCCESS;
}
if (!available && g_driver->get_input_state_bool) {
XrBool32 boolean_value = XR_FALSE;
available = g_driver->get_input_state_bool(predicted_time, user_path.c_str(), component_path.c_str(),
&boolean_value) == XR_SUCCESS;
if (available) {
value = boolean_value ? 1.0f : 0.0f;
}
}
} else if constexpr (std::is_same_v<StateType, XrActionStateVector2f>) {
if (!g_driver->get_input_state_vector2f) {
continue;
}
XrVector2f vector_value{value.x, value.y};
available = g_driver->get_input_state_vector2f(predicted_time, user_path.c_str(), component_path.c_str(),
&vector_value) == XR_SUCCESS;
value = {vector_value.x, vector_value.y};
} else {
return XR_ERROR_VALIDATION_FAILURE;
}
if (available) {
if (!has_active_source) {
resolved_value = value;
has_active_source = true;
continue;
}
if constexpr (std::is_same_v<StateType, XrActionStateBoolean>) {
resolved_value = (resolved_value != XR_FALSE || value != XR_FALSE) ? XR_TRUE : XR_FALSE;
} else if constexpr (std::is_same_v<StateType, XrActionStateFloat>) {
if (std::fabs(value) > std::fabs(resolved_value)) {
resolved_value = value;
}
} else if constexpr (std::is_same_v<StateType, XrActionStateVector2f>) {
const float candidate_length_sq = value.x * value.x + value.y * value.y;
const float resolved_length_sq =
resolved_value.x * resolved_value.x + resolved_value.y * resolved_value.y;
if (candidate_length_sq > resolved_length_sq) {
resolved_value = value;
}
}
}
}
if (has_active_source) {
state->currentState = resolved_value;
state->isActive = XR_TRUE;
}
return XR_SUCCESS;
}
// Forward declare all functions
XRAPI_ATTR XrResult XRAPI_CALL xrGetInstanceProcAddr(XrInstance instance, const char* name,
PFN_xrVoidFunction* function);
// Function map for xrGetInstanceProcAddr
static std::unordered_map<std::string, PFN_xrVoidFunction> g_clientFunctionMap;
static void InitializeFunctionMap();
// xrEnumerateApiLayerProperties
XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateApiLayerProperties(uint32_t propertyCapacityInput,
uint32_t* propertyCountOutput,
XrApiLayerProperties* properties) {
spdlog::debug("xrEnumerateApiLayerProperties called");
if (propertyCountOutput) {
*propertyCountOutput = 0;
}
return XR_SUCCESS;
}
// xrEnumerateInstanceExtensionProperties
XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateInstanceExtensionProperties(const char* layerName,
uint32_t propertyCapacityInput,
uint32_t* propertyCountOutput,
XrExtensionProperties* properties) {
spdlog::debug("xrEnumerateInstanceExtensionProperties called");
std::vector<const char*> extensions;
#ifdef OX_OPENGL
extensions.push_back("XR_KHR_opengl_enable");
#endif
#ifdef OX_VULKAN
extensions.push_back("XR_KHR_vulkan_enable");
extensions.push_back("XR_KHR_vulkan_enable2");
#endif
#ifdef OX_METAL
extensions.push_back("XR_KHR_metal_enable");
#endif
extensions.push_back("XR_HTCX_vive_tracker_interaction");
const uint32_t extensionCount = static_cast<uint32_t>(extensions.size());
if (propertyCountOutput) {
*propertyCountOutput = extensionCount;
}
if (propertyCapacityInput == 0) {
return XR_SUCCESS;
}
if (!properties) {
spdlog::error("xrEnumerateInstanceExtensionProperties: Null properties");
return XR_ERROR_VALIDATION_FAILURE;
}
uint32_t count = propertyCapacityInput < extensionCount ? propertyCapacityInput : extensionCount;
for (uint32_t i = 0; i < count; i++) {
properties[i].type = XR_TYPE_EXTENSION_PROPERTIES;
properties[i].next = nullptr;
properties[i].extensionVersion = 1;
safe_copy_string(properties[i].extensionName, XR_MAX_EXTENSION_NAME_SIZE, extensions[i]);
}
return XR_SUCCESS;
}
// xrCreateInstance
XRAPI_ATTR XrResult XRAPI_CALL xrCreateInstance(const XrInstanceCreateInfo* createInfo, XrInstance* instance) {
spdlog::debug("xrCreateInstance called");
if (!createInfo || !instance) {
spdlog::error("xrCreateInstance: Invalid parameters");
return XR_ERROR_VALIDATION_FAILURE;
}
// Initialize function map
if (g_clientFunctionMap.empty()) {
InitializeFunctionMap();
}
std::lock_guard<std::mutex> lock(g_instance_mutex);
if (!g_driver) {
spdlog::error("Failed to load runtime driver");
return XR_ERROR_RUNTIME_FAILURE;
}
XrInstance newInstance = AllocateRuntimeHandle<XrInstance>();
g_instances[newInstance] = true;
*instance = newInstance;
spdlog::info("OpenXR instance created successfully");
return XR_SUCCESS;
}
// xrDestroyInstance
XRAPI_ATTR XrResult XRAPI_CALL xrDestroyInstance(XrInstance instance) {
spdlog::debug("xrDestroyInstance called");
std::lock_guard<std::mutex> lock(g_instance_mutex);
auto it = g_instances.find(instance);
if (it == g_instances.end()) {
spdlog::error("xrDestroyInstance: Invalid instance handle");
return XR_ERROR_HANDLE_INVALID;
}
g_instances.erase(it);
if (g_instances.empty()) {
while (!g_session_events.empty()) {
g_session_events.pop();
}
}
spdlog::info("OpenXR instance destroyed");
return XR_SUCCESS;
}
// xrGetInstanceProperties
XRAPI_ATTR XrResult XRAPI_CALL xrGetInstanceProperties(XrInstance instance, XrInstanceProperties* instanceProperties) {
spdlog::debug("xrGetInstanceProperties called");
if (!instanceProperties) {
spdlog::error("xrGetInstanceProperties: Null instanceProperties");
return XR_ERROR_VALIDATION_FAILURE;
}
std::lock_guard<std::mutex> lock(g_instance_mutex);
if (g_instances.find(instance) == g_instances.end()) {
spdlog::error("xrGetInstanceProperties: Invalid instance handle");
return XR_ERROR_HANDLE_INVALID;
}
#if defined(OX_VERSION_MAJOR) && defined(OX_VERSION_MINOR) && defined(OX_VERSION_PATCH)
instanceProperties->runtimeVersion = XR_MAKE_VERSION(OX_VERSION_MAJOR, OX_VERSION_MINOR, OX_VERSION_PATCH);
#else
instanceProperties->runtimeVersion = XR_MAKE_VERSION(0, 0, 0);
#endif
safe_copy_string(instanceProperties->runtimeName, XR_MAX_RUNTIME_NAME_SIZE, "ox-runtime");
return XR_SUCCESS;
}
// xrPollEvent - returns session state change events
XRAPI_ATTR XrResult XRAPI_CALL xrPollEvent(XrInstance instance, XrEventDataBuffer* eventData) {
spdlog::debug("xrPollEvent called");
if (!eventData) {
return XR_ERROR_VALIDATION_FAILURE;
}
std::lock_guard<std::mutex> lock(g_instance_mutex);
if (g_instances.find(instance) == g_instances.end()) {
return XR_ERROR_HANDLE_INVALID;
}
if (!g_session_events.empty()) {
const QueuedSessionStateEvent service_event = g_session_events.front();
g_session_events.pop();
XrEventDataSessionStateChanged* stateEvent = reinterpret_cast<XrEventDataSessionStateChanged*>(eventData);
stateEvent->type = XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED;
stateEvent->next = nullptr;
stateEvent->session = service_event.session;
stateEvent->time = service_event.timestamp;
stateEvent->state = service_event.state;
spdlog::info("Session state event queued by runtime");
return XR_SUCCESS;
}
return XR_EVENT_UNAVAILABLE;
}
// String conversion maps
static const std::unordered_map<XrResult, const char*> g_resultStrings = {
{XR_SUCCESS, "XR_SUCCESS"},
{XR_TIMEOUT_EXPIRED, "XR_TIMEOUT_EXPIRED"},
{XR_SESSION_LOSS_PENDING, "XR_SESSION_LOSS_PENDING"},
{XR_EVENT_UNAVAILABLE, "XR_EVENT_UNAVAILABLE"},
{XR_SPACE_BOUNDS_UNAVAILABLE, "XR_SPACE_BOUNDS_UNAVAILABLE"},
{XR_SESSION_NOT_FOCUSED, "XR_SESSION_NOT_FOCUSED"},
{XR_FRAME_DISCARDED, "XR_FRAME_DISCARDED"},
{XR_ERROR_VALIDATION_FAILURE, "XR_ERROR_VALIDATION_FAILURE"},
{XR_ERROR_RUNTIME_FAILURE, "XR_ERROR_RUNTIME_FAILURE"},
{XR_ERROR_OUT_OF_MEMORY, "XR_ERROR_OUT_OF_MEMORY"},
{XR_ERROR_API_VERSION_UNSUPPORTED, "XR_ERROR_API_VERSION_UNSUPPORTED"},
{XR_ERROR_INITIALIZATION_FAILED, "XR_ERROR_INITIALIZATION_FAILED"},
{XR_ERROR_FUNCTION_UNSUPPORTED, "XR_ERROR_FUNCTION_UNSUPPORTED"},
{XR_ERROR_FEATURE_UNSUPPORTED, "XR_ERROR_FEATURE_UNSUPPORTED"},
{XR_ERROR_EXTENSION_NOT_PRESENT, "XR_ERROR_EXTENSION_NOT_PRESENT"},
{XR_ERROR_LIMIT_REACHED, "XR_ERROR_LIMIT_REACHED"},
{XR_ERROR_SIZE_INSUFFICIENT, "XR_ERROR_SIZE_INSUFFICIENT"},
{XR_ERROR_HANDLE_INVALID, "XR_ERROR_HANDLE_INVALID"},
{XR_ERROR_INSTANCE_LOST, "XR_ERROR_INSTANCE_LOST"},
{XR_ERROR_SESSION_RUNNING, "XR_ERROR_SESSION_RUNNING"},
{XR_ERROR_SESSION_NOT_RUNNING, "XR_ERROR_SESSION_NOT_RUNNING"},
{XR_ERROR_SESSION_LOST, "XR_ERROR_SESSION_LOST"},
{XR_ERROR_SYSTEM_INVALID, "XR_ERROR_SYSTEM_INVALID"},
{XR_ERROR_PATH_INVALID, "XR_ERROR_PATH_INVALID"},
{XR_ERROR_PATH_COUNT_EXCEEDED, "XR_ERROR_PATH_COUNT_EXCEEDED"},
{XR_ERROR_PATH_FORMAT_INVALID, "XR_ERROR_PATH_FORMAT_INVALID"},
{XR_ERROR_PATH_UNSUPPORTED, "XR_ERROR_PATH_UNSUPPORTED"},
{XR_ERROR_LAYER_INVALID, "XR_ERROR_LAYER_INVALID"},
{XR_ERROR_LAYER_LIMIT_EXCEEDED, "XR_ERROR_LAYER_LIMIT_EXCEEDED"},
{XR_ERROR_SWAPCHAIN_RECT_INVALID, "XR_ERROR_SWAPCHAIN_RECT_INVALID"},
{XR_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED, "XR_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED"},
{XR_ERROR_ACTION_TYPE_MISMATCH, "XR_ERROR_ACTION_TYPE_MISMATCH"},
{XR_ERROR_SESSION_NOT_READY, "XR_ERROR_SESSION_NOT_READY"},
{XR_ERROR_SESSION_NOT_STOPPING, "XR_ERROR_SESSION_NOT_STOPPING"},
{XR_ERROR_TIME_INVALID, "XR_ERROR_TIME_INVALID"},
{XR_ERROR_REFERENCE_SPACE_UNSUPPORTED, "XR_ERROR_REFERENCE_SPACE_UNSUPPORTED"},
{XR_ERROR_FILE_ACCESS_ERROR, "XR_ERROR_FILE_ACCESS_ERROR"},
{XR_ERROR_FILE_CONTENTS_INVALID, "XR_ERROR_FILE_CONTENTS_INVALID"},
{XR_ERROR_FORM_FACTOR_UNSUPPORTED, "XR_ERROR_FORM_FACTOR_UNSUPPORTED"},
{XR_ERROR_FORM_FACTOR_UNAVAILABLE, "XR_ERROR_FORM_FACTOR_UNAVAILABLE"},
{XR_ERROR_API_LAYER_NOT_PRESENT, "XR_ERROR_API_LAYER_NOT_PRESENT"},
{XR_ERROR_CALL_ORDER_INVALID, "XR_ERROR_CALL_ORDER_INVALID"},
{XR_ERROR_GRAPHICS_DEVICE_INVALID, "XR_ERROR_GRAPHICS_DEVICE_INVALID"},
{XR_ERROR_POSE_INVALID, "XR_ERROR_POSE_INVALID"},
{XR_ERROR_INDEX_OUT_OF_RANGE, "XR_ERROR_INDEX_OUT_OF_RANGE"},
{XR_ERROR_VIEW_CONFIGURATION_TYPE_UNSUPPORTED, "XR_ERROR_VIEW_CONFIGURATION_TYPE_UNSUPPORTED"},
{XR_ERROR_ENVIRONMENT_BLEND_MODE_UNSUPPORTED, "XR_ERROR_ENVIRONMENT_BLEND_MODE_UNSUPPORTED"},
{XR_ERROR_NAME_DUPLICATED, "XR_ERROR_NAME_DUPLICATED"},
{XR_ERROR_NAME_INVALID, "XR_ERROR_NAME_INVALID"},
{XR_ERROR_ACTIONSET_NOT_ATTACHED, "XR_ERROR_ACTIONSET_NOT_ATTACHED"},
{XR_ERROR_ACTIONSETS_ALREADY_ATTACHED, "XR_ERROR_ACTIONSETS_ALREADY_ATTACHED"},
{XR_ERROR_LOCALIZED_NAME_DUPLICATED, "XR_ERROR_LOCALIZED_NAME_DUPLICATED"},
{XR_ERROR_LOCALIZED_NAME_INVALID, "XR_ERROR_LOCALIZED_NAME_INVALID"},
{XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING, "XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING"},
};
static const std::unordered_map<XrStructureType, const char*> g_structureTypeStrings = {
{XR_TYPE_UNKNOWN, "XR_TYPE_UNKNOWN"},
{XR_TYPE_API_LAYER_PROPERTIES, "XR_TYPE_API_LAYER_PROPERTIES"},
{XR_TYPE_EXTENSION_PROPERTIES, "XR_TYPE_EXTENSION_PROPERTIES"},
{XR_TYPE_INSTANCE_CREATE_INFO, "XR_TYPE_INSTANCE_CREATE_INFO"},
{XR_TYPE_SYSTEM_GET_INFO, "XR_TYPE_SYSTEM_GET_INFO"},
{XR_TYPE_SYSTEM_PROPERTIES, "XR_TYPE_SYSTEM_PROPERTIES"},
{XR_TYPE_VIEW_LOCATE_INFO, "XR_TYPE_VIEW_LOCATE_INFO"},
{XR_TYPE_VIEW, "XR_TYPE_VIEW"},
{XR_TYPE_SESSION_CREATE_INFO, "XR_TYPE_SESSION_CREATE_INFO"},
{XR_TYPE_SWAPCHAIN_CREATE_INFO, "XR_TYPE_SWAPCHAIN_CREATE_INFO"},
{XR_TYPE_SESSION_BEGIN_INFO, "XR_TYPE_SESSION_BEGIN_INFO"},
{XR_TYPE_VIEW_STATE, "XR_TYPE_VIEW_STATE"},
{XR_TYPE_FRAME_END_INFO, "XR_TYPE_FRAME_END_INFO"},
{XR_TYPE_HAPTIC_VIBRATION, "XR_TYPE_HAPTIC_VIBRATION"},
{XR_TYPE_EVENT_DATA_BUFFER, "XR_TYPE_EVENT_DATA_BUFFER"},
{XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING, "XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING"},
{XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED, "XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED"},
{XR_TYPE_ACTION_STATE_BOOLEAN, "XR_TYPE_ACTION_STATE_BOOLEAN"},
{XR_TYPE_ACTION_STATE_FLOAT, "XR_TYPE_ACTION_STATE_FLOAT"},
{XR_TYPE_ACTION_STATE_VECTOR2F, "XR_TYPE_ACTION_STATE_VECTOR2F"},
{XR_TYPE_ACTION_STATE_POSE, "XR_TYPE_ACTION_STATE_POSE"},
{XR_TYPE_ACTION_SET_CREATE_INFO, "XR_TYPE_ACTION_SET_CREATE_INFO"},
{XR_TYPE_ACTION_CREATE_INFO, "XR_TYPE_ACTION_CREATE_INFO"},
{XR_TYPE_INSTANCE_PROPERTIES, "XR_TYPE_INSTANCE_PROPERTIES"},
{XR_TYPE_FRAME_WAIT_INFO, "XR_TYPE_FRAME_WAIT_INFO"},
{XR_TYPE_COMPOSITION_LAYER_PROJECTION, "XR_TYPE_COMPOSITION_LAYER_PROJECTION"},
{XR_TYPE_COMPOSITION_LAYER_QUAD, "XR_TYPE_COMPOSITION_LAYER_QUAD"},
{XR_TYPE_REFERENCE_SPACE_CREATE_INFO, "XR_TYPE_REFERENCE_SPACE_CREATE_INFO"},
{XR_TYPE_ACTION_SPACE_CREATE_INFO, "XR_TYPE_ACTION_SPACE_CREATE_INFO"},
{XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING, "XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING"},
{XR_TYPE_VIEW_CONFIGURATION_VIEW, "XR_TYPE_VIEW_CONFIGURATION_VIEW"},
{XR_TYPE_SPACE_LOCATION, "XR_TYPE_SPACE_LOCATION"},
{XR_TYPE_SPACE_VELOCITY, "XR_TYPE_SPACE_VELOCITY"},
{XR_TYPE_FRAME_STATE, "XR_TYPE_FRAME_STATE"},
{XR_TYPE_VIEW_CONFIGURATION_PROPERTIES, "XR_TYPE_VIEW_CONFIGURATION_PROPERTIES"},
{XR_TYPE_FRAME_BEGIN_INFO, "XR_TYPE_FRAME_BEGIN_INFO"},
{XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW, "XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW"},
{XR_TYPE_EVENT_DATA_EVENTS_LOST, "XR_TYPE_EVENT_DATA_EVENTS_LOST"},
{XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING, "XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING"},
{XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED, "XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED"},
{XR_TYPE_INTERACTION_PROFILE_STATE, "XR_TYPE_INTERACTION_PROFILE_STATE"},
{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, "XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO"},
{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO, "XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO"},
{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO, "XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO"},
{XR_TYPE_ACTION_STATE_GET_INFO, "XR_TYPE_ACTION_STATE_GET_INFO"},
{XR_TYPE_HAPTIC_ACTION_INFO, "XR_TYPE_HAPTIC_ACTION_INFO"},
{XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO, "XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO"},
{XR_TYPE_ACTIONS_SYNC_INFO, "XR_TYPE_ACTIONS_SYNC_INFO"},
{XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO, "XR_TYPE_BOUND_SOURCES_FOR_ACTION_ENUMERATE_INFO"},
{XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO, "XR_TYPE_INPUT_SOURCE_LOCALIZED_NAME_GET_INFO"},
{XR_TYPE_COMPOSITION_LAYER_CUBE_KHR, "XR_TYPE_COMPOSITION_LAYER_CUBE_KHR"},
{XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR, "XR_TYPE_COMPOSITION_LAYER_DEPTH_INFO_KHR"},
{XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR, "XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR"},
{XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR, "XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR"},
{XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR, "XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR"},
{XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR, "XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR"},
{XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR, "XR_TYPE_GRAPHICS_BINDING_OPENGL_XCB_KHR"},
{XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR, "XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR"},
{XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR, "XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR"},
{XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR, "XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR"},
{XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR, "XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR"},
{XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR, "XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR"},
{XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR, "XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR"},
};
// Rest of the runtime functions (simplified versions)
XRAPI_ATTR XrResult XRAPI_CALL xrResultToString(XrInstance instance, XrResult value,
char buffer[XR_MAX_RESULT_STRING_SIZE]) {
auto it = g_resultStrings.find(value);
if (it != g_resultStrings.end()) {
safe_copy_string(buffer, XR_MAX_RESULT_STRING_SIZE, it->second);
} else {
std::snprintf(buffer, XR_MAX_RESULT_STRING_SIZE, "XR_UNKNOWN_RESULT_%d", value);
}
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrStructureTypeToString(XrInstance instance, XrStructureType value,
char buffer[XR_MAX_STRUCTURE_NAME_SIZE]) {
auto it = g_structureTypeStrings.find(value);
if (it != g_structureTypeStrings.end()) {
safe_copy_string(buffer, XR_MAX_STRUCTURE_NAME_SIZE, it->second);
} else {
std::snprintf(buffer, XR_MAX_STRUCTURE_NAME_SIZE, "XR_UNKNOWN_STRUCTURE_TYPE_%d", value);
}
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrGetSystem(XrInstance instance, const XrSystemGetInfo* getInfo, XrSystemId* systemId) {
spdlog::debug("xrGetSystem called");
if (!getInfo || !systemId) {
return XR_ERROR_VALIDATION_FAILURE;
}
std::lock_guard<std::mutex> lock(g_instance_mutex);
if (g_instances.find(instance) == g_instances.end()) {
return XR_ERROR_HANDLE_INVALID;
}
*systemId = 1;
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrGetSystemProperties(XrInstance instance, XrSystemId systemId,
XrSystemProperties* properties) {
spdlog::debug("xrGetSystemProperties called");
if (!properties) {
return XR_ERROR_VALIDATION_FAILURE;
}
std::lock_guard<std::mutex> lock(g_instance_mutex);
if (g_instances.find(instance) == g_instances.end()) {
return XR_ERROR_HANDLE_INVALID;
}
XrSystemProperties system_props{XR_TYPE_SYSTEM_PROPERTIES};
g_driver->get_system_properties(&system_props);
properties->systemId = systemId;
safe_copy_string(properties->systemName, XR_MAX_SYSTEM_NAME_SIZE, system_props.systemName);
properties->vendorId = system_props.vendorId;
properties->graphicsProperties.maxSwapchainImageWidth = system_props.graphicsProperties.maxSwapchainImageWidth;
properties->graphicsProperties.maxSwapchainImageHeight = system_props.graphicsProperties.maxSwapchainImageHeight;
properties->graphicsProperties.maxLayerCount = kRuntimeMaxLayerCount;
properties->trackingProperties = system_props.trackingProperties;
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateViewConfigurations(XrInstance instance, XrSystemId systemId,
uint32_t viewConfigurationTypeCapacityInput,
uint32_t* viewConfigurationTypeCountOutput,
XrViewConfigurationType* viewConfigurationTypes) {
spdlog::debug("xrEnumerateViewConfigurations called");
const XrViewConfigurationType configs[] = {XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
if (viewConfigurationTypeCountOutput) {
*viewConfigurationTypeCountOutput = 1;
}
if (viewConfigurationTypeCapacityInput > 0 && viewConfigurationTypes) {
viewConfigurationTypes[0] = configs[0];
}
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrGetViewConfigurationProperties(
XrInstance instance, XrSystemId systemId, XrViewConfigurationType viewConfigurationType,
XrViewConfigurationProperties* configurationProperties) {
spdlog::debug("xrGetViewConfigurationProperties called");
if (!configurationProperties) {
return XR_ERROR_VALIDATION_FAILURE;
}
configurationProperties->viewConfigurationType = viewConfigurationType;
configurationProperties->fovMutable = XR_FALSE;
return XR_SUCCESS;
}
XRAPI_ATTR XrResult XRAPI_CALL xrEnumerateViewConfigurationViews(XrInstance instance, XrSystemId systemId,
XrViewConfigurationType viewConfigurationType,
uint32_t viewCapacityInput, uint32_t* viewCountOutput,
XrViewConfigurationView* views) {
spdlog::debug("xrEnumerateViewConfigurationViews called");
if (viewCountOutput) {
*viewCountOutput = 2; // Stereo
}
if (viewCapacityInput > 0 && views) {