Path: blob/master/modules/openxr/scene/openxr_composition_layer.h
10278 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 "../extensions/openxr_composition_layer_extension.h"35#include "scene/3d/node_3d.h"3637class JavaObject;38class MeshInstance3D;39class Mesh;40class OpenXRAPI;41class OpenXRCompositionLayerExtension;42class OpenXRViewportCompositionLayerProvider;43class SubViewport;4445class OpenXRCompositionLayer : public Node3D {46GDCLASS(OpenXRCompositionLayer, Node3D);4748public:49// Must be identical to Filter enum definition in OpenXRViewportCompositionLayerProvider.50enum Filter {51FILTER_NEAREST,52FILTER_LINEAR,53FILTER_CUBIC,54};5556// Must be identical to MipmapMode enum definition in OpenXRViewportCompositionLayerProvider.57enum MipmapMode {58MIPMAP_MODE_DISABLED,59MIPMAP_MODE_NEAREST,60MIPMAP_MODE_LINEAR,61};6263// Must be identical to Wrap enum definition in OpenXRViewportCompositionLayerProvider.64enum Wrap {65WRAP_CLAMP_TO_BORDER,66WRAP_CLAMP_TO_EDGE,67WRAP_REPEAT,68WRAP_MIRRORED_REPEAT,69WRAP_MIRROR_CLAMP_TO_EDGE,70};7172// Must be identical to Swizzle enum definition in OpenXRViewportCompositionLayerProvider.73enum Swizzle {74SWIZZLE_RED,75SWIZZLE_GREEN,76SWIZZLE_BLUE,77SWIZZLE_ALPHA,78SWIZZLE_ZERO,79SWIZZLE_ONE,80};8182private:83XrCompositionLayerBaseHeader *composition_layer_base_header = nullptr;84OpenXRViewportCompositionLayerProvider *openxr_layer_provider = nullptr;8586SubViewport *layer_viewport = nullptr;87bool use_android_surface = false;88Size2i android_surface_size = Size2i(1024, 1024);89bool enable_hole_punch = false;90MeshInstance3D *fallback = nullptr;91bool should_update_fallback_mesh = false;92bool openxr_session_running = false;93bool registered = false;9495OpenXRViewportCompositionLayerProvider::SwapchainState *swapchain_state = nullptr;9697Dictionary extension_property_values;9899bool _should_use_fallback_node();100void _create_fallback_node();101void _reset_fallback_material();102void _remove_fallback_node();103104void _setup_composition_layer_provider();105void _clear_composition_layer_provider();106107protected:108OpenXRAPI *openxr_api = nullptr;109OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;110111static void _bind_methods();112113void _notification(int p_what);114void _get_property_list(List<PropertyInfo> *p_property_list) const;115bool _get(const StringName &p_property, Variant &r_value) const;116bool _set(const StringName &p_property, const Variant &p_value);117void _validate_property(PropertyInfo &p_property) const;118119virtual void _on_openxr_session_begun();120virtual void _on_openxr_session_stopping();121122bool _should_register();123124virtual Ref<Mesh> _create_fallback_mesh() = 0;125126void update_fallback_mesh();127128XrPosef get_openxr_pose();129130static Vector<OpenXRCompositionLayer *> composition_layer_nodes;131bool is_viewport_in_use(SubViewport *p_viewport);132133OpenXRCompositionLayer(XrCompositionLayerBaseHeader *p_composition_layer);134135public:136void set_layer_viewport(SubViewport *p_viewport);137SubViewport *get_layer_viewport() const;138139void set_use_android_surface(bool p_use_android_surface);140bool get_use_android_surface() const;141142void set_android_surface_size(Size2i p_size);143Size2i get_android_surface_size() const;144145void set_enable_hole_punch(bool p_enable);146bool get_enable_hole_punch() const;147148void set_sort_order(int p_order);149int get_sort_order() const;150151void set_alpha_blend(bool p_alpha_blend);152bool get_alpha_blend() const;153154Ref<JavaObject> get_android_surface();155bool is_natively_supported() const;156157void set_min_filter(Filter p_mode);158Filter get_min_filter() const;159160void set_mag_filter(Filter p_mode);161Filter get_mag_filter() const;162163void set_mipmap_mode(MipmapMode p_mode);164MipmapMode get_mipmap_mode() const;165166void set_horizontal_wrap(Wrap p_mode);167Wrap get_horizontal_wrap() const;168169void set_vertical_wrap(Wrap p_mode);170Wrap get_vertical_wrap() const;171172void set_red_swizzle(Swizzle p_mode);173Swizzle get_red_swizzle() const;174175void set_green_swizzle(Swizzle p_mode);176Swizzle get_green_swizzle() const;177178void set_blue_swizzle(Swizzle p_mode);179Swizzle get_blue_swizzle() const;180181void set_alpha_swizzle(Swizzle p_mode);182Swizzle get_alpha_swizzle() const;183184void set_max_anisotropy(float p_value);185float get_max_anisotropy() const;186187void set_border_color(Color p_color);188Color get_border_color() const;189190virtual PackedStringArray get_configuration_warnings() const override;191192virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;193194~OpenXRCompositionLayer();195};196197VARIANT_ENUM_CAST(OpenXRCompositionLayer::Filter)198VARIANT_ENUM_CAST(OpenXRCompositionLayer::MipmapMode)199VARIANT_ENUM_CAST(OpenXRCompositionLayer::Wrap)200VARIANT_ENUM_CAST(OpenXRCompositionLayer::Swizzle)201202203