openxr_api_extension.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**************************************************************************/
  2. /* openxr_api_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_api_extension.h"
  31. void OpenXRAPIExtension::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_instance"), &OpenXRAPIExtension::get_instance);
  33. ClassDB::bind_method(D_METHOD("get_system_id"), &OpenXRAPIExtension::get_system_id);
  34. ClassDB::bind_method(D_METHOD("get_session"), &OpenXRAPIExtension::get_session);
  35. ClassDB::bind_method(D_METHOD("transform_from_pose", "pose"), &OpenXRAPIExtension::transform_from_pose);
  36. ClassDB::bind_method(D_METHOD("xr_result", "result", "format", "args"), &OpenXRAPIExtension::xr_result);
  37. ClassDB::bind_static_method("OpenXRAPIExtension", D_METHOD("openxr_is_enabled", "check_run_in_editor"), &OpenXRAPIExtension::openxr_is_enabled);
  38. ClassDB::bind_method(D_METHOD("get_instance_proc_addr", "name"), &OpenXRAPIExtension::get_instance_proc_addr);
  39. ClassDB::bind_method(D_METHOD("get_error_string", "result"), &OpenXRAPIExtension::get_error_string);
  40. ClassDB::bind_method(D_METHOD("get_swapchain_format_name", "swapchain_format"), &OpenXRAPIExtension::get_swapchain_format_name);
  41. ClassDB::bind_method(D_METHOD("is_initialized"), &OpenXRAPIExtension::is_initialized);
  42. ClassDB::bind_method(D_METHOD("is_running"), &OpenXRAPIExtension::is_running);
  43. ClassDB::bind_method(D_METHOD("get_play_space"), &OpenXRAPIExtension::get_play_space);
  44. ClassDB::bind_method(D_METHOD("get_next_frame_time"), &OpenXRAPIExtension::get_next_frame_time);
  45. ClassDB::bind_method(D_METHOD("can_render"), &OpenXRAPIExtension::can_render);
  46. }
  47. uint64_t OpenXRAPIExtension::get_instance() {
  48. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  49. return (uint64_t)OpenXRAPI::get_singleton()->get_instance();
  50. }
  51. uint64_t OpenXRAPIExtension::get_system_id() {
  52. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  53. return (uint64_t)OpenXRAPI::get_singleton()->get_system_id();
  54. }
  55. uint64_t OpenXRAPIExtension::get_session() {
  56. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  57. return (uint64_t)OpenXRAPI::get_singleton()->get_session();
  58. }
  59. Transform3D OpenXRAPIExtension::transform_from_pose(GDExtensionConstPtr<const void> p_pose) {
  60. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), Transform3D());
  61. return OpenXRAPI::get_singleton()->transform_from_pose(*(XrPosef *)p_pose.data);
  62. }
  63. bool OpenXRAPIExtension::xr_result(uint64_t result, String format, Array args) {
  64. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
  65. return OpenXRAPI::get_singleton()->xr_result((XrResult)result, format.utf8().get_data(), args);
  66. }
  67. bool OpenXRAPIExtension::openxr_is_enabled(bool p_check_run_in_editor) {
  68. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
  69. return OpenXRAPI::openxr_is_enabled(p_check_run_in_editor);
  70. }
  71. uint64_t OpenXRAPIExtension::get_instance_proc_addr(String p_name) {
  72. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  73. CharString str = p_name.utf8();
  74. PFN_xrVoidFunction addr = nullptr;
  75. XrResult result = OpenXRAPI::get_singleton()->get_instance_proc_addr(str.get_data(), &addr);
  76. if (result != XR_SUCCESS) {
  77. return 0;
  78. }
  79. return reinterpret_cast<uint64_t>(addr);
  80. }
  81. String OpenXRAPIExtension::get_error_string(uint64_t result) {
  82. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String());
  83. return OpenXRAPI::get_singleton()->get_error_string((XrResult)result);
  84. }
  85. String OpenXRAPIExtension::get_swapchain_format_name(int64_t p_swapchain_format) {
  86. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), String());
  87. return OpenXRAPI::get_singleton()->get_swapchain_format_name(p_swapchain_format);
  88. }
  89. bool OpenXRAPIExtension::is_initialized() {
  90. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
  91. return OpenXRAPI::get_singleton()->is_initialized();
  92. }
  93. bool OpenXRAPIExtension::is_running() {
  94. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
  95. return OpenXRAPI::get_singleton()->is_running();
  96. }
  97. uint64_t OpenXRAPIExtension::get_play_space() {
  98. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  99. return (uint64_t)OpenXRAPI::get_singleton()->get_play_space();
  100. }
  101. int64_t OpenXRAPIExtension::get_next_frame_time() {
  102. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), 0);
  103. return (XrTime)OpenXRAPI::get_singleton()->get_next_frame_time();
  104. }
  105. bool OpenXRAPIExtension::can_render() {
  106. ERR_FAIL_NULL_V(OpenXRAPI::get_singleton(), false);
  107. return OpenXRAPI::get_singleton()->can_render();
  108. }
  109. OpenXRAPIExtension::OpenXRAPIExtension() {
  110. }