openxr_fb_update_swapchain_extension.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**************************************************************************/
  2. /* openxr_fb_update_swapchain_extension.cpp */
  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. #include "openxr_fb_update_swapchain_extension.h"
  31. // Always include this as late as possible.
  32. #include "../openxr_platform_inc.h"
  33. OpenXRFBUpdateSwapchainExtension *OpenXRFBUpdateSwapchainExtension::singleton = nullptr;
  34. OpenXRFBUpdateSwapchainExtension *OpenXRFBUpdateSwapchainExtension::get_singleton() {
  35. return singleton;
  36. }
  37. OpenXRFBUpdateSwapchainExtension::OpenXRFBUpdateSwapchainExtension(const String &p_rendering_driver) {
  38. singleton = this;
  39. rendering_driver = p_rendering_driver;
  40. }
  41. OpenXRFBUpdateSwapchainExtension::~OpenXRFBUpdateSwapchainExtension() {
  42. singleton = nullptr;
  43. }
  44. HashMap<String, bool *> OpenXRFBUpdateSwapchainExtension::get_requested_extensions() {
  45. HashMap<String, bool *> request_extensions;
  46. request_extensions[XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME] = &fb_swapchain_update_state_ext;
  47. if (rendering_driver == "vulkan") {
  48. #ifdef XR_USE_GRAPHICS_API_VULKAN
  49. request_extensions[XR_FB_SWAPCHAIN_UPDATE_STATE_VULKAN_EXTENSION_NAME] = &fb_swapchain_update_state_vulkan_ext;
  50. #endif
  51. } else if (rendering_driver == "opengl3") {
  52. #ifdef XR_USE_GRAPHICS_API_OPENGL_ES
  53. request_extensions[XR_FB_SWAPCHAIN_UPDATE_STATE_OPENGL_ES_EXTENSION_NAME] = &fb_swapchain_update_state_opengles_ext;
  54. #endif
  55. }
  56. return request_extensions;
  57. }
  58. void OpenXRFBUpdateSwapchainExtension::on_instance_created(const XrInstance p_instance) {
  59. if (fb_swapchain_update_state_ext) {
  60. EXT_INIT_XR_FUNC(xrUpdateSwapchainFB);
  61. EXT_INIT_XR_FUNC(xrGetSwapchainStateFB);
  62. }
  63. if (fb_swapchain_update_state_vulkan_ext) {
  64. // nothing to register here...
  65. }
  66. if (fb_swapchain_update_state_opengles_ext) {
  67. // nothing to register here...
  68. }
  69. }
  70. void OpenXRFBUpdateSwapchainExtension::on_instance_destroyed() {
  71. fb_swapchain_update_state_ext = false;
  72. fb_swapchain_update_state_vulkan_ext = false;
  73. fb_swapchain_update_state_opengles_ext = false;
  74. }
  75. bool OpenXRFBUpdateSwapchainExtension::is_enabled() const {
  76. if (rendering_driver == "vulkan") {
  77. return fb_swapchain_update_state_ext && fb_swapchain_update_state_vulkan_ext;
  78. } else if (rendering_driver == "opengl3") {
  79. #ifdef XR_USE_GRAPHICS_API_OPENGL_ES
  80. return fb_swapchain_update_state_ext && fb_swapchain_update_state_opengles_ext;
  81. #else
  82. return fb_swapchain_update_state_ext;
  83. #endif
  84. }
  85. return false;
  86. }