Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/openxr/src/loader/loader_init_data.hpp
21320 views
1
// Copyright (c) 2017-2025 The Khronos Group Inc.
2
// Copyright (c) 2017-2019 Valve Corporation
3
// Copyright (c) 2017-2019 LunarG, Inc.
4
//
5
// SPDX-License-Identifier: Apache-2.0 OR MIT
6
//
7
// Initial Author: Mark Young <[email protected]>
8
//
9
10
#pragma once
11
12
#include <xr_dependencies.h>
13
#include <openxr/openxr_platform.h>
14
15
#if defined(XR_USE_PLATFORM_ANDROID)
16
#include <json/value.h>
17
#include <android/asset_manager_jni.h>
18
#include "android_utilities.h"
19
20
// Warning: For system software use only. Enabling this define in regular applications
21
// will make it incompatible with many conformant runtimes.
22
#if !defined(XR_DISABLE_LOADER_INIT_ANDROID_LOADER_KHR)
23
/*!
24
* Later code will assume that if this is defined then a platform-specific struct
25
* must be provided for successful initialization.
26
*/
27
#define XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT
28
#endif // !defined(XR_DISABLE_LOADER_INIT_ANDROID_LOADER_KHR)
29
#endif // defined(XR_USE_PLATFORM_ANDROID)
30
31
/*!
32
* Stores a copy of the data passed to the xrInitializeLoaderKHR function in a singleton.
33
*/
34
class LoaderInitData {
35
public:
36
/*!
37
* Singleton accessor.
38
*/
39
static LoaderInitData& instance() {
40
static LoaderInitData obj;
41
return obj;
42
}
43
44
#if defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
45
/*!
46
* Type alias for the platform-specific structure type.
47
*/
48
using PlatformStructType = XrLoaderInitInfoAndroidKHR;
49
50
/*!
51
* Native library path.
52
*/
53
std::string _android_native_library_path;
54
/*!
55
* Android asset manager.
56
*/
57
AAssetManager* _android_asset_manager;
58
#endif
59
60
/*!
61
* Get our copy of the data, casted to pass to the runtime's matching method.
62
* Only some platforms have platform-specific loader init info.
63
*/
64
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
65
const XrLoaderInitInfoBaseHeaderKHR* getPlatformParam() {
66
#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
67
return reinterpret_cast<const XrLoaderInitInfoBaseHeaderKHR*>(&_platform_info);
68
#else
69
return nullptr;
70
#endif
71
}
72
73
#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
74
75
/*!
76
* Get the data via its real structure type.
77
*/
78
const PlatformStructType& getPlatformData() const { return _platform_info; }
79
#endif
80
81
/*!
82
* Has this been correctly initialized?
83
*/
84
bool initialized() const noexcept { return _initialized; }
85
86
/*!
87
* Initialize loader data - called by InitializeLoaderInitData() and thus ultimately by the loader's xrInitializeLoaderKHR
88
* implementation.
89
*/
90
XrResult initialize(const XrLoaderInitInfoBaseHeaderKHR* info);
91
92
private:
93
//! Private constructor, forces use of singleton accessor.
94
LoaderInitData() = default;
95
96
/*!
97
* Initialize non-platform-specific loader data.
98
*/
99
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
100
XrResult initializeProperties(const XrLoaderInitInfoBaseHeaderKHR* info);
101
102
/*!
103
* Initialize platform-specific loader data - called ultimately by the loader's xrInitializeLoaderKHR
104
* implementation. Each platform that needs this extension will provide an implementation of this.
105
*/
106
XrResult initializePlatform(const XrLoaderInitInfoBaseHeaderKHR* info);
107
108
#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
109
/*!
110
* Only some platforms have platform-specific loader init info.
111
*/
112
PlatformStructType _platform_info;
113
#endif // defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
114
115
//! Flag for indicating whether _platform_info is valid.
116
bool _initialized = false;
117
};
118
119
//! Initialize loader init data, where required.
120
XrResult InitializeLoaderInitData(const XrLoaderInitInfoBaseHeaderKHR* loaderInitInfo);
121
122
#if defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
123
XrResult GetPlatformRuntimeVirtualManifest(Json::Value& out_manifest);
124
std::string GetAndroidNativeLibraryDir();
125
void* GetAndroidAssetManager();
126
#endif // defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)
127
128