Path: blob/master/modules/openxr/scene/openxr_composition_layer.h
21568 views
/**************************************************************************/1/* openxr_composition_layer.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include <openxr/openxr.h>3334#include "scene/3d/node_3d.h"3536class JavaObject;37class MeshInstance3D;38class Mesh;39class OpenXRAPI;40class OpenXRCompositionLayerExtension;41class SubViewport;4243class OpenXRCompositionLayer : public Node3D {44GDCLASS(OpenXRCompositionLayer, Node3D);4546public:47// Must be identical to Filter enum definition in OpenXRCompositionLayerExtension.48enum Filter {49FILTER_NEAREST,50FILTER_LINEAR,51FILTER_CUBIC,52};5354// Must be identical to MipmapMode enum definition in OpenXRCompositionLayerExtension.55enum MipmapMode {56MIPMAP_MODE_DISABLED,57MIPMAP_MODE_NEAREST,58MIPMAP_MODE_LINEAR,59};6061// Must be identical to Wrap enum definition in OpenXRCompositionLayerExtension.62enum Wrap {63WRAP_CLAMP_TO_BORDER,64WRAP_CLAMP_TO_EDGE,65WRAP_REPEAT,66WRAP_MIRRORED_REPEAT,67WRAP_MIRROR_CLAMP_TO_EDGE,68};6970// Must be identical to Swizzle enum definition in OpenXRCompositionLayerExtension.71enum Swizzle {72SWIZZLE_RED,73SWIZZLE_GREEN,74SWIZZLE_BLUE,75SWIZZLE_ALPHA,76SWIZZLE_ZERO,77SWIZZLE_ONE,78};7980// Must be identical to EyeVisibility enum definition in OpenXRCompositionLayerExtension.81enum EyeVisibility {82EYE_VISIBILITY_BOTH,83EYE_VISIBILITY_LEFT,84EYE_VISIBILITY_RIGHT,85};8687protected:88RID composition_layer;8990private:91SubViewport *layer_viewport = nullptr;92bool use_android_surface = false;93Size2i android_surface_size = Size2i(1024, 1024);94bool enable_hole_punch = false;95bool alpha_blend = false;96int sort_order = 1;97bool protected_content = false;98MeshInstance3D *fallback = nullptr;99bool should_update_fallback_mesh = false;100bool openxr_session_running = false;101bool registered = false;102Dictionary extension_property_values;103104Filter min_filter = FILTER_LINEAR;105Filter mag_filter = FILTER_LINEAR;106MipmapMode mipmap_mode = MIPMAP_MODE_LINEAR;107Wrap horizontal_wrap = WRAP_CLAMP_TO_BORDER;108Wrap vertical_wrap = WRAP_CLAMP_TO_BORDER;109Swizzle red_swizzle = SWIZZLE_RED;110Swizzle green_swizzle = SWIZZLE_GREEN;111Swizzle blue_swizzle = SWIZZLE_BLUE;112Swizzle alpha_swizzle = SWIZZLE_ALPHA;113float max_anisotropy = 1.0;114Color border_color = { 0.0, 0.0, 0.0, 0.0 };115EyeVisibility eye_visibility = EYE_VISIBILITY_BOTH;116117bool _should_use_fallback_node();118void _create_fallback_node();119void _reset_fallback_material();120void _remove_fallback_node();121122void _setup_composition_layer();123void _clear_composition_layer();124125void _viewport_size_changed();126127protected:128OpenXRAPI *openxr_api = nullptr;129OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;130131static void _bind_methods();132133void _notification(int p_what);134void _get_property_list(List<PropertyInfo> *p_property_list) const;135bool _get(const StringName &p_property, Variant &r_value) const;136bool _set(const StringName &p_property, const Variant &p_value);137void _validate_property(PropertyInfo &p_property) const;138139virtual void _on_openxr_session_begun();140virtual void _on_openxr_session_stopping();141142bool _should_register();143144virtual Ref<Mesh> _create_fallback_mesh() = 0;145virtual XrStructureType _get_openxr_type() const = 0;146147void update_transform();148void update_fallback_mesh();149150static Vector<OpenXRCompositionLayer *> composition_layer_nodes;151bool is_viewport_in_use(SubViewport *p_viewport);152153OpenXRCompositionLayer();154155public:156void set_layer_viewport(SubViewport *p_viewport);157SubViewport *get_layer_viewport() const;158159void set_use_android_surface(bool p_use_android_surface);160bool get_use_android_surface() const;161162void set_android_surface_size(Size2i p_size);163Size2i get_android_surface_size() const;164165void set_enable_hole_punch(bool p_enable);166bool get_enable_hole_punch() const;167168void set_sort_order(int p_order);169int get_sort_order() const;170171void set_alpha_blend(bool p_alpha_blend);172bool get_alpha_blend() const;173174Ref<JavaObject> get_android_surface();175bool is_natively_supported() const;176177void set_protected_content(bool p_protected_content);178bool is_protected_content() const;179180void set_min_filter(Filter p_mode);181Filter get_min_filter() const;182183void set_mag_filter(Filter p_mode);184Filter get_mag_filter() const;185186void set_mipmap_mode(MipmapMode p_mode);187MipmapMode get_mipmap_mode() const;188189void set_horizontal_wrap(Wrap p_mode);190Wrap get_horizontal_wrap() const;191192void set_vertical_wrap(Wrap p_mode);193Wrap get_vertical_wrap() const;194195void set_red_swizzle(Swizzle p_mode);196Swizzle get_red_swizzle() const;197198void set_green_swizzle(Swizzle p_mode);199Swizzle get_green_swizzle() const;200201void set_blue_swizzle(Swizzle p_mode);202Swizzle get_blue_swizzle() const;203204void set_alpha_swizzle(Swizzle p_mode);205Swizzle get_alpha_swizzle() const;206207void set_max_anisotropy(float p_value);208float get_max_anisotropy() const;209210void set_border_color(const Color &p_color);211Color get_border_color() const;212213void set_eye_visibility(EyeVisibility p_eye_visibility);214EyeVisibility get_eye_visibility() const;215216virtual PackedStringArray get_configuration_warnings() const override;217218virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;219220~OpenXRCompositionLayer();221};222223VARIANT_ENUM_CAST(OpenXRCompositionLayer::Filter)224VARIANT_ENUM_CAST(OpenXRCompositionLayer::MipmapMode)225VARIANT_ENUM_CAST(OpenXRCompositionLayer::Wrap)226VARIANT_ENUM_CAST(OpenXRCompositionLayer::Swizzle)227VARIANT_ENUM_CAST(OpenXRCompositionLayer::EyeVisibility)228229230