arvr_interface.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**************************************************************************/
  2. /* arvr_interface.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 "arvr_interface.h"
  31. void ARVRInterface::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_name"), &ARVRInterface::get_name);
  33. ClassDB::bind_method(D_METHOD("get_capabilities"), &ARVRInterface::get_capabilities);
  34. ClassDB::bind_method(D_METHOD("is_primary"), &ARVRInterface::is_primary);
  35. ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &ARVRInterface::set_is_primary);
  36. ClassDB::bind_method(D_METHOD("is_initialized"), &ARVRInterface::is_initialized);
  37. ClassDB::bind_method(D_METHOD("set_is_initialized", "initialized"), &ARVRInterface::set_is_initialized);
  38. ClassDB::bind_method(D_METHOD("initialize"), &ARVRInterface::initialize);
  39. ClassDB::bind_method(D_METHOD("uninitialize"), &ARVRInterface::uninitialize);
  40. ClassDB::bind_method(D_METHOD("get_tracking_status"), &ARVRInterface::get_tracking_status);
  41. ClassDB::bind_method(D_METHOD("get_render_targetsize"), &ARVRInterface::get_render_targetsize);
  42. ClassDB::bind_method(D_METHOD("is_stereo"), &ARVRInterface::is_stereo);
  43. ClassDB::bind_method(D_METHOD("get_transform_for_eye", "eye", "transform"), &ARVRInterface::get_transform_for_eye);
  44. ADD_GROUP("Interface", "interface_");
  45. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary");
  46. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_initialized"), "set_is_initialized", "is_initialized");
  47. // we don't have any properties specific to VR yet....
  48. // but we do have properties specific to AR....
  49. ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &ARVRInterface::get_anchor_detection_is_enabled);
  50. ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &ARVRInterface::set_anchor_detection_is_enabled);
  51. ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &ARVRInterface::get_camera_feed_id);
  52. ADD_GROUP("AR", "ar_");
  53. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled");
  54. BIND_ENUM_CONSTANT(ARVR_NONE);
  55. BIND_ENUM_CONSTANT(ARVR_MONO);
  56. BIND_ENUM_CONSTANT(ARVR_STEREO);
  57. BIND_ENUM_CONSTANT(ARVR_AR);
  58. BIND_ENUM_CONSTANT(ARVR_EXTERNAL);
  59. BIND_ENUM_CONSTANT(EYE_MONO);
  60. BIND_ENUM_CONSTANT(EYE_LEFT);
  61. BIND_ENUM_CONSTANT(EYE_RIGHT);
  62. BIND_ENUM_CONSTANT(ARVR_NORMAL_TRACKING);
  63. BIND_ENUM_CONSTANT(ARVR_EXCESSIVE_MOTION);
  64. BIND_ENUM_CONSTANT(ARVR_INSUFFICIENT_FEATURES);
  65. BIND_ENUM_CONSTANT(ARVR_UNKNOWN_TRACKING);
  66. BIND_ENUM_CONSTANT(ARVR_NOT_TRACKING);
  67. };
  68. StringName ARVRInterface::get_name() const {
  69. return "Unknown";
  70. };
  71. bool ARVRInterface::is_primary() {
  72. ARVRServer *arvr_server = ARVRServer::get_singleton();
  73. ERR_FAIL_NULL_V(arvr_server, false);
  74. return arvr_server->get_primary_interface() == this;
  75. };
  76. void ARVRInterface::set_is_primary(bool p_is_primary) {
  77. ARVRServer *arvr_server = ARVRServer::get_singleton();
  78. ERR_FAIL_NULL(arvr_server);
  79. if (p_is_primary) {
  80. ERR_FAIL_COND(!is_initialized());
  81. arvr_server->set_primary_interface(this);
  82. } else {
  83. arvr_server->clear_primary_interface_if(this);
  84. };
  85. };
  86. void ARVRInterface::set_is_initialized(bool p_initialized) {
  87. if (p_initialized) {
  88. if (!is_initialized()) {
  89. initialize();
  90. };
  91. } else {
  92. if (is_initialized()) {
  93. uninitialize();
  94. };
  95. };
  96. };
  97. ARVRInterface::Tracking_status ARVRInterface::get_tracking_status() const {
  98. return tracking_state;
  99. };
  100. ARVRInterface::ARVRInterface() {
  101. tracking_state = ARVR_UNKNOWN_TRACKING;
  102. };
  103. ARVRInterface::~ARVRInterface(){};
  104. // optional render to external texture which enhances performance on those platforms that require us to submit our end result into special textures.
  105. unsigned int ARVRInterface::get_external_texture_for_eye(ARVRInterface::Eyes p_eye) {
  106. return 0;
  107. };
  108. // optional render to external depth texture which enhances performance on those platforms that require us to submit our end result into special textures.
  109. unsigned int ARVRInterface::get_external_depth_for_eye(ARVRInterface::Eyes p_eye) {
  110. return 0;
  111. };
  112. /** these will only be implemented on AR interfaces, so we want dummies for VR **/
  113. bool ARVRInterface::get_anchor_detection_is_enabled() const {
  114. return false;
  115. };
  116. void ARVRInterface::set_anchor_detection_is_enabled(bool p_enable){
  117. // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc.
  118. };
  119. int ARVRInterface::get_camera_feed_id() {
  120. // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc.
  121. return 0;
  122. };