summaryrefslogtreecommitdiffstats
path: root/modules/openxr/scene/openxr_composition_layer.h
diff options
context:
space:
mode:
authorDavid Snopek <dsnopek@gmail.com>2024-03-25 08:07:28 -0500
committerDavid Snopek <dsnopek@gmail.com>2024-04-04 09:20:23 -0500
commit0f2b804059331f2454e060577ae0e1b44675c5aa (patch)
treef83679824636edffe9827d9d968b0b85d2e54708 /modules/openxr/scene/openxr_composition_layer.h
parent29b3d9e9e538f0aa8effc8ad8bf19a2915292a89 (diff)
downloadredot-engine-0f2b804059331f2454e060577ae0e1b44675c5aa.tar.gz
Add support for OpenXR composition layers
Co-authored-by: Bastiaan Olij <mux213@gmail.com>
Diffstat (limited to 'modules/openxr/scene/openxr_composition_layer.h')
-rw-r--r--modules/openxr/scene/openxr_composition_layer.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/modules/openxr/scene/openxr_composition_layer.h b/modules/openxr/scene/openxr_composition_layer.h
new file mode 100644
index 0000000000..f683aea647
--- /dev/null
+++ b/modules/openxr/scene/openxr_composition_layer.h
@@ -0,0 +1,91 @@
+/**************************************************************************/
+/* openxr_composition_layer.h */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
+
+#ifndef OPENXR_COMPOSITION_LAYER_H
+#define OPENXR_COMPOSITION_LAYER_H
+
+#include <openxr/openxr.h>
+
+#include "scene/3d/node_3d.h"
+
+class MeshInstance3D;
+class Mesh;
+class OpenXRAPI;
+class OpenXRCompositionLayerExtension;
+class OpenXRViewportCompositionLayerProvider;
+class SubViewport;
+
+class OpenXRCompositionLayer : public Node3D {
+ GDCLASS(OpenXRCompositionLayer, Node3D);
+
+ SubViewport *layer_viewport = nullptr;
+ MeshInstance3D *fallback = nullptr;
+ bool should_update_fallback_mesh = false;
+
+ void _create_fallback_node();
+ void _reset_fallback_material();
+
+protected:
+ OpenXRAPI *openxr_api = nullptr;
+ OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
+ OpenXRViewportCompositionLayerProvider *openxr_layer_provider = nullptr;
+
+ static void _bind_methods();
+
+ void _notification(int p_what);
+
+ virtual void _on_openxr_session_begun();
+ virtual void _on_openxr_session_stopping();
+
+ virtual Ref<Mesh> _create_fallback_mesh() = 0;
+
+ void update_fallback_mesh();
+
+ static HashSet<SubViewport *> viewports_in_use;
+
+public:
+ void set_layer_viewport(SubViewport *p_viewport);
+ SubViewport *get_layer_viewport() const;
+
+ void set_sort_order(int p_order);
+ int get_sort_order() const;
+
+ void set_alpha_blend(bool p_alpha_blend);
+ bool get_alpha_blend() const;
+
+ bool is_natively_supported() const;
+
+ virtual PackedStringArray get_configuration_warnings() const override;
+
+ OpenXRCompositionLayer();
+ ~OpenXRCompositionLayer();
+};
+
+#endif // OPENXR_COMPOSITION_LAYER_H