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