openxr_structure.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**************************************************************************/
  2. /* openxr_structure.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_structure.h"
  31. void OpenXRStructureBase::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_structure_type"), &OpenXRStructureBase::_get_structure_type);
  33. ClassDB::bind_method(D_METHOD("set_next", "entity"), &OpenXRStructureBase::set_next);
  34. ClassDB::bind_method(D_METHOD("get_next"), &OpenXRStructureBase::get_next);
  35. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "next", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRStructureBase"), "set_next", "get_next");
  36. GDVIRTUAL_BIND(_get_header, "next");
  37. }
  38. void OpenXRStructureBase::set_next(const Ref<OpenXRStructureBase> p_next) {
  39. next = p_next;
  40. }
  41. Ref<OpenXRStructureBase> OpenXRStructureBase::get_next() const {
  42. return next;
  43. }
  44. void *OpenXRStructureBase::get_header(void *p_next) {
  45. void *n = p_next;
  46. if (get_next().is_valid()) {
  47. n = get_next()->get_header(p_next);
  48. }
  49. uint64_t pointer = 0;
  50. if (GDVIRTUAL_CALL(_get_header, (uint64_t)n, pointer)) {
  51. return reinterpret_cast<void *>(pointer);
  52. }
  53. return n;
  54. }
  55. XrStructureType OpenXRStructureBase::get_structure_type() {
  56. // By default we call get_header to get the structure type so we have a guaranteed implementation.
  57. // The first member of our header is always the structure type, so this works:
  58. XrStructureType *header = (XrStructureType *)get_header();
  59. if (header == nullptr) {
  60. // Header can return nullptr for valid reasons, so we do not error here!
  61. return XR_TYPE_UNKNOWN;
  62. } else {
  63. return *header;
  64. }
  65. }
  66. // Return structure type as uint64_t to GDScript
  67. uint64_t OpenXRStructureBase::_get_structure_type() {
  68. return (uint64_t)get_structure_type();
  69. }