Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/openxr/scene/openxr_composition_layer.h
21568 views
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
// Must be identical to EyeVisibility enum definition in OpenXRCompositionLayerExtension.
82
enum EyeVisibility {
83
EYE_VISIBILITY_BOTH,
84
EYE_VISIBILITY_LEFT,
85
EYE_VISIBILITY_RIGHT,
86
};
87
88
protected:
89
RID composition_layer;
90
91
private:
92
SubViewport *layer_viewport = nullptr;
93
bool use_android_surface = false;
94
Size2i android_surface_size = Size2i(1024, 1024);
95
bool enable_hole_punch = false;
96
bool alpha_blend = false;
97
int sort_order = 1;
98
bool protected_content = false;
99
MeshInstance3D *fallback = nullptr;
100
bool should_update_fallback_mesh = false;
101
bool openxr_session_running = false;
102
bool registered = false;
103
Dictionary extension_property_values;
104
105
Filter min_filter = FILTER_LINEAR;
106
Filter mag_filter = FILTER_LINEAR;
107
MipmapMode mipmap_mode = MIPMAP_MODE_LINEAR;
108
Wrap horizontal_wrap = WRAP_CLAMP_TO_BORDER;
109
Wrap vertical_wrap = WRAP_CLAMP_TO_BORDER;
110
Swizzle red_swizzle = SWIZZLE_RED;
111
Swizzle green_swizzle = SWIZZLE_GREEN;
112
Swizzle blue_swizzle = SWIZZLE_BLUE;
113
Swizzle alpha_swizzle = SWIZZLE_ALPHA;
114
float max_anisotropy = 1.0;
115
Color border_color = { 0.0, 0.0, 0.0, 0.0 };
116
EyeVisibility eye_visibility = EYE_VISIBILITY_BOTH;
117
118
bool _should_use_fallback_node();
119
void _create_fallback_node();
120
void _reset_fallback_material();
121
void _remove_fallback_node();
122
123
void _setup_composition_layer();
124
void _clear_composition_layer();
125
126
void _viewport_size_changed();
127
128
protected:
129
OpenXRAPI *openxr_api = nullptr;
130
OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
131
132
static void _bind_methods();
133
134
void _notification(int p_what);
135
void _get_property_list(List<PropertyInfo> *p_property_list) const;
136
bool _get(const StringName &p_property, Variant &r_value) const;
137
bool _set(const StringName &p_property, const Variant &p_value);
138
void _validate_property(PropertyInfo &p_property) const;
139
140
virtual void _on_openxr_session_begun();
141
virtual void _on_openxr_session_stopping();
142
143
bool _should_register();
144
145
virtual Ref<Mesh> _create_fallback_mesh() = 0;
146
virtual XrStructureType _get_openxr_type() const = 0;
147
148
void update_transform();
149
void update_fallback_mesh();
150
151
static Vector<OpenXRCompositionLayer *> composition_layer_nodes;
152
bool is_viewport_in_use(SubViewport *p_viewport);
153
154
OpenXRCompositionLayer();
155
156
public:
157
void set_layer_viewport(SubViewport *p_viewport);
158
SubViewport *get_layer_viewport() const;
159
160
void set_use_android_surface(bool p_use_android_surface);
161
bool get_use_android_surface() const;
162
163
void set_android_surface_size(Size2i p_size);
164
Size2i get_android_surface_size() const;
165
166
void set_enable_hole_punch(bool p_enable);
167
bool get_enable_hole_punch() const;
168
169
void set_sort_order(int p_order);
170
int get_sort_order() const;
171
172
void set_alpha_blend(bool p_alpha_blend);
173
bool get_alpha_blend() const;
174
175
Ref<JavaObject> get_android_surface();
176
bool is_natively_supported() const;
177
178
void set_protected_content(bool p_protected_content);
179
bool is_protected_content() const;
180
181
void set_min_filter(Filter p_mode);
182
Filter get_min_filter() const;
183
184
void set_mag_filter(Filter p_mode);
185
Filter get_mag_filter() const;
186
187
void set_mipmap_mode(MipmapMode p_mode);
188
MipmapMode get_mipmap_mode() const;
189
190
void set_horizontal_wrap(Wrap p_mode);
191
Wrap get_horizontal_wrap() const;
192
193
void set_vertical_wrap(Wrap p_mode);
194
Wrap get_vertical_wrap() const;
195
196
void set_red_swizzle(Swizzle p_mode);
197
Swizzle get_red_swizzle() const;
198
199
void set_green_swizzle(Swizzle p_mode);
200
Swizzle get_green_swizzle() const;
201
202
void set_blue_swizzle(Swizzle p_mode);
203
Swizzle get_blue_swizzle() const;
204
205
void set_alpha_swizzle(Swizzle p_mode);
206
Swizzle get_alpha_swizzle() const;
207
208
void set_max_anisotropy(float p_value);
209
float get_max_anisotropy() const;
210
211
void set_border_color(const Color &p_color);
212
Color get_border_color() const;
213
214
void set_eye_visibility(EyeVisibility p_eye_visibility);
215
EyeVisibility get_eye_visibility() const;
216
217
virtual PackedStringArray get_configuration_warnings() const override;
218
219
virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;
220
221
~OpenXRCompositionLayer();
222
};
223
224
VARIANT_ENUM_CAST(OpenXRCompositionLayer::Filter)
225
VARIANT_ENUM_CAST(OpenXRCompositionLayer::MipmapMode)
226
VARIANT_ENUM_CAST(OpenXRCompositionLayer::Wrap)
227
VARIANT_ENUM_CAST(OpenXRCompositionLayer::Swizzle)
228
VARIANT_ENUM_CAST(OpenXRCompositionLayer::EyeVisibility)
229
230