openxr_extension_wrapper_extension.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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(_set_hand_joint_locations_and_get_next_pointer, "hand_index", "next_pointer");
  39. GDVIRTUAL_BIND(_get_composition_layer_count);
  40. GDVIRTUAL_BIND(_get_composition_layer, "index");
  41. GDVIRTUAL_BIND(_get_composition_layer_order, "index");
  42. GDVIRTUAL_BIND(_get_suggested_tracker_names);
  43. GDVIRTUAL_BIND(_on_register_metadata);
  44. GDVIRTUAL_BIND(_on_before_instance_created);
  45. GDVIRTUAL_BIND(_on_instance_created, "instance");
  46. GDVIRTUAL_BIND(_on_instance_destroyed);
  47. GDVIRTUAL_BIND(_on_session_created, "session");
  48. GDVIRTUAL_BIND(_on_process);
  49. GDVIRTUAL_BIND(_on_pre_render);
  50. GDVIRTUAL_BIND(_on_main_swapchains_created);
  51. GDVIRTUAL_BIND(_on_session_destroyed);
  52. GDVIRTUAL_BIND(_on_state_idle);
  53. GDVIRTUAL_BIND(_on_state_ready);
  54. GDVIRTUAL_BIND(_on_state_synchronized);
  55. GDVIRTUAL_BIND(_on_state_visible);
  56. GDVIRTUAL_BIND(_on_state_focused);
  57. GDVIRTUAL_BIND(_on_state_stopping);
  58. GDVIRTUAL_BIND(_on_state_loss_pending);
  59. GDVIRTUAL_BIND(_on_state_exiting);
  60. GDVIRTUAL_BIND(_on_event_polled, "event");
  61. GDVIRTUAL_BIND(_set_viewport_composition_layer_and_get_next_pointer, "layer", "property_values", "next_pointer");
  62. GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_properties);
  63. GDVIRTUAL_BIND(_get_viewport_composition_layer_extension_property_defaults);
  64. GDVIRTUAL_BIND(_on_viewport_composition_layer_destroyed, "layer");
  65. GDVIRTUAL_BIND(_set_android_surface_swapchain_create_info_and_get_next_pointer, "property_values", "next_pointer");
  66. ClassDB::bind_method(D_METHOD("get_openxr_api"), &OpenXRExtensionWrapperExtension::get_openxr_api);
  67. ClassDB::bind_method(D_METHOD("register_extension_wrapper"), &OpenXRExtensionWrapperExtension::register_extension_wrapper);
  68. }
  69. HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extensions() {
  70. Dictionary request_extension;
  71. if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
  72. HashMap<String, bool *> result;
  73. Array keys = request_extension.keys();
  74. for (int i = 0; i < keys.size(); i++) {
  75. String key = keys.get(i);
  76. GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
  77. result.insert(key, value);
  78. }
  79. return result;
  80. }
  81. return HashMap<String, bool *>();
  82. }
  83. void *OpenXRExtensionWrapperExtension::set_system_properties_and_get_next_pointer(void *p_next_pointer) {
  84. uint64_t pointer;
  85. if (GDVIRTUAL_CALL(_set_system_properties_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  86. return reinterpret_cast<void *>(pointer);
  87. }
  88. return nullptr;
  89. }
  90. void *OpenXRExtensionWrapperExtension::set_instance_create_info_and_get_next_pointer(void *p_next_pointer) {
  91. uint64_t pointer;
  92. if (GDVIRTUAL_CALL(_set_instance_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  93. return reinterpret_cast<void *>(pointer);
  94. }
  95. return nullptr;
  96. }
  97. void *OpenXRExtensionWrapperExtension::set_session_create_and_get_next_pointer(void *p_next_pointer) {
  98. uint64_t pointer;
  99. if (GDVIRTUAL_CALL(_set_session_create_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  100. return reinterpret_cast<void *>(pointer);
  101. }
  102. return nullptr;
  103. }
  104. void *OpenXRExtensionWrapperExtension::set_swapchain_create_info_and_get_next_pointer(void *p_next_pointer) {
  105. uint64_t pointer;
  106. if (GDVIRTUAL_CALL(_set_swapchain_create_info_and_get_next_pointer, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  107. return reinterpret_cast<void *>(pointer);
  108. }
  109. return nullptr;
  110. }
  111. void *OpenXRExtensionWrapperExtension::set_hand_joint_locations_and_get_next_pointer(int p_hand_index, void *p_next_pointer) {
  112. uint64_t pointer;
  113. if (GDVIRTUAL_CALL(_set_hand_joint_locations_and_get_next_pointer, p_hand_index, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  114. return reinterpret_cast<void *>(pointer);
  115. }
  116. return nullptr;
  117. }
  118. PackedStringArray OpenXRExtensionWrapperExtension::get_suggested_tracker_names() {
  119. PackedStringArray ret;
  120. if (GDVIRTUAL_CALL(_get_suggested_tracker_names, ret)) {
  121. return ret;
  122. }
  123. return PackedStringArray();
  124. }
  125. int OpenXRExtensionWrapperExtension::get_composition_layer_count() {
  126. int count = 0;
  127. GDVIRTUAL_CALL(_get_composition_layer_count, count);
  128. return count;
  129. }
  130. XrCompositionLayerBaseHeader *OpenXRExtensionWrapperExtension::get_composition_layer(int p_index) {
  131. uint64_t pointer;
  132. if (GDVIRTUAL_CALL(_get_composition_layer, p_index, pointer)) {
  133. return reinterpret_cast<XrCompositionLayerBaseHeader *>(pointer);
  134. }
  135. return nullptr;
  136. }
  137. int OpenXRExtensionWrapperExtension::get_composition_layer_order(int p_index) {
  138. int order = 0;
  139. GDVIRTUAL_CALL(_get_composition_layer_order, p_index, order);
  140. return order;
  141. }
  142. void OpenXRExtensionWrapperExtension::on_register_metadata() {
  143. GDVIRTUAL_CALL(_on_register_metadata);
  144. }
  145. void OpenXRExtensionWrapperExtension::on_before_instance_created() {
  146. GDVIRTUAL_CALL(_on_before_instance_created);
  147. }
  148. void OpenXRExtensionWrapperExtension::on_instance_created(const XrInstance p_instance) {
  149. uint64_t instance = (uint64_t)p_instance;
  150. GDVIRTUAL_CALL(_on_instance_created, instance);
  151. }
  152. void OpenXRExtensionWrapperExtension::on_instance_destroyed() {
  153. GDVIRTUAL_CALL(_on_instance_destroyed);
  154. }
  155. void OpenXRExtensionWrapperExtension::on_session_created(const XrSession p_session) {
  156. uint64_t session = (uint64_t)p_session;
  157. GDVIRTUAL_CALL(_on_session_created, session);
  158. }
  159. void OpenXRExtensionWrapperExtension::on_process() {
  160. GDVIRTUAL_CALL(_on_process);
  161. }
  162. void OpenXRExtensionWrapperExtension::on_pre_render() {
  163. GDVIRTUAL_CALL(_on_pre_render);
  164. }
  165. void OpenXRExtensionWrapperExtension::on_main_swapchains_created() {
  166. GDVIRTUAL_CALL(_on_main_swapchains_created);
  167. }
  168. void OpenXRExtensionWrapperExtension::on_session_destroyed() {
  169. GDVIRTUAL_CALL(_on_session_destroyed);
  170. }
  171. void OpenXRExtensionWrapperExtension::on_state_idle() {
  172. GDVIRTUAL_CALL(_on_state_idle);
  173. }
  174. void OpenXRExtensionWrapperExtension::on_state_ready() {
  175. GDVIRTUAL_CALL(_on_state_ready);
  176. }
  177. void OpenXRExtensionWrapperExtension::on_state_synchronized() {
  178. GDVIRTUAL_CALL(_on_state_synchronized);
  179. }
  180. void OpenXRExtensionWrapperExtension::on_state_visible() {
  181. GDVIRTUAL_CALL(_on_state_visible);
  182. }
  183. void OpenXRExtensionWrapperExtension::on_state_focused() {
  184. GDVIRTUAL_CALL(_on_state_focused);
  185. }
  186. void OpenXRExtensionWrapperExtension::on_state_stopping() {
  187. GDVIRTUAL_CALL(_on_state_stopping);
  188. }
  189. void OpenXRExtensionWrapperExtension::on_state_loss_pending() {
  190. GDVIRTUAL_CALL(_on_state_loss_pending);
  191. }
  192. void OpenXRExtensionWrapperExtension::on_state_exiting() {
  193. GDVIRTUAL_CALL(_on_state_exiting);
  194. }
  195. bool OpenXRExtensionWrapperExtension::on_event_polled(const XrEventDataBuffer &p_event) {
  196. bool event_polled;
  197. if (GDVIRTUAL_CALL(_on_event_polled, GDExtensionConstPtr<void>(&p_event), event_polled)) {
  198. return event_polled;
  199. }
  200. return false;
  201. }
  202. void *OpenXRExtensionWrapperExtension::set_viewport_composition_layer_and_get_next_pointer(const XrCompositionLayerBaseHeader *p_layer, const Dictionary &p_property_values, void *p_next_pointer) {
  203. uint64_t pointer = 0;
  204. if (GDVIRTUAL_CALL(_set_viewport_composition_layer_and_get_next_pointer, GDExtensionConstPtr<void>(p_layer), p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  205. return reinterpret_cast<void *>(pointer);
  206. }
  207. return p_next_pointer;
  208. }
  209. void OpenXRExtensionWrapperExtension::on_viewport_composition_layer_destroyed(const XrCompositionLayerBaseHeader *p_layer) {
  210. GDVIRTUAL_CALL(_on_viewport_composition_layer_destroyed, GDExtensionConstPtr<void>(p_layer));
  211. }
  212. void OpenXRExtensionWrapperExtension::get_viewport_composition_layer_extension_properties(List<PropertyInfo> *p_property_list) {
  213. TypedArray<Dictionary> properties;
  214. if (GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_properties, properties)) {
  215. for (int i = 0; i < properties.size(); i++) {
  216. p_property_list->push_back(PropertyInfo::from_dict(properties[i]));
  217. }
  218. }
  219. }
  220. Dictionary OpenXRExtensionWrapperExtension::get_viewport_composition_layer_extension_property_defaults() {
  221. Dictionary property_defaults;
  222. GDVIRTUAL_CALL(_get_viewport_composition_layer_extension_property_defaults, property_defaults);
  223. return property_defaults;
  224. }
  225. void *OpenXRExtensionWrapperExtension::set_android_surface_swapchain_create_info_and_get_next_pointer(const Dictionary &p_property_values, void *p_next_pointer) {
  226. uint64_t pointer = 0;
  227. if (GDVIRTUAL_CALL(_set_android_surface_swapchain_create_info_and_get_next_pointer, p_property_values, GDExtensionPtr<void>(p_next_pointer), pointer)) {
  228. return reinterpret_cast<void *>(pointer);
  229. }
  230. return p_next_pointer;
  231. }
  232. Ref<OpenXRAPIExtension> OpenXRExtensionWrapperExtension::get_openxr_api() {
  233. return openxr_api;
  234. }
  235. void OpenXRExtensionWrapperExtension::register_extension_wrapper() {
  236. OpenXRAPI::register_extension_wrapper(this);
  237. }
  238. OpenXRExtensionWrapperExtension::OpenXRExtensionWrapperExtension() {
  239. openxr_api.instantiate();
  240. }
  241. OpenXRExtensionWrapperExtension::~OpenXRExtensionWrapperExtension() {
  242. }