openxr_fb_foveation_extension.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**************************************************************************/
  2. /* openxr_fb_foveation_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_FB_FOVEATION_EXTENSION_H
  31. #define OPENXR_FB_FOVEATION_EXTENSION_H
  32. // This extension implements the FB Foveation extension.
  33. // This is an extension Meta added due to VRS being unavailable on Android.
  34. // Other Android based devices are implementing this as well, see:
  35. // https://github.khronos.org/OpenXR-Inventory/extension_support.html#XR_FB_foveation
  36. // Note: Currently we only support this for OpenGL.
  37. // This extension works on enabling foveated rendering on the swapchain.
  38. // Vulkan does not render 3D content directly to the swapchain image
  39. // hence this extension can't be used.
  40. #include "../openxr_api.h"
  41. #include "../util.h"
  42. #include "openxr_extension_wrapper.h"
  43. #include "openxr_fb_update_swapchain_extension.h"
  44. class OpenXRFBFoveationExtension : public OpenXRExtensionWrapper {
  45. public:
  46. static OpenXRFBFoveationExtension *get_singleton();
  47. OpenXRFBFoveationExtension(const String &p_rendering_driver);
  48. virtual ~OpenXRFBFoveationExtension() override;
  49. virtual HashMap<String, bool *> get_requested_extensions() override;
  50. virtual void on_instance_created(const XrInstance p_instance) override;
  51. virtual void on_instance_destroyed() override;
  52. virtual void *set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) override;
  53. virtual void on_state_ready() override;
  54. bool is_enabled() const;
  55. XrFoveationLevelFB get_foveation_level() const;
  56. void set_foveation_level(XrFoveationLevelFB p_foveation_level);
  57. XrFoveationDynamicFB get_foveation_dynamic() const;
  58. void set_foveation_dynamic(XrFoveationDynamicFB p_foveation_dynamic);
  59. private:
  60. static OpenXRFBFoveationExtension *singleton;
  61. // Setup
  62. String rendering_driver;
  63. bool fb_foveation_ext = false;
  64. bool fb_foveation_configuration_ext = false;
  65. // Configuration
  66. XrFoveationLevelFB foveation_level = XR_FOVEATION_LEVEL_NONE_FB;
  67. XrFoveationDynamicFB foveation_dynamic = XR_FOVEATION_DYNAMIC_DISABLED_FB;
  68. void update_profile();
  69. // Enable foveation on this swapchain
  70. XrSwapchainCreateInfoFoveationFB swapchain_create_info_foveation_fb;
  71. OpenXRFBUpdateSwapchainExtension *swapchain_update_state_ext = nullptr;
  72. // OpenXR API call wrappers
  73. EXT_PROTO_XRRESULT_FUNC3(xrCreateFoveationProfileFB, (XrSession), session, (const XrFoveationProfileCreateInfoFB *), create_info, (XrFoveationProfileFB *), profile);
  74. EXT_PROTO_XRRESULT_FUNC1(xrDestroyFoveationProfileFB, (XrFoveationProfileFB), profile);
  75. };
  76. #endif // OPENXR_FB_FOVEATION_EXTENSION_H