xr_interface_extension.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**************************************************************************/
  2. /* xr_interface_extension.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 XR_INTERFACE_EXTENSION_H
  31. #define XR_INTERFACE_EXTENSION_H
  32. #include "servers/xr/xr_interface.h"
  33. class XRInterfaceExtension : public XRInterface {
  34. GDCLASS(XRInterfaceExtension, XRInterface);
  35. public:
  36. private:
  37. bool can_add_blits = false;
  38. Vector<BlitToScreen> blits;
  39. protected:
  40. _THREAD_SAFE_CLASS_
  41. static void _bind_methods();
  42. public:
  43. /** general interface information **/
  44. virtual StringName get_name() const override;
  45. virtual uint32_t get_capabilities() const override;
  46. GDVIRTUAL0RC(StringName, _get_name);
  47. GDVIRTUAL0RC(uint32_t, _get_capabilities);
  48. virtual bool is_initialized() const override;
  49. virtual bool initialize() override;
  50. virtual void uninitialize() override;
  51. virtual Dictionary get_system_info() override;
  52. GDVIRTUAL0RC(bool, _is_initialized);
  53. GDVIRTUAL0R(bool, _initialize);
  54. GDVIRTUAL0(_uninitialize);
  55. GDVIRTUAL0RC(Dictionary, _get_system_info);
  56. /** input and output **/
  57. virtual PackedStringArray get_suggested_tracker_names() const override; /* return a list of likely/suggested tracker names */
  58. virtual PackedStringArray get_suggested_pose_names(const StringName &p_tracker_name) const override; /* return a list of likely/suggested action names for this tracker */
  59. virtual TrackingStatus get_tracking_status() const override;
  60. virtual void trigger_haptic_pulse(const String &p_action_name, const StringName &p_tracker_name, double p_frequency, double p_amplitude, double p_duration_sec, double p_delay_sec = 0) override;
  61. GDVIRTUAL0RC(PackedStringArray, _get_suggested_tracker_names);
  62. GDVIRTUAL1RC(PackedStringArray, _get_suggested_pose_names, const StringName &);
  63. GDVIRTUAL0RC(XRInterface::TrackingStatus, _get_tracking_status);
  64. GDVIRTUAL6(_trigger_haptic_pulse, const String &, const StringName &, double, double, double, double);
  65. /** specific to VR **/
  66. virtual bool supports_play_area_mode(XRInterface::PlayAreaMode p_mode) override; /* query if this interface supports this play area mode */
  67. virtual XRInterface::PlayAreaMode get_play_area_mode() const override; /* get the current play area mode */
  68. virtual bool set_play_area_mode(XRInterface::PlayAreaMode p_mode) override; /* change the play area mode, note that this should return false if the mode is not available */
  69. virtual PackedVector3Array get_play_area() const override; /* if available, returns an array of vectors denoting the play area the player can move around in */
  70. GDVIRTUAL1RC(bool, _supports_play_area_mode, XRInterface::PlayAreaMode);
  71. GDVIRTUAL0RC(XRInterface::PlayAreaMode, _get_play_area_mode);
  72. GDVIRTUAL1RC(bool, _set_play_area_mode, XRInterface::PlayAreaMode);
  73. GDVIRTUAL0RC(PackedVector3Array, _get_play_area);
  74. /** specific to AR **/
  75. virtual bool get_anchor_detection_is_enabled() const override;
  76. virtual void set_anchor_detection_is_enabled(bool p_enable) override;
  77. virtual int get_camera_feed_id() override;
  78. GDVIRTUAL0RC(bool, _get_anchor_detection_is_enabled);
  79. GDVIRTUAL1(_set_anchor_detection_is_enabled, bool);
  80. GDVIRTUAL0RC(int, _get_camera_feed_id);
  81. /** rendering and internal **/
  82. virtual Size2 get_render_target_size() override;
  83. virtual uint32_t get_view_count() override;
  84. virtual Transform3D get_camera_transform() override;
  85. virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override;
  86. virtual Projection get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override;
  87. virtual RID get_vrs_texture() override;
  88. virtual RID get_color_texture() override;
  89. virtual RID get_depth_texture() override;
  90. virtual RID get_velocity_texture() override;
  91. GDVIRTUAL0R(Size2, _get_render_target_size);
  92. GDVIRTUAL0R(uint32_t, _get_view_count);
  93. GDVIRTUAL0R(Transform3D, _get_camera_transform);
  94. GDVIRTUAL2R(Transform3D, _get_transform_for_view, uint32_t, const Transform3D &);
  95. GDVIRTUAL4R(PackedFloat64Array, _get_projection_for_view, uint32_t, double, double, double);
  96. GDVIRTUAL0R(RID, _get_vrs_texture);
  97. GDVIRTUAL0R(RID, _get_color_texture);
  98. GDVIRTUAL0R(RID, _get_depth_texture);
  99. GDVIRTUAL0R(RID, _get_velocity_texture);
  100. void add_blit(RID p_render_target, Rect2 p_src_rect, Rect2i p_dst_rect, bool p_use_layer = false, uint32_t p_layer = 0, bool p_apply_lens_distortion = false, Vector2 p_eye_center = Vector2(), double p_k1 = 0.0, double p_k2 = 0.0, double p_upscale = 1.0, double p_aspect_ratio = 1.0);
  101. virtual void process() override;
  102. virtual void pre_render() override;
  103. virtual bool pre_draw_viewport(RID p_render_target) override;
  104. virtual Vector<BlitToScreen> post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) override;
  105. virtual void end_frame() override;
  106. GDVIRTUAL0(_process);
  107. GDVIRTUAL0(_pre_render);
  108. GDVIRTUAL1R(bool, _pre_draw_viewport, RID);
  109. GDVIRTUAL2(_post_draw_viewport, RID, const Rect2 &);
  110. GDVIRTUAL0(_end_frame);
  111. /* access to some internals we need */
  112. RID get_render_target_texture(RID p_render_target);
  113. // RID get_render_target_depth(RID p_render_target);
  114. };
  115. #endif // XR_INTERFACE_EXTENSION_H