2023-01-05 13:25:55 +01:00
/**************************************************************************/
/* xr_interface.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-05 00:50:27 +01:00
2020-04-08 16:47:36 +02:00
# ifndef XR_INTERFACE_H
# define XR_INTERFACE_H
2017-04-23 14:10:41 +02:00
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
# include "core/math/projection.h"
2018-09-11 18:13:45 +02:00
# include "core/os/thread_safe.h"
2020-04-08 16:47:36 +02:00
# include "servers/xr_server.h"
2024-03-26 02:57:26 +01:00
# include "xr_vrs.h"
2017-04-23 14:10:41 +02:00
2021-05-07 15:19:04 +02:00
// forward declaration
struct BlitToScreen ;
2017-04-23 14:10:41 +02:00
/**
Fix various typos with codespell
Found via `codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,fave,findn,hist,inout,leapyear,lod,nd,numer,ois,ony,paket,seeked,sinc,switchs,te,uint`
2021-07-07 17:17:32 +02:00
The XR interface is a template class on top of which we build interface to different AR , VR and tracking SDKs .
2017-04-23 14:10:41 +02:00
The idea is that we subclass this class , implement the logic , and then instantiate a singleton of each interface
when Godot starts . These instances do not initialize themselves but register themselves with the AR / VR server .
If the user wants to enable AR / VR the choose the interface they want to use and initialize it .
2022-03-09 13:56:14 +01:00
Note that we may make this into a fully instantiable class for GDExtension support .
2017-04-23 14:10:41 +02:00
*/
2021-06-04 18:03:15 +02:00
class XRInterface : public RefCounted {
GDCLASS ( XRInterface , RefCounted ) ;
2017-04-23 14:10:41 +02:00
public :
2023-08-26 17:39:43 +02:00
enum Capabilities { /* purely metadata, provides some info about what this interface supports */
2020-04-08 16:47:36 +02:00
XR_NONE = 0 , /* no capabilities */
XR_MONO = 1 , /* can be used with mono output */
XR_STEREO = 2 , /* can be used with stereo output */
2021-08-29 08:05:11 +02:00
XR_QUAD = 4 , /* can be used with quad output (not currently supported) */
XR_VR = 8 , /* offers VR support */
XR_AR = 16 , /* offers AR support */
XR_EXTERNAL = 32 /* renders to external device */
2017-04-23 14:10:41 +02:00
} ;
2021-08-23 07:23:16 +02:00
enum TrackingStatus { /* tracking status currently based on AR but we can start doing more with this for VR as well */
2020-04-08 16:47:36 +02:00
XR_NORMAL_TRACKING ,
XR_EXCESSIVE_MOTION ,
XR_INSUFFICIENT_FEATURES ,
XR_UNKNOWN_TRACKING ,
XR_NOT_TRACKING
2017-09-29 13:36:27 +02:00
} ;
2021-06-27 13:51:30 +02:00
enum PlayAreaMode { /* defines the mode used by the XR interface for tracking */
XR_PLAY_AREA_UNKNOWN , /* Area mode not set or not available */
XR_PLAY_AREA_3DOF , /* Only support orientation tracking, no positional tracking, area will center around player */
XR_PLAY_AREA_SITTING , /* Player is in seated position, limited positional tracking, fixed guardian around player */
XR_PLAY_AREA_ROOMSCALE , /* Player is free to move around, full positional tracking */
2024-01-15 23:26:55 +01:00
XR_PLAY_AREA_STAGE , /* Same as roomscale but origin point is fixed to the center of the physical space */
2021-06-27 13:51:30 +02:00
} ;
2023-02-02 15:14:16 +01:00
enum EnvironmentBlendMode {
XR_ENV_BLEND_MODE_OPAQUE , /* You cannot see the real world, VR like */
XR_ENV_BLEND_MODE_ADDITIVE , /* You can see the real world, AR like */
XR_ENV_BLEND_MODE_ALPHA_BLEND , /* Real world is passed through where alpha channel is 0.0 and gradually blends to opaque for value 1.0. */
} ;
2017-09-29 13:36:27 +02:00
protected :
_THREAD_SAFE_CLASS_
static void _bind_methods ( ) ;
public :
/** general interface information **/
2021-08-23 07:23:16 +02:00
virtual StringName get_name ( ) const = 0 ;
virtual uint32_t get_capabilities ( ) const = 0 ;
2017-04-23 14:10:41 +02:00
bool is_primary ( ) ;
2021-08-23 07:23:16 +02:00
void set_primary ( bool p_is_primary ) ;
2017-04-23 14:10:41 +02:00
2018-07-25 03:11:03 +02:00
virtual bool is_initialized ( ) const = 0 ; /* returns true if we've initialized this interface */
2017-04-23 14:10:41 +02:00
virtual bool initialize ( ) = 0 ; /* initialize this interface, if this has an HMD it becomes the primary interface */
virtual void uninitialize ( ) = 0 ; /* deinitialize this interface */
2023-03-13 02:26:10 +01:00
virtual Dictionary get_system_info ( ) = 0 ; /* return a dictionary with info about our system */
2017-04-23 14:10:41 +02:00
2021-08-29 08:05:11 +02:00
/** input and output **/
virtual PackedStringArray get_suggested_tracker_names ( ) const ; /* return a list of likely/suggested tracker names */
virtual PackedStringArray get_suggested_pose_names ( const StringName & p_tracker_name ) const ; /* return a list of likely/suggested action names for this tracker */
2021-08-23 07:23:16 +02:00
virtual TrackingStatus get_tracking_status ( ) const ; /* get the status of our current tracking */
2021-08-29 08:05:11 +02:00
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 ) ; /* trigger a haptic pulse */
2017-09-29 13:36:27 +02:00
/** specific to VR **/
2021-06-27 13:51:30 +02:00
virtual bool supports_play_area_mode ( XRInterface : : PlayAreaMode p_mode ) ; /* query if this interface supports this play area mode */
virtual XRInterface : : PlayAreaMode get_play_area_mode ( ) const ; /* get the current play area mode */
virtual bool set_play_area_mode ( XRInterface : : PlayAreaMode p_mode ) ; /* change the play area mode, note that this should return false if the mode is not available */
virtual PackedVector3Array get_play_area ( ) const ; /* if available, returns an array of vectors denoting the play area the player can move around in */
2017-09-29 13:36:27 +02:00
/** specific to AR **/
virtual bool get_anchor_detection_is_enabled ( ) const ;
virtual void set_anchor_detection_is_enabled ( bool p_enable ) ;
2017-08-20 16:17:24 +02:00
virtual int get_camera_feed_id ( ) ;
2017-09-29 13:36:27 +02:00
/** rendering and internal **/
2024-03-21 08:58:24 +01:00
// These methods are called from the main thread.
virtual Transform3D get_camera_transform ( ) = 0 ; /* returns the position of our camera, only used for updating reference frame. For monoscopic this is equal to the views transform, for stereoscopic this should be an average */
virtual void process ( ) = 0 ;
// These methods can be called from both main and render thread.
2021-08-23 07:23:16 +02:00
virtual Size2 get_render_target_size ( ) = 0 ; /* returns the recommended render target size per eye for this device */
2021-05-07 15:19:04 +02:00
virtual uint32_t get_view_count ( ) = 0 ; /* returns the view count we need (1 is monoscopic, 2 is stereoscopic but can be more) */
2024-03-21 08:58:24 +01:00
// These methods are called from the rendering thread.
2021-05-07 15:19:04 +02:00
virtual Transform3D get_transform_for_view ( uint32_t p_view , const Transform3D & p_cam_transform ) = 0 ; /* get each views transform */
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
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 */
2022-09-01 10:10:53 +02:00
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) */
2022-01-26 02:25:20 +01:00
virtual void pre_render ( ) { } ;
virtual bool pre_draw_viewport ( RID p_render_target ) { return true ; } ; /* inform XR interface we are about to start our viewport draw process */
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 ( ) { } ;
2022-09-26 09:04:12 +02:00
/** 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 ( ) { }
2024-03-26 02:57:26 +01:00
/** environment blend mode **/
2023-02-02 15:14:16 +01:00
virtual Array get_supported_environment_blend_modes ( ) ;
2023-09-12 04:39:48 +02:00
virtual XRInterface : : EnvironmentBlendMode get_environment_blend_mode ( ) const { return XR_ENV_BLEND_MODE_OPAQUE ; }
2023-02-02 15:14:16 +01:00
virtual bool set_environment_blend_mode ( EnvironmentBlendMode mode ) { return false ; }
2024-03-26 02:57:26 +01:00
/** VRS **/
virtual RID get_vrs_texture ( ) ; /* obtain VRS texture */
2020-04-08 16:47:36 +02:00
XRInterface ( ) ;
~ XRInterface ( ) ;
2017-04-23 14:10:41 +02:00
} ;
2020-04-08 16:47:36 +02:00
VARIANT_ENUM_CAST ( XRInterface : : Capabilities ) ;
2021-08-23 07:23:16 +02:00
VARIANT_ENUM_CAST ( XRInterface : : TrackingStatus ) ;
2021-06-27 13:51:30 +02:00
VARIANT_ENUM_CAST ( XRInterface : : PlayAreaMode ) ;
2023-02-02 15:14:16 +01:00
VARIANT_ENUM_CAST ( XRInterface : : EnvironmentBlendMode ) ;
2017-04-23 14:10:41 +02:00
2022-01-04 20:26:22 +01:00
# endif // XR_INTERFACE_H