Debian Codegraph @

modules/openxr/scene/openxr_composition_layer.h

raw symbols SCIP
1 /**************************************************************************/
2 /* openxr_composition_layer.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 <openxr/openxr.h>
34
35 #include "scene/3d/node_3d.h"
36
37 class JavaObject;
38 class MeshInstance3D;
39 class Mesh;
40 class OpenXRAPI;
41 class OpenXRCompositionLayerExtension;
42 class SubViewport;
43
44 class OpenXRCompositionLayer : public Node3D {
45 GDCLASS(OpenXRCompositionLayer, Node3D);
46
47 public:
48 // Must be identical to Filter enum definition in OpenXRCompositionLayerExtension.
49 enum Filter {
50 FILTER_NEAREST,
51 FILTER_LINEAR,
52 FILTER_CUBIC,
53 };
54
55 // Must be identical to MipmapMode enum definition in OpenXRCompositionLayerExtension.
56 enum MipmapMode {
57 MIPMAP_MODE_DISABLED,
58 MIPMAP_MODE_NEAREST,
59 MIPMAP_MODE_LINEAR,
60 };
61
62 // Must be identical to Wrap enum definition in OpenXRCompositionLayerExtension.
63 enum Wrap {
64 WRAP_CLAMP_TO_BORDER,
65 WRAP_CLAMP_TO_EDGE,
66 WRAP_REPEAT,
67 WRAP_MIRRORED_REPEAT,
68 WRAP_MIRROR_CLAMP_TO_EDGE,
69 };
70
71 // Must be identical to Swizzle enum definition in OpenXRCompositionLayerExtension.
72 enum Swizzle {
73 SWIZZLE_RED,
74 SWIZZLE_GREEN,
75 SWIZZLE_BLUE,
76 SWIZZLE_ALPHA,
77 SWIZZLE_ZERO,
78 SWIZZLE_ONE,
79 };
80
81 protected:
82 RID composition_layer;
83
84 private:
85 SubViewport *layer_viewport = nullptr;
86 bool use_android_surface = false;
87 Size2i android_surface_size = Size2i(1024, 1024);
88 bool enable_hole_punch = false;
89 bool alpha_blend = false;
90 int sort_order = 1;
91 bool protected_content = false;
92 MeshInstance3D *fallback = nullptr;
93 bool should_update_fallback_mesh = false;
94 bool openxr_session_running = false;
95 bool registered = false;
96 Dictionary extension_property_values;
97
98 Filter min_filter = FILTER_LINEAR;
99 Filter mag_filter = FILTER_LINEAR;
100 MipmapMode mipmap_mode = MIPMAP_MODE_LINEAR;
101 Wrap horizontal_wrap = WRAP_CLAMP_TO_BORDER;
102 Wrap vertical_wrap = WRAP_CLAMP_TO_BORDER;
103 Swizzle red_swizzle = SWIZZLE_RED;
104 Swizzle green_swizzle = SWIZZLE_GREEN;
105 Swizzle blue_swizzle = SWIZZLE_BLUE;
106 Swizzle alpha_swizzle = SWIZZLE_ALPHA;
107 float max_anisotropy = 1.0;
108 Color border_color = { 0.0, 0.0, 0.0, 0.0 };
109
110 bool _should_use_fallback_node();
111 void _create_fallback_node();
112 void _reset_fallback_material();
113 void _remove_fallback_node();
114
115 void _setup_composition_layer();
116 void _clear_composition_layer();
117
118 void _viewport_size_changed();
119
120 protected:
121 OpenXRAPI *openxr_api = nullptr;
122 OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
123
124 static void _bind_methods();
125
126 void _notification(int p_what);
127 void _get_property_list(List<PropertyInfo> *p_property_list) const;
128 bool _get(const StringName &p_property, Variant &r_value) const;
129 bool _set(const StringName &p_property, const Variant &p_value);
130 void _validate_property(PropertyInfo &p_property) const;
131
132 virtual void _on_openxr_session_begun();
133 virtual void _on_openxr_session_stopping();
134
135 bool _should_register();
136
137 virtual Ref<Mesh> _create_fallback_mesh() = 0;
138 virtual XrStructureType _get_openxr_type() const = 0;
139
140 void update_transform();
141 void update_fallback_mesh();
142
143 static Vector<OpenXRCompositionLayer *> composition_layer_nodes;
144 bool is_viewport_in_use(SubViewport *p_viewport);
145
146 OpenXRCompositionLayer();
147
148 public:
149 void set_layer_viewport(SubViewport *p_viewport);
150 SubViewport *get_layer_viewport() const;
151
152 void set_use_android_surface(bool p_use_android_surface);
153 bool get_use_android_surface() const;
154
155 void set_android_surface_size(Size2i p_size);
156 Size2i get_android_surface_size() const;
157
158 void set_enable_hole_punch(bool p_enable);
159 bool get_enable_hole_punch() const;
160
161 void set_sort_order(int p_order);
162 int get_sort_order() const;
163
164 void set_alpha_blend(bool p_alpha_blend);
165 bool get_alpha_blend() const;
166
167 Ref<JavaObject> get_android_surface();
168 bool is_natively_supported() const;
169
170 void set_protected_content(bool p_protected_content);
171 bool is_protected_content() const;
172
173 void set_min_filter(Filter p_mode);
174 Filter get_min_filter() const;
175
176 void set_mag_filter(Filter p_mode);
177 Filter get_mag_filter() const;
178
179 void set_mipmap_mode(MipmapMode p_mode);
180 MipmapMode get_mipmap_mode() const;
181
182 void set_horizontal_wrap(Wrap p_mode);
183 Wrap get_horizontal_wrap() const;
184
185 void set_vertical_wrap(Wrap p_mode);
186 Wrap get_vertical_wrap() const;
187
188 void set_red_swizzle(Swizzle p_mode);
189 Swizzle get_red_swizzle() const;
190
191 void set_green_swizzle(Swizzle p_mode);
192 Swizzle get_green_swizzle() const;
193
194 void set_blue_swizzle(Swizzle p_mode);
195 Swizzle get_blue_swizzle() const;
196
197 void set_alpha_swizzle(Swizzle p_mode);
198 Swizzle get_alpha_swizzle() const;
199
200 void set_max_anisotropy(float p_value);
201 float get_max_anisotropy() const;
202
203 void set_border_color(const Color &p_color);
204 Color get_border_color() const;
205
206 virtual PackedStringArray get_configuration_warnings() const override;
207
208 virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;
209
210 ~OpenXRCompositionLayer();
211 };
212
213 VARIANT_ENUM_CAST(OpenXRCompositionLayer::Filter)
214 VARIANT_ENUM_CAST(OpenXRCompositionLayer::MipmapMode)
215 VARIANT_ENUM_CAST(OpenXRCompositionLayer::Wrap)
216 VARIANT_ENUM_CAST(OpenXRCompositionLayer::Swizzle)