openxr_composition_layer_extension.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /**************************************************************************/
  2. /* openxr_composition_layer_extension.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_EXTENSION_H
  31. #define OPENXR_COMPOSITION_LAYER_EXTENSION_H
  32. #include "openxr_composition_layer_provider.h"
  33. #include "openxr_extension_wrapper.h"
  34. #include "../openxr_api.h"
  35. class OpenXRViewportCompositionLayerProvider;
  36. // This extension provides access to composition layers for displaying 2D content through the XR compositor.
  37. // OpenXRCompositionLayerExtension enables the extensions related to this functionality
  38. class OpenXRCompositionLayerExtension : public OpenXRExtensionWrapper, public OpenXRCompositionLayerProvider {
  39. public:
  40. static OpenXRCompositionLayerExtension *get_singleton();
  41. OpenXRCompositionLayerExtension();
  42. virtual ~OpenXRCompositionLayerExtension() override;
  43. virtual HashMap<String, bool *> get_requested_extensions() override;
  44. virtual void on_session_created(const XrSession p_instance) override;
  45. virtual void on_session_destroyed() override;
  46. virtual void on_pre_render() override;
  47. virtual int get_composition_layer_count() override;
  48. virtual XrCompositionLayerBaseHeader *get_composition_layer(int p_index) override;
  49. virtual int get_composition_layer_order(int p_index) override;
  50. void register_viewport_composition_layer_provider(OpenXRViewportCompositionLayerProvider *p_composition_layer);
  51. void unregister_viewport_composition_layer_provider(OpenXRViewportCompositionLayerProvider *p_composition_layer);
  52. bool is_available(XrStructureType p_which);
  53. private:
  54. static OpenXRCompositionLayerExtension *singleton;
  55. Vector<OpenXRViewportCompositionLayerProvider *> composition_layers;
  56. bool cylinder_ext_available = false;
  57. bool equirect_ext_available = false;
  58. };
  59. class OpenXRViewportCompositionLayerProvider {
  60. XrCompositionLayerBaseHeader *composition_layer = nullptr;
  61. int sort_order = 1;
  62. bool alpha_blend = false;
  63. Dictionary extension_property_values;
  64. bool extension_property_values_changed = true;
  65. RID viewport;
  66. Size2i viewport_size;
  67. OpenXRAPI::OpenXRSwapChainInfo swapchain_info;
  68. Size2i swapchain_size;
  69. bool static_image = false;
  70. OpenXRAPI *openxr_api = nullptr;
  71. OpenXRCompositionLayerExtension *composition_layer_extension = nullptr;
  72. bool update_and_acquire_swapchain(bool p_static_image);
  73. void free_swapchain();
  74. RID get_current_swapchain_texture();
  75. public:
  76. XrStructureType get_openxr_type() { return composition_layer->type; }
  77. void set_sort_order(int p_sort_order) { sort_order = p_sort_order; }
  78. int get_sort_order() const { return sort_order; }
  79. void set_alpha_blend(bool p_alpha_blend);
  80. bool get_alpha_blend() const { return alpha_blend; }
  81. void set_viewport(RID p_viewport, Size2i p_size);
  82. RID get_viewport() const { return viewport; }
  83. void set_extension_property_values(const Dictionary &p_property_values);
  84. void on_pre_render();
  85. XrCompositionLayerBaseHeader *get_composition_layer();
  86. OpenXRViewportCompositionLayerProvider(XrCompositionLayerBaseHeader *p_composition_layer);
  87. ~OpenXRViewportCompositionLayerProvider();
  88. };
  89. #endif // OPENXR_COMPOSITION_LAYER_EXTENSION_H