Debian Codegraph @

modules/openxr/extensions/openxr_future_extension.h

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_future_extension.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 /*
34 The OpenXR future extension forms the basis of OpenXR's ability to
35 execute logic asynchronously.
36
37 Asynchronous functions will return a future object which can be
38 polled each frame to determine if the asynchronous function has
39 been completed.
40
41 If so the future can be used to obtain final return values.
42 The API call for this is often part of the extension that utilizes
43 the future.
44
45 We will be using Godot Callables to drive responses on futures.
46 */
47
48 #include "../util.h"
49 #include "core/object/ref_counted.h"
50 #include "openxr_extension_wrapper.h"
51
52 #include <openxr/openxr.h>
53
54 class OpenXRFutureExtension;
55
56 class OpenXRFutureResult : public RefCounted {
57 GDCLASS(OpenXRFutureResult, RefCounted);
58
59 friend class OpenXRFutureExtension;
60
61 protected:
62 static void _bind_methods();
63
64 void _mark_as_finished();
65 void _mark_as_cancelled();
66
67 public:
68 enum ResultStatus {
69 RESULT_RUNNING,
70 RESULT_FINISHED,
71 RESULT_CANCELLED,
72 };
73
74 ResultStatus get_status() const;
75 XrFutureEXT get_future() const;
76
77 void set_result_value(const Variant &p_result_value);
78 Variant get_result_value() const;
79
80 void cancel_future();
81
82 OpenXRFutureResult(XrFutureEXT p_future, const Callable &p_on_success);
83
84 private:
85 ResultStatus status = RESULT_RUNNING;
86 XrFutureEXT future;
87 Variant result_value;
88 Callable on_success_callback;
89
90 uint64_t _get_future() const;
91 };
92
93 VARIANT_ENUM_CAST(OpenXRFutureResult::ResultStatus);
94
95 class OpenXRFutureExtension : public OpenXRExtensionWrapper {
96 GDCLASS(OpenXRFutureExtension, OpenXRExtensionWrapper);
97
98 protected:
99 static void _bind_methods();
100
101 public:
102 static OpenXRFutureExtension *get_singleton();
103
104 OpenXRFutureExtension();
105 virtual ~OpenXRFutureExtension() override;
106
107 virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
108
109 virtual void on_instance_created(const XrInstance p_instance) override;
110 virtual void on_instance_destroyed() override;
111 virtual void on_session_destroyed() override;
112
113 virtual void on_process() override;
114
115 bool is_active() const;
116
117 Ref<OpenXRFutureResult> register_future(XrFutureEXT p_future, const Callable &p_on_success = Callable());
118 void cancel_future(XrFutureEXT p_future);
119
120 private:
121 static OpenXRFutureExtension *singleton;
122
123 bool future_ext = false;
124
125 HashMap<XrFutureEXT, Ref<OpenXRFutureResult>> futures;
126
127 // Make these accessible from GDExtension and/or GDScript
128 Ref<OpenXRFutureResult> _register_future(uint64_t p_future, const Callable &p_on_success = Callable());
129 void _cancel_future(uint64_t p_future);
130
131 // OpenXR API call wrappers
132
133 // Futures
134 EXT_PROTO_XRRESULT_FUNC3(xrPollFutureEXT, (XrInstance), instance, (const XrFuturePollInfoEXT *), poll_info, (XrFuturePollResultEXT *), poll_result);
135 EXT_PROTO_XRRESULT_FUNC2(xrCancelFutureEXT, (XrInstance), instance, (const XrFutureCancelInfoEXT *), cancel_info);
136 };