openxr_extension_wrapper_extension.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /**************************************************************************/
  2. /* openxr_extension_wrapper_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_extension_wrapper_extension.h"
  31. #include "../openxr_api.h"
  32. void OpenXRExtensionWrapperExtension::_bind_methods() {
  33. GDVIRTUAL_BIND(_get_requested_extensions);
  34. GDVIRTUAL_BIND(_set_system_properties_and_get_next_pointer, "next_pointer");
  35. GDVIRTUAL_BIND(_set_instance_create_info_and_get_next_pointer, "next_pointer");
  36. GDVIRTUAL_BIND(_set_session_create_and_get_next_pointer, "next_pointer");
  37. GDVIRTUAL_BIND(_set_swapchain_create_info_and_get_next_pointer, "next_pointer");
  38. GDVIRTUAL_BIND(_on_register_metadata);
  39. GDVIRTUAL_BIND(_on_before_instance_created);
  40. GDVIRTUAL_BIND(_on_instance_created, "instance");
  41. GDVIRTUAL_BIND(_on_instance_destroyed);
  42. GDVIRTUAL_BIND(_on_session_created, "session");
  43. GDVIRTUAL_BIND(_on_process);
  44. GDVIRTUAL_BIND(_on_pre_render);
  45. GDVIRTUAL_BIND(_on_session_destroyed);
  46. GDVIRTUAL_BIND(_on_state_idle);
  47. GDVIRTUAL_BIND(_on_state_ready);
  48. GDVIRTUAL_BIND(_on_state_synchronized);
  49. GDVIRTUAL_BIND(_on_state_visible);
  50. GDVIRTUAL_BIND(_on_state_focused);
  51. GDVIRTUAL_BIND(_on_state_stopping);
  52. GDVIRTUAL_BIND(_on_state_loss_pending);
  53. GDVIRTUAL_BIND(_on_state_exiting);
  54. GDVIRTUAL_BIND(_on_event_polled, "event");
  55. ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapperExtension::get_openxr_api);
  56. ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapperExtension::register_extension_wrapper);
  57. }
  58. HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extensions() {
  59. Dictionary request_extension;
  60. if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
  61. HashMap<String, bool *> result;
  62. Array keys = request_extension.keys();
  63. for (int i = 0; i < keys.size(); i++) {
  64. String key = keys.get(i);
  65. GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
  66. result.insert(key, value);
  67. }
  68. return result;
  69. }
  70. return HashMap<String, bool *>();
  71. }
  72. void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
  73. uint64_t pointer;
  74. if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  75. return reinterpret_cast<void *>(pointer);
  76. }
  77. return nullptr;
  78. }
  79. void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
  80. uint64_t pointer;
  81. if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  82. return reinterpret_cast<void *>(pointer);
  83. }
  84. return nullptr;
  85. }
  86. void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
  87. uint64_t pointer;
  88. if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  89. return reinterpret_cast<void *>(pointer);
  90. }
  91. return nullptr;
  92. }
  93. void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
  94. uint64_t pointer;
  95. if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  96. return reinterpret_cast<void *>(pointer);
  97. }
  98. return nullptr;
  99. }
  100. void OpenXRExtensionWrapperExtension::on_register_metadata() {
  101. GDVIRTUAL_CALL(_on_register_metadata);
  102. }
  103. void OpenXRExtensionWrapperExtension::on_before_instance_created() {
  104. GDVIRTUAL_CALL(_on_before_instance_created);
  105. }
  106. void OpenXRExtensionWrapperExtension::on_instance_created(const XrInstance p_instance) {
  107. uint64_t instance = (uint64_t)p_instance;
  108. GDVIRTUAL_CALL(_on_instance_created, instance);
  109. }
  110. void OpenXRExtensionWrapperExtension::on_instance_destroyed() {
  111. GDVIRTUAL_CALL(_on_instance_destroyed);
  112. }
  113. void OpenXRExtensionWrapperExtension::on_session_created(const XrSession p_session) {
  114. uint64_t session = (uint64_t)p_session;
  115. GDVIRTUAL_CALL(_on_session_created, session);
  116. }
  117. void OpenXRExtensionWrapperExtension::on_process() {
  118. GDVIRTUAL_CALL(_on_process);
  119. }
  120. void OpenXRExtensionWrapperExtension::on_pre_render() {
  121. GDVIRTUAL_CALL(_on_pre_render);
  122. }
  123. void OpenXRExtensionWrapperExtension::on_session_destroyed() {
  124. GDVIRTUAL_CALL(_on_session_destroyed);
  125. }
  126. void OpenXRExtensionWrapperExtension::on_state_idle() {
  127. GDVIRTUAL_CALL(_on_state_idle);
  128. }
  129. void OpenXRExtensionWrapperExtension::on_state_ready() {
  130. GDVIRTUAL_CALL(_on_state_ready);
  131. }
  132. void OpenXRExtensionWrapperExtension::on_state_synchronized() {
  133. GDVIRTUAL_CALL(_on_state_synchronized);
  134. }
  135. void OpenXRExtensionWrapperExtension::on_state_visible() {
  136. GDVIRTUAL_CALL(_on_state_visible);
  137. }
  138. void OpenXRExtensionWrapperExtension::on_state_focused() {
  139. GDVIRTUAL_CALL(_on_state_focused);
  140. }
  141. void OpenXRExtensionWrapperExtension::on_state_stopping() {
  142. GDVIRTUAL_CALL(_on_state_stopping);
  143. }
  144. void OpenXRExtensionWrapperExtension::on_state_loss_pending() {
  145. GDVIRTUAL_CALL(_on_state_loss_pending);
  146. }
  147. void OpenXRExtensionWrapperExtension::on_state_exiting() {
  148. GDVIRTUAL_CALL(_on_state_exiting);
  149. }
  150. bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p_event) {
  151. bool event_polled;
  152. if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {
  153. return event_polled;
  154. }
  155. return false;
  156. }
  157. Ref<OpenXRAPIExtension> OpenXRExtensionWrapperExtension::get_openxr_api() {
  158. return openxr_api;
  159. }
  160. void OpenXRExtensionWrapperExtension::register_extension_wrapper() {
  161. OpenXRAPI::register_extension_wrapper(this);
  162. }
  163. OpenXRExtensionWrapperExtension::OpenXRExtensionWrapperExtension() :
  164. Object(), OpenXRExtensionWrapper() {
  165. openxr_api.instantiate();
  166. }