Debian Codegraph @

modules/openxr/extensions/openxr_fb_foveation_extension.h

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_fb_foveation_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 // This extension implements the FB Foveation extension.
34 // This is an extension Meta added due to VRS being unavailable on Android.
35 // Other Android based devices are implementing this as well, see:
36 // https://github.khronos.org/OpenXR-Inventory/extension_support.html#XR_FB_foveation
37
38 #include "../openxr_api.h"
39 #include "../util.h"
40 #include "openxr_extension_wrapper.h"
41 #include "openxr_fb_update_swapchain_extension.h"
42
43 #include "../openxr_platform_inc.h"
44
45 class OpenXRFBFoveationExtension : public OpenXRExtensionWrapper {
46 GDCLASS(OpenXRFBFoveationExtension, OpenXRExtensionWrapper);
47
48 protected:
49 static void _bind_methods() {}
50
51 public:
52 static OpenXRFBFoveationExtension *get_singleton();
53
54 OpenXRFBFoveationExtension(const String &p_rendering_driver);
55 virtual ~OpenXRFBFoveationExtension() override;
56
57 virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
58
59 virtual void on_instance_created(const XrInstance p_instance) override;
60 virtual void on_instance_destroyed() override;
61
62 virtual void *set_system_properties_and_get_next_pointer(void *p_next_pointer) override;
63 virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) override;
64
65 virtual void on_main_swapchains_created() override;
66
67 bool is_enabled() const;
68
69 XrFoveationLevelFB get_foveation_level() const;
70 void set_foveation_level(XrFoveationLevelFB p_foveation_level);
71
72 XrFoveationDynamicFB get_foveation_dynamic() const;
73 void set_foveation_dynamic(XrFoveationDynamicFB p_foveation_dynamic);
74
75 bool is_foveation_eye_tracked_enabled() const;
76 void get_fragment_density_offsets(LocalVector<Vector2i> &r_offsets);
77
78 private:
79 static OpenXRFBFoveationExtension *singleton;
80
81 // Setup
82 String rendering_driver;
83 bool fb_foveation_ext = false;
84 bool fb_foveation_configuration_ext = false;
85 bool fb_foveation_vulkan_ext = false;
86 bool meta_foveation_eye_tracked_ext = false;
87 bool meta_vulkan_swapchain_create_info_ext = false;
88
89 // Configuration
90 XrFoveationLevelFB foveation_level = XR_FOVEATION_LEVEL_NONE_FB;
91 XrFoveationDynamicFB foveation_dynamic = XR_FOVEATION_DYNAMIC_DISABLED_FB;
92
93 void _update_profile_rt();
94
95 void update_profile() {
96 // If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
97 RenderingServer *rendering_server = RenderingServer::get_singleton();
98 ERR_FAIL_NULL(rendering_server);
99
100 rendering_server->call_on_render_thread(callable_mp(this, &OpenXRFBFoveationExtension::_update_profile_rt));
101 }
102
103 // Enable foveation on this swapchain
104 XrSwapchainCreateInfoFoveationFB swapchain_create_info_foveation_fb;
105 OpenXRFBUpdateSwapchainExtension *swapchain_update_state_ext = nullptr;
106
107 // Enable eye tracked foveation
108 XrSystemFoveationEyeTrackedPropertiesMETA meta_foveation_eye_tracked_properties;
109 XrFoveationEyeTrackedProfileCreateInfoMETA meta_foveation_eye_tracked_create_info;
110 #ifdef VULKAN_ENABLED
111 XrVulkanSwapchainCreateInfoMETA meta_vulkan_swapchain_create_info;
112 #endif
113
114 // OpenXR API call wrappers
115 EXT_PROTO_XRRESULT_FUNC3(xrCreateFoveationProfileFB, (XrSession), session, (const XrFoveationProfileCreateInfoFB *), create_info, (XrFoveationProfileFB *), profile);
116 EXT_PROTO_XRRESULT_FUNC1(xrDestroyFoveationProfileFB, (XrFoveationProfileFB), profile);
117 EXT_PROTO_XRRESULT_FUNC2(xrGetFoveationEyeTrackedStateMETA, (XrSession), session, (XrFoveationEyeTrackedStateMETA *), foveationState);
118 };