arvr_interface.cpp 6.5 KB

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