Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/extensions/openxr_fb_foveation_extension.h
10278 views
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
class OpenXRFBFoveationExtension : public OpenXRExtensionWrapper {
44
GDCLASS(OpenXRFBFoveationExtension, OpenXRExtensionWrapper);
45
46
protected:
47
static void _bind_methods() {}
48
49
public:
50
static OpenXRFBFoveationExtension *get_singleton();
51
52
OpenXRFBFoveationExtension(const String &p_rendering_driver);
53
virtual ~OpenXRFBFoveationExtension() override;
54
55
virtual HashMap<String, bool *> get_requested_extensions() override;
56
57
virtual void on_instance_created(const XrInstance p_instance) override;
58
virtual void on_instance_destroyed() override;
59
60
virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) override;
61
62
virtual void on_main_swapchains_created() override;
63
64
bool is_enabled() const;
65
66
XrFoveationLevelFB get_foveation_level() const;
67
void set_foveation_level(XrFoveationLevelFB p_foveation_level);
68
69
XrFoveationDynamicFB get_foveation_dynamic() const;
70
void set_foveation_dynamic(XrFoveationDynamicFB p_foveation_dynamic);
71
72
private:
73
static OpenXRFBFoveationExtension *singleton;
74
75
// Setup
76
String rendering_driver;
77
bool fb_foveation_ext = false;
78
bool fb_foveation_configuration_ext = false;
79
bool fb_foveation_vulkan_ext = false;
80
81
// Configuration
82
XrFoveationLevelFB foveation_level = XR_FOVEATION_LEVEL_NONE_FB;
83
XrFoveationDynamicFB foveation_dynamic = XR_FOVEATION_DYNAMIC_DISABLED_FB;
84
85
static void _update_profile();
86
87
void update_profile() {
88
// If we're rendering on a separate thread, we may still be processing the last frame, don't communicate this till we're ready...
89
RenderingServer *rendering_server = RenderingServer::get_singleton();
90
ERR_FAIL_NULL(rendering_server);
91
92
rendering_server->call_on_render_thread(callable_mp_static(&OpenXRFBFoveationExtension::_update_profile));
93
}
94
95
// Enable foveation on this swapchain
96
XrSwapchainCreateInfoFoveationFB swapchain_create_info_foveation_fb;
97
OpenXRFBUpdateSwapchainExtension *swapchain_update_state_ext = nullptr;
98
99
// OpenXR API call wrappers
100
EXT_PROTO_XRRESULT_FUNC3(xrCreateFoveationProfileFB, (XrSession), session, (const XrFoveationProfileCreateInfoFB *), create_info, (XrFoveationProfileFB *), profile);
101
EXT_PROTO_XRRESULT_FUNC1(xrDestroyFoveationProfileFB, (XrFoveationProfileFB), profile);
102
};
103
104