util.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* util.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 UTIL_H
  31. #define UTIL_H
  32. #define UNPACK(...) __VA_ARGS__
  33. #define INIT_XR_FUNC_V(openxr_api, name) \
  34. do { \
  35. XrResult get_instance_proc_addr_result; \
  36. get_instance_proc_addr_result = openxr_api->get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr); \
  37. ERR_FAIL_COND_V(XR_FAILED(get_instance_proc_addr_result), false); \
  38. } while (0)
  39. #define EXT_INIT_XR_FUNC_V(name) INIT_XR_FUNC_V(OpenXRAPI::get_singleton(), name)
  40. #define OPENXR_API_INIT_XR_FUNC_V(name) INIT_XR_FUNC_V(this, name)
  41. #define INIT_XR_FUNC(openxr_api, name) \
  42. do { \
  43. XrResult get_instance_proc_addr_result; \
  44. get_instance_proc_addr_result = openxr_api->get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr); \
  45. ERR_FAIL_COND(XR_FAILED(get_instance_proc_addr_result)); \
  46. } while (0)
  47. #define EXT_INIT_XR_FUNC(name) INIT_XR_FUNC(OpenXRAPI::get_singleton(), name)
  48. #define OPENXR_API_INIT_XR_FUNC(name) INIT_XR_FUNC(this, name)
  49. #define TRY_INIT_XR_FUNC(openxr_api, name) \
  50. openxr_api->try_get_instance_proc_addr(#name, (PFN_xrVoidFunction *)&name##_ptr)
  51. #define EXT_TRY_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(OpenXRAPI::get_singleton(), name)
  52. #define OPENXR_TRY_API_INIT_XR_FUNC(name) TRY_INIT_XR_FUNC(this, name)
  53. #define GDEXTENSION_INIT_XR_FUNC(name) \
  54. do { \
  55. name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
  56. ERR_FAIL_NULL(name##_ptr); \
  57. } while (0)
  58. #define GDEXTENSION_INIT_XR_FUNC_V(name) \
  59. do { \
  60. name##_ptr = reinterpret_cast<PFN_##name>(get_openxr_api()->get_instance_proc_addr(#name)); \
  61. ERR_FAIL_NULL_V(name##_ptr, false); \
  62. } while (0)
  63. #define EXT_PROTO_XRRESULT_FUNC1(func_name, arg1_type, arg1) \
  64. PFN_##func_name func_name##_ptr = nullptr; \
  65. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1) const { \
  66. if (!func_name##_ptr) { \
  67. return XR_ERROR_HANDLE_INVALID; \
  68. } \
  69. return (*func_name##_ptr)(p_##arg1); \
  70. }
  71. #define EXT_PROTO_XRRESULT_FUNC2(func_name, arg1_type, arg1, arg2_type, arg2) \
  72. PFN_##func_name func_name##_ptr = nullptr; \
  73. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2) const { \
  74. if (!func_name##_ptr) { \
  75. return XR_ERROR_HANDLE_INVALID; \
  76. } \
  77. return (*func_name##_ptr)(p_##arg1, p_##arg2); \
  78. }
  79. #define EXT_PROTO_XRRESULT_FUNC3(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3) \
  80. PFN_##func_name func_name##_ptr = nullptr; \
  81. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3) const { \
  82. if (!func_name##_ptr) { \
  83. return XR_ERROR_HANDLE_INVALID; \
  84. } \
  85. return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3); \
  86. }
  87. #define EXT_PROTO_XRRESULT_FUNC4(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4) \
  88. PFN_##func_name func_name##_ptr = nullptr; \
  89. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4) const { \
  90. if (!func_name##_ptr) { \
  91. return XR_ERROR_HANDLE_INVALID; \
  92. } \
  93. return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4); \
  94. }
  95. #define EXT_PROTO_XRRESULT_FUNC5(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4, arg5_type, arg5) \
  96. PFN_##func_name func_name##_ptr = nullptr; \
  97. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4, UNPACK arg5_type p_##arg5) const { \
  98. if (!func_name##_ptr) { \
  99. return XR_ERROR_HANDLE_INVALID; \
  100. } \
  101. return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4, p_##arg5); \
  102. }
  103. #define EXT_PROTO_XRRESULT_FUNC6(func_name, arg1_type, arg1, arg2_type, arg2, arg3_type, arg3, arg4_type, arg4, arg5_type, arg5, arg6_type, arg6) \
  104. PFN_##func_name func_name##_ptr = nullptr; \
  105. XRAPI_ATTR XrResult XRAPI_CALL func_name(UNPACK arg1_type p_##arg1, UNPACK arg2_type p_##arg2, UNPACK arg3_type p_##arg3, UNPACK arg4_type p_##arg4, UNPACK arg5_type p_##arg5, UNPACK arg6_type p_##arg6) const { \
  106. if (!func_name##_ptr) { \
  107. return XR_ERROR_HANDLE_INVALID; \
  108. } \
  109. return (*func_name##_ptr)(p_##arg1, p_##arg2, p_##arg3, p_##arg4, p_##arg5, p_##arg6); \
  110. }
  111. #endif // UTIL_H