openxr_composition_layer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #ifndef OPENXR_COMPOSITION_LAYER_H
  31. #define OPENXR_COMPOSITION_LAYER_H
  32. #include <openxr/openxr.h>
  33. #include "scene/3d/node_3d.h"
  34. class JavaObject;
  35. class MeshInstance3D;
  36. class Mesh;
  37. class OpenXRAPI;
  38. class OpenXRCompositionLayerExtension;
  39. class OpenXRViewportCompositionLayerProvider;
  40. class SubViewport;
  41. class OpenXRCompositionLayer : public Node3D {
  42. GDCLASS(OpenXRCompositionLayer, Node3D);
  43. XrCompositionLayerBaseHeader *composition_layer_base_header = nullptr;
  44. OpenXRViewportCompositionLayerProvider *openxr_layer_provider = nullptr;
  45. SubViewport *layer_viewport = nullptr;
  46. bool use_android_surface = false;
  47. Size2i android_surface_size = Size2i(1024, 1024);
  48. bool enable_hole_punch = false;
  49. MeshInstance3D *fallback = nullptr;
  50. bool should_update_fallback_mesh = false;
  51. bool openxr_session_running = false;
  52. Dictionary extension_property_values;
  53. bool _should_use_fallback_node();
  54. void _create_fallback_node();
  55. void _reset_fallback_material();
  56. void _remove_fallback_node();
  57. void _setup_composition_layer_provider();
  58. void _clear_composition_layer_provider();
  59. protected:
  60. OpenXRAPI *openxr_api = nullptr;
  61. OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
  62. static void _bind_methods();
  63. void _notification(int p_what);
  64. void _get_property_list(List<PropertyInfo> *p_property_list) const;
  65. bool _get(const StringName &p_property, Variant &r_value) const;
  66. bool _set(const StringName &p_property, const Variant &p_value);
  67. void _validate_property(PropertyInfo &p_property) const;
  68. virtual void _on_openxr_session_begun();
  69. virtual void _on_openxr_session_stopping();
  70. virtual Ref<Mesh> _create_fallback_mesh() = 0;
  71. void update_fallback_mesh();
  72. XrPosef get_openxr_pose();
  73. static Vector<OpenXRCompositionLayer *> composition_layer_nodes;
  74. bool is_viewport_in_use(SubViewport *p_viewport);
  75. OpenXRCompositionLayer(XrCompositionLayerBaseHeader *p_composition_layer);
  76. public:
  77. void set_layer_viewport(SubViewport *p_viewport);
  78. SubViewport *get_layer_viewport() const;
  79. void set_use_android_surface(bool p_use_android_surface);
  80. bool get_use_android_surface() const;
  81. void set_android_surface_size(Size2i p_size);
  82. Size2i get_android_surface_size() const;
  83. void set_enable_hole_punch(bool p_enable);
  84. bool get_enable_hole_punch() const;
  85. void set_sort_order(int p_order);
  86. int get_sort_order() const;
  87. void set_alpha_blend(bool p_alpha_blend);
  88. bool get_alpha_blend() const;
  89. Ref<JavaObject> get_android_surface();
  90. bool is_natively_supported() const;
  91. virtual PackedStringArray get_configuration_warnings() const override;
  92. virtual Vector2 intersects_ray(const Vector3 &p_origin, const Vector3 &p_direction) const;
  93. ~OpenXRCompositionLayer();
  94. };
  95. #endif // OPENXR_COMPOSITION_LAYER_H