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