2
0

openxr_frame_synthesis_extension.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**************************************************************************/
  2. /* openxr_frame_synthesis_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. #pragma once
  31. #include "../openxr_api.h"
  32. #include "openxr_extension_wrapper.h"
  33. #include <openxr/openxr.h>
  34. class OpenXRFrameSynthesisExtension : public OpenXRExtensionWrapper {
  35. GDCLASS(OpenXRFrameSynthesisExtension, OpenXRExtensionWrapper);
  36. public:
  37. static OpenXRFrameSynthesisExtension *get_singleton();
  38. OpenXRFrameSynthesisExtension();
  39. virtual ~OpenXRFrameSynthesisExtension() override;
  40. virtual HashMap<String, bool *> get_requested_extensions(XrVersion p_version) override;
  41. virtual void on_instance_created(const XrInstance p_instance) override;
  42. virtual void on_instance_destroyed() override;
  43. virtual void prepare_view_configuration(uint32_t p_view_count) override;
  44. virtual void *set_view_configuration_and_get_next_pointer(uint32_t p_view, void *p_next_pointer) override;
  45. virtual void print_view_configuration_info(uint32_t p_view) const override;
  46. virtual void on_session_destroyed() override;
  47. virtual void on_main_swapchains_created() override;
  48. virtual void on_pre_render() override;
  49. virtual void on_post_draw_viewport(RID p_render_target) override;
  50. virtual void *set_projection_views_and_get_next_pointer(int p_view_index, void *p_next_pointer) override;
  51. bool is_available() const;
  52. bool is_enabled() const;
  53. void set_enabled(bool p_enabled);
  54. bool get_relax_frame_interval() const;
  55. void set_relax_frame_interval(bool p_relax_frame_interval);
  56. void skip_next_frame();
  57. protected:
  58. static void _bind_methods();
  59. void _set_render_state_enabled_rt(bool p_enabled);
  60. void _set_relax_frame_interval_rt(bool p_relax_frame_interval);
  61. void _set_skip_next_frame_rt();
  62. private:
  63. enum SwapchainTypes {
  64. SWAPCHAIN_MOTION_VECTOR,
  65. SWAPCHAIN_DEPTH,
  66. SWAPCHAIN_MAX
  67. };
  68. void free_swapchains();
  69. static OpenXRFrameSynthesisExtension *singleton;
  70. bool frame_synthesis_ext = false;
  71. bool enabled = true;
  72. bool relax_frame_interval = false;
  73. // Frame synthesis render state, only accessible on render thread
  74. struct RenderState {
  75. bool enabled = true;
  76. bool relax_frame_interval = false;
  77. bool skip_next_frame = false;
  78. LocalVector<XrFrameSynthesisConfigViewEXT> config_views;
  79. OpenXRAPI::OpenXRSwapChainInfo swapchains[SWAPCHAIN_MAX];
  80. LocalVector<XrFrameSynthesisInfoEXT> frame_synthesis_info;
  81. Transform3D previous_transform;
  82. } render_state;
  83. };