Debian Codegraph @

modules/openxr/extensions/openxr_visibility_mask_extension.h

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_visibility_mask_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 #include "../util.h"
34
35 #include "core/templates/vector.h"
36 #include "openxr_extension_wrapper.h"
37 #include "scene/resources/mesh.h"
38
39 // The OpenXR visibility mask extension provides a mesh for each eye that
40 // can be used as a mask to determine which part of our rendered result
41 // is actually visible to the user. Due to lens distortion the edges of
42 // the rendered image are never used in the final result output on the HMD.
43 //
44 // Blacking out this are of the render result can remove a fair amount of
45 // overhead in rendering part of the screen that is unused.
46 //
47 // https://registry.khronos.org/OpenXR/specs/1.0/html/xrspec.html#XR_KHR_visibility_mask
48
49 class OpenXRVisibilityMaskExtension : public OpenXRExtensionWrapper {
50 GDCLASS(OpenXRVisibilityMaskExtension, OpenXRExtensionWrapper);
51
52 protected:
53 static void _bind_methods() {}
54
55 public:
56 static OpenXRVisibilityMaskExtension *get_singleton();
57
58 OpenXRVisibilityMaskExtension();
59 virtual ~OpenXRVisibilityMaskExtension() override;
60
61 virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
62
63 virtual void on_instance_created(const XrInstance p_instance) override;
64
65 virtual void on_session_created(const XrSession p_instance) override;
66 virtual void on_session_destroyed() override;
67
68 virtual void on_pre_render() override;
69 virtual bool on_event_polled(const XrEventDataBuffer &event) override;
70
71 bool is_available();
72 RID get_mesh();
73
74 private:
75 static OpenXRVisibilityMaskExtension *singleton;
76
77 bool available = false;
78 bool is_dirty = false;
79
80 RID shader;
81 RID material;
82 RID mesh;
83
84 struct MeshData {
85 Vector<XrVector2f> vertices;
86 Vector<uint32_t> indices;
87 };
88
89 uint32_t mesh_count = 0;
90 MeshData mesh_data[4];
91
92 void _update_mesh_data(uint32_t p_view);
93 void _update_mesh();
94
95 // OpenXR API call wrappers
96 EXT_PROTO_XRRESULT_FUNC5(xrGetVisibilityMaskKHR, (XrSession), session, (XrViewConfigurationType), viewConfigurationType, (uint32_t), viewIndex, (XrVisibilityMaskTypeKHR), visibilityMaskType, (XrVisibilityMaskKHR *), visibilityMask);
97 };