Skyscraper 2.0
XrDispatchTable.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
7#include <openxr/openxr.h>
8#include <openxr/openxr_platform.h>
9#include <openxr/openxr_reflection.h>
10
11#include "XrListFunctions.h"
12
22
23namespace xr {
24
26#define XR_DISPATCH_TABLE_MEMBER(name) PFN_##name name{nullptr};
27#define XR_DISPATCH_TABLE_MEMBER_VOID(name) PFN_xrVoidFunction name{nullptr};
28
31#undef XR_DISPATCH_TABLE_DEFINE_MEMBER
32#undef XR_DISPATCH_TABLE_MEMBER_VOID
33
34 void Initialize(XrInstance instance, PFN_xrGetInstanceProcAddr getInstanceProcAddr) {
35 auto getFunctionPointer = [&](const char* name) -> PFN_xrVoidFunction {
36 PFN_xrVoidFunction function = nullptr;
37 (void)getInstanceProcAddr(instance, name, &function);
38 return function;
39 };
40
41#define XR_DISPATCH_TABLE_GET_PROC_ADDRESS(name) name = reinterpret_cast<PFN_##name>(getFunctionPointer(#name));
42#define XR_DISPATCH_TABLE_SET_NO_OP(name)
43
46#undef XR_DISPATCH_TABLE_GET_PROC_ADDRESS
47#undef XR_DISPATCH_TABLE_SET_NO_OP
48 }
49 };
50} // namespace xr
51
52// Add all xrFunctions, including extension functions, to the global namespace so they can be used as C functions.
53#ifdef ENABLE_GLOBAL_XR_DISPATCH_TABLE
54// clang-format off
55 namespace xr {
56 inline DispatchTable g_dispatchTable{};
57 }
58
59 #define XR_DISPATCH_TABLE_GLOBAL(name) inline const PFN_##name& name = xr::g_dispatchTable. name;
60 #define XR_DISPATCH_TABLE_NO_OP(name)
61
62 #if !defined(XR_NO_PROTOTYPES)
63 // If openxr.h already defined function prototypes
64 // avoid adding duplicated PFN aliases in global namespace
65 #else
66 XR_LIST_FUNCTIONS_OPENXR_FUNCTIONS(XR_DISPATCH_TABLE_GLOBAL);
67 #endif
68
69 #if !defined(XR_NO_PROTOTYPES) && defined(XR_EXTENSION_PROTOTYPES)
70 // If openxr.h already defined extension function prototypes
71 // avoid adding duplicated PFN aliases in global namespace
72 #else
73 XR_LIST_FUNCTIONS_OPENXR_EXTENSIONS(XR_DISPATCH_TABLE_GLOBAL, XR_DISPATCH_TABLE_NO_OP);
74 #endif
75
76 #undef XR_DISPATCH_TABLE_GLOBAL
77 #undef XR_DISPATCH_TABLE_NO_OP
78// clang-format on
79#endif // ENABLE_GLOBAL_XR_DISPATCH_TABLE
80
#define XR_DISPATCH_TABLE_MEMBER(name)
#define XR_DISPATCH_TABLE_GET_PROC_ADDRESS(name)
#define XR_DISPATCH_TABLE_SET_NO_OP(name)
#define XR_DISPATCH_TABLE_MEMBER_VOID(name)
#define XR_LIST_FUNCTIONS_OPENXR_EXTENSIONS(_, __)
#define XR_LIST_FUNCTIONS_OPENXR_FUNCTIONS(_)
The xr::DispatchTable struct contains all available PFN pointers to xr functions including those in a...
XR_LIST_FUNCTIONS_OPENXR_FUNCTIONS(XR_DISPATCH_TABLE_MEMBER)
XR_LIST_FUNCTIONS_OPENXR_EXTENSIONS(XR_DISPATCH_TABLE_MEMBER, XR_DISPATCH_TABLE_MEMBER_VOID)
void Initialize(XrInstance instance, PFN_xrGetInstanceProcAddr getInstanceProcAddr)