diff options
Diffstat (limited to 'servers/xr')
-rw-r--r-- | servers/xr/xr_interface.cpp | 35 | ||||
-rw-r--r-- | servers/xr/xr_interface.h | 12 | ||||
-rw-r--r-- | servers/xr/xr_interface_extension.cpp | 174 | ||||
-rw-r--r-- | servers/xr/xr_interface_extension.h | 9 |
4 files changed, 108 insertions, 122 deletions
diff --git a/servers/xr/xr_interface.cpp b/servers/xr/xr_interface.cpp index 4b9ea40223..b437ed1512 100644 --- a/servers/xr/xr_interface.cpp +++ b/servers/xr/xr_interface.cpp @@ -68,6 +68,13 @@ void XRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &XRInterface::set_anchor_detection_is_enabled); ClassDB::bind_method(D_METHOD("get_camera_feed_id"), &XRInterface::get_camera_feed_id); + ClassDB::bind_method(D_METHOD("is_passthrough_supported"), &XRInterface::is_passthrough_supported); + ClassDB::bind_method(D_METHOD("is_passthrough_enabled"), &XRInterface::is_passthrough_enabled); + ClassDB::bind_method(D_METHOD("start_passthrough"), &XRInterface::start_passthrough); + ClassDB::bind_method(D_METHOD("stop_passthrough"), &XRInterface::stop_passthrough); + ClassDB::bind_method(D_METHOD("get_transform_for_view", "view", "cam_transform"), &XRInterface::get_transform_for_view); + ClassDB::bind_method(D_METHOD("get_projection_for_view", "view", "aspect", "near", "far"), &XRInterface::get_projection_for_view); + ADD_GROUP("AR", "ar_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled"); @@ -116,6 +123,7 @@ XRInterface::XRInterface() {} XRInterface::~XRInterface() { if (vrs.vrs_texture.is_valid()) { + ERR_FAIL_NULL(RenderingServer::get_singleton()); RS::get_singleton()->free(vrs.vrs_texture); vrs.vrs_texture = RID(); } @@ -160,11 +168,12 @@ RID XRInterface::get_vrs_texture() { // Default logic will return a standard VRS image based on our target size and default projections. // Note that this only gets called if VRS is supported on the hardware. - Size2 texel_size = Size2(16.0, 16.0); // For now we assume we always use 16x16 texels, seems to be the standard. + int32_t texel_width = RD::get_singleton()->limit_get(RD::LIMIT_VRS_TEXEL_WIDTH); + int32_t texel_height = RD::get_singleton()->limit_get(RD::LIMIT_VRS_TEXEL_HEIGHT); int view_count = get_view_count(); Size2 target_size = get_render_target_size(); real_t aspect = target_size.x / target_size.y; // is this y/x ? - Size2 vrs_size = Size2(round(0.5 + target_size.x / texel_size.x), round(0.5 + target_size.y / texel_size.y)); + Size2 vrs_size = Size2(round(0.5 + target_size.x / texel_width), round(0.5 + target_size.y / texel_height)); real_t radius = vrs_size.length() * 0.5; Size2 vrs_sizei = vrs_size; @@ -172,6 +181,8 @@ RID XRInterface::get_vrs_texture() { const uint8_t densities[] = { 0, // 1x1 1, // 1x2 + // 2, // 1x4 - not supported + // 3, // 1x8 - not supported // 4, // 2x1 5, // 2x2 6, // 2x4 @@ -217,12 +228,7 @@ RID XRInterface::get_vrs_texture() { data_ptr[d++] = density; } } - - Ref<Image> image; - image.instantiate(); - image->create_from_data(vrs_sizei.x, vrs_sizei.y, false, Image::FORMAT_R8, data); - - images.push_back(image); + images.push_back(Image::create_from_data(vrs_sizei.x, vrs_sizei.y, false, Image::FORMAT_R8, data)); } if (images.size() == 1) { @@ -236,6 +242,19 @@ RID XRInterface::get_vrs_texture() { } /** these are optional, so we want dummies **/ + +RID XRInterface::get_color_texture() { + return RID(); +} + +RID XRInterface::get_depth_texture() { + return RID(); +} + +RID XRInterface::get_velocity_texture() { + return RID(); +} + PackedStringArray XRInterface::get_suggested_tracker_names() const { PackedStringArray arr; diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h index f11458f1cc..2960074dd2 100644 --- a/servers/xr/xr_interface.h +++ b/servers/xr/xr_interface.h @@ -121,8 +121,9 @@ public: virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) = 0; /* get each views transform */ virtual Projection get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) = 0; /* get each view projection matrix */ virtual RID get_vrs_texture(); /* obtain VRS texture */ - - // note, external color/depth/vrs texture support will be added here soon. + virtual RID get_color_texture(); /* obtain color output texture (if applicable) */ + virtual RID get_depth_texture(); /* obtain depth output texture (if applicable, used for reprojection) */ + virtual RID get_velocity_texture(); /* obtain velocity output texture (if applicable, used for spacewarp) */ virtual void process() = 0; virtual void pre_render(){}; @@ -130,7 +131,12 @@ public: virtual Vector<BlitToScreen> post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) = 0; /* inform XR interface we finished our viewport draw process */ virtual void end_frame(){}; - virtual void notification(int p_what){}; + /** passthrough **/ + + virtual bool is_passthrough_supported() { return false; } + virtual bool is_passthrough_enabled() { return false; } + virtual bool start_passthrough() { return false; } + virtual void stop_passthrough() {} XRInterface(); ~XRInterface(); diff --git a/servers/xr/xr_interface_extension.cpp b/servers/xr/xr_interface_extension.cpp index 7395cd5ad4..2142ecd262 100644 --- a/servers/xr/xr_interface_extension.cpp +++ b/servers/xr/xr_interface_extension.cpp @@ -58,8 +58,6 @@ void XRInterfaceExtension::_bind_methods() { GDVIRTUAL_BIND(_post_draw_viewport, "render_target", "screen_rect"); GDVIRTUAL_BIND(_end_frame); - GDVIRTUAL_BIND(_notification, "what"); - /** input and output **/ GDVIRTUAL_BIND(_get_suggested_tracker_names); @@ -74,6 +72,15 @@ void XRInterfaceExtension::_bind_methods() { GDVIRTUAL_BIND(_set_anchor_detection_is_enabled, "enabled"); GDVIRTUAL_BIND(_get_camera_feed_id); + // override output methods + GDVIRTUAL_BIND(_get_color_texture); + GDVIRTUAL_BIND(_get_depth_texture); + GDVIRTUAL_BIND(_get_velocity_texture); + + ClassDB::bind_method(D_METHOD("get_color_texture"), &XRInterfaceExtension::get_color_texture); + ClassDB::bind_method(D_METHOD("get_depth_texture"), &XRInterfaceExtension::get_depth_texture); + ClassDB::bind_method(D_METHOD("get_velocity_texture"), &XRInterfaceExtension::get_velocity_texture); + // helper methods ClassDB::bind_method(D_METHOD("add_blit", "render_target", "src_rect", "dst_rect", "use_layer", "layer", "apply_lens_distortion", "eye_center", "k1", "k2", "upscale", "aspect_ratio"), &XRInterfaceExtension::add_blit); ClassDB::bind_method(D_METHOD("get_render_target_texture", "render_target"), &XRInterfaceExtension::get_render_target_texture); @@ -91,33 +98,21 @@ StringName XRInterfaceExtension::get_name() const { } uint32_t XRInterfaceExtension::get_capabilities() const { - uint32_t capabilities; - - if (GDVIRTUAL_CALL(_get_capabilities, capabilities)) { - return capabilities; - } - - return 0; + uint32_t capabilities = 0; + GDVIRTUAL_CALL(_get_capabilities, capabilities); + return capabilities; } bool XRInterfaceExtension::is_initialized() const { - bool initialised = false; - - if (GDVIRTUAL_CALL(_is_initialized, initialised)) { - return initialised; - } - - return false; + bool initialized = false; + GDVIRTUAL_CALL(_is_initialized, initialized); + return initialized; } bool XRInterfaceExtension::initialize() { - bool initialised = false; - - if (GDVIRTUAL_CALL(_initialize, initialised)) { - return initialised; - } - - return false; + bool initialized = false; + GDVIRTUAL_CALL(_initialize, initialized); + return initialized; } void XRInterfaceExtension::uninitialize() { @@ -141,13 +136,9 @@ PackedStringArray XRInterfaceExtension::get_suggested_pose_names(const StringNam } XRInterface::TrackingStatus XRInterfaceExtension::get_tracking_status() const { - uint32_t status; - - if (GDVIRTUAL_CALL(_get_tracking_status, status)) { - return TrackingStatus(status); - } - - return XR_UNKNOWN_TRACKING; + uint32_t status = XR_UNKNOWN_TRACKING; + GDVIRTUAL_CALL(_get_tracking_status, status); + return TrackingStatus(status); } void XRInterfaceExtension::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) { @@ -155,52 +146,34 @@ void XRInterfaceExtension::trigger_haptic_pulse(const String &p_action_name, con } bool XRInterfaceExtension::supports_play_area_mode(XRInterface::PlayAreaMode p_mode) { - bool is_supported; - - if (GDVIRTUAL_CALL(_supports_play_area_mode, p_mode, is_supported)) { - return is_supported; - } - - return false; + bool is_supported = false; + GDVIRTUAL_CALL(_supports_play_area_mode, p_mode, is_supported); + return is_supported; } XRInterface::PlayAreaMode XRInterfaceExtension::get_play_area_mode() const { - uint32_t mode; - - if (GDVIRTUAL_CALL(_get_play_area_mode, mode)) { - return XRInterface::PlayAreaMode(mode); - } - - return XRInterface::XR_PLAY_AREA_UNKNOWN; + uint32_t mode = XR_PLAY_AREA_UNKNOWN; + GDVIRTUAL_CALL(_get_play_area_mode, mode); + return XRInterface::PlayAreaMode(mode); } bool XRInterfaceExtension::set_play_area_mode(XRInterface::PlayAreaMode p_mode) { - bool success; - - if (GDVIRTUAL_CALL(_set_play_area_mode, p_mode, success)) { - return success; - } - - return false; + bool success = false; + GDVIRTUAL_CALL(_set_play_area_mode, p_mode, success); + return success; } PackedVector3Array XRInterfaceExtension::get_play_area() const { PackedVector3Array arr; - GDVIRTUAL_CALL(_get_play_area, arr); - return arr; } /** these will only be implemented on AR interfaces, so we want dummies for VR **/ bool XRInterfaceExtension::get_anchor_detection_is_enabled() const { - bool enabled; - - if (GDVIRTUAL_CALL(_get_anchor_detection_is_enabled, enabled)) { - return enabled; - } - - return false; + bool enabled = false; + GDVIRTUAL_CALL(_get_anchor_detection_is_enabled, enabled); + return enabled; } void XRInterfaceExtension::set_anchor_detection_is_enabled(bool p_enable) { @@ -209,53 +182,33 @@ void XRInterfaceExtension::set_anchor_detection_is_enabled(bool p_enable) { } int XRInterfaceExtension::get_camera_feed_id() { - int feed_id; - - if (GDVIRTUAL_CALL(_get_camera_feed_id, feed_id)) { - return feed_id; - } - - return 0; + int feed_id = 0; + GDVIRTUAL_CALL(_get_camera_feed_id, feed_id); + return feed_id; } Size2 XRInterfaceExtension::get_render_target_size() { Size2 size; - - if (GDVIRTUAL_CALL(_get_render_target_size, size)) { - return size; - } - - return Size2(0, 0); + GDVIRTUAL_CALL(_get_render_target_size, size); + return size; } uint32_t XRInterfaceExtension::get_view_count() { - uint32_t view_count; - - if (GDVIRTUAL_CALL(_get_view_count, view_count)) { - return view_count; - } - - return 1; + uint32_t view_count = 1; + GDVIRTUAL_CALL(_get_view_count, view_count); + return view_count; } Transform3D XRInterfaceExtension::get_camera_transform() { Transform3D transform; - - if (GDVIRTUAL_CALL(_get_camera_transform, transform)) { - return transform; - } - - return Transform3D(); + GDVIRTUAL_CALL(_get_camera_transform, transform); + return transform; } Transform3D XRInterfaceExtension::get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) { Transform3D transform; - - if (GDVIRTUAL_CALL(_get_transform_for_view, p_view, p_cam_transform, transform)) { - return transform; - } - - return Transform3D(); + GDVIRTUAL_CALL(_get_transform_for_view, p_view, p_cam_transform, transform); + return transform; } Projection XRInterfaceExtension::get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) { @@ -264,7 +217,7 @@ Projection XRInterfaceExtension::get_projection_for_view(uint32_t p_view, double if (GDVIRTUAL_CALL(_get_projection_for_view, p_view, p_aspect, p_z_near, p_z_far, arr)) { ERR_FAIL_COND_V_MSG(arr.size() != 16, Projection(), "Projection matrix must contain 16 floats"); - real_t *m = (real_t *)cm.matrix; + real_t *m = (real_t *)cm.columns; for (int i = 0; i < 16; i++) { m[i] = arr[i]; } @@ -283,6 +236,24 @@ RID XRInterfaceExtension::get_vrs_texture() { } } +RID XRInterfaceExtension::get_color_texture() { + RID texture; + GDVIRTUAL_CALL(_get_color_texture, texture); + return texture; +} + +RID XRInterfaceExtension::get_depth_texture() { + RID texture; + GDVIRTUAL_CALL(_get_depth_texture, texture); + return texture; +} + +RID XRInterfaceExtension::get_velocity_texture() { + RID texture; + GDVIRTUAL_CALL(_get_velocity_texture, texture); + return texture; +} + void XRInterfaceExtension::add_blit(RID p_render_target, Rect2 p_src_rect, Rect2i p_dst_rect, bool p_use_layer, uint32_t p_layer, bool p_apply_lens_distortion, Vector2 p_eye_center, double p_k1, double p_k2, double p_upscale, double p_aspect_ratio) { BlitToScreen blit; @@ -315,13 +286,8 @@ void XRInterfaceExtension::pre_render() { bool XRInterfaceExtension::pre_draw_viewport(RID p_render_target) { bool do_render = true; - - if (GDVIRTUAL_CALL(_pre_draw_viewport, p_render_target, do_render)) { - return do_render; - } else { - // if not implemented we're returning true - return true; - } + GDVIRTUAL_CALL(_pre_draw_viewport, p_render_target, do_render); + return do_render; // If not implemented we're returning true. } Vector<BlitToScreen> XRInterfaceExtension::post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) { @@ -341,10 +307,6 @@ void XRInterfaceExtension::end_frame() { GDVIRTUAL_CALL(_end_frame); } -void XRInterfaceExtension::notification(int p_what) { - GDVIRTUAL_CALL(_notification, p_what); -} - RID XRInterfaceExtension::get_render_target_texture(RID p_render_target) { // In due time this will need to be enhance to return the correct INTERNAL RID for the chosen rendering engine. // So once a GLES driver is implemented we'll return that and the implemented plugin needs to handle this correctly too. @@ -358,9 +320,5 @@ RID XRInterfaceExtension::get_render_target_texture(RID p_render_target) { RID XRInterfaceExtension::get_render_target_depth(RID p_render_target) { // TODO implement this, the problem is that our depth texture isn't part of our render target as it is used for 3D rendering only // but we don't have access to our render buffers from here.... - RendererSceneRenderRD * rd_scene = ?????; - ERR_FAIL_NULL_V_MSG(rd_scene, RID(), "Renderer scene render not setup"); - - return rd_scene->render_buffers_get_depth_texture(????????????); } */ diff --git a/servers/xr/xr_interface_extension.h b/servers/xr/xr_interface_extension.h index 65b474425e..123626864d 100644 --- a/servers/xr/xr_interface_extension.h +++ b/servers/xr/xr_interface_extension.h @@ -102,6 +102,9 @@ public: virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; virtual Projection get_projection_for_view(uint32_t p_view, double p_aspect, double p_z_near, double p_z_far) override; virtual RID get_vrs_texture() override; + virtual RID get_color_texture() override; + virtual RID get_depth_texture() override; + virtual RID get_velocity_texture() override; GDVIRTUAL0R(Size2, _get_render_target_size); GDVIRTUAL0R(uint32_t, _get_view_count); @@ -109,6 +112,9 @@ public: GDVIRTUAL2R(Transform3D, _get_transform_for_view, uint32_t, const Transform3D &); GDVIRTUAL4R(PackedFloat64Array, _get_projection_for_view, uint32_t, double, double, double); GDVIRTUAL0R(RID, _get_vrs_texture); + GDVIRTUAL0R(RID, _get_color_texture); + GDVIRTUAL0R(RID, _get_depth_texture); + GDVIRTUAL0R(RID, _get_velocity_texture); 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); @@ -117,7 +123,6 @@ public: virtual bool pre_draw_viewport(RID p_render_target) override; virtual Vector<BlitToScreen> post_draw_viewport(RID p_render_target, const Rect2 &p_screen_rect) override; virtual void end_frame() override; - virtual void notification(int p_what) override; GDVIRTUAL0(_process); GDVIRTUAL0(_pre_render); @@ -125,8 +130,6 @@ public: GDVIRTUAL2(_post_draw_viewport, RID, const Rect2 &); GDVIRTUAL0(_end_frame); - GDVIRTUAL1(_notification, int); - /* access to some internals we need */ RID get_render_target_texture(RID p_render_target); // RID get_render_target_depth(RID p_render_target); |