summaryrefslogtreecommitdiff
path: root/servers/xr
diff options
context:
space:
mode:
Diffstat (limited to 'servers/xr')
-rw-r--r--servers/xr/xr_interface.cpp7
-rw-r--r--servers/xr/xr_interface.h29
-rw-r--r--servers/xr/xr_positional_tracker.cpp60
-rw-r--r--servers/xr/xr_positional_tracker.h34
4 files changed, 69 insertions, 61 deletions
diff --git a/servers/xr/xr_interface.cpp b/servers/xr/xr_interface.cpp
index e9858416ec..09e8e12f8b 100644
--- a/servers/xr/xr_interface.cpp
+++ b/servers/xr/xr_interface.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "xr_interface.h"
+#include "servers/rendering/renderer_compositor.h"
void XRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_name"), &XRInterface::get_name);
@@ -45,7 +46,7 @@ void XRInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tracking_status"), &XRInterface::get_tracking_status);
ClassDB::bind_method(D_METHOD("get_render_targetsize"), &XRInterface::get_render_targetsize);
- ClassDB::bind_method(D_METHOD("is_stereo"), &XRInterface::is_stereo);
+ ClassDB::bind_method(D_METHOD("get_view_count"), &XRInterface::get_view_count);
ADD_GROUP("Interface", "interface_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary");
diff --git a/servers/xr/xr_interface.h b/servers/xr/xr_interface.h
index 99fcef7925..6b248c9554 100644
--- a/servers/xr/xr_interface.h
+++ b/servers/xr/xr_interface.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,13 +33,15 @@
#include "core/math/camera_matrix.h"
#include "core/os/thread_safe.h"
-#include "scene/main/window.h"
#include "servers/xr_server.h"
+// forward declaration
+struct BlitToScreen;
+
/**
@author Bastiaan Olij <mux213@gmail.com>
- The XR interface is a template class ontop of which we build interface to different AR, VR and tracking SDKs.
+ The XR interface is a template class on top of which we build interface to different AR, VR and tracking SDKs.
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.
@@ -48,8 +50,8 @@
Note that we may make this into a fully instantiable class for GDNative support.
*/
-class XRInterface : public Reference {
- GDCLASS(XRInterface, Reference);
+class XRInterface : public RefCounted {
+ GDCLASS(XRInterface, RefCounted);
public:
enum Capabilities { /* purely meta data, provides some info about what this interface supports */
@@ -106,17 +108,22 @@ public:
/** rendering and internal **/
virtual Size2 get_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */
- virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */
- virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */
- virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) = 0; /* get each eyes projection matrix */
- virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); /* if applicable return external texture to render to */
- virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */
+ virtual uint32_t get_view_count() = 0; /* returns the view count we need (1 is monoscopic, 2 is stereoscopic but can be more) */
+ virtual Transform3D get_camera_transform() = 0; /* returns the position of our camera for updating our camera node. For monoscopic this is equal to the views transform, for stereoscopic this should be an average */
+ virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) = 0; /* get each views transform */
+ virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) = 0; /* get each view projection matrix */
+
+ virtual Vector<BlitToScreen> commit_views(RID p_render_target, const Rect2 &p_screen_rect) = 0; /* commit rendered views to the XR interface */
virtual void process() = 0;
virtual void notification(int p_what) = 0;
XRInterface();
~XRInterface();
+
+ // deprecated
+ virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); /* if applicable return external texture to render to */
+ virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */
};
VARIANT_ENUM_CAST(XRInterface::Capabilities);
diff --git a/servers/xr/xr_positional_tracker.cpp b/servers/xr/xr_positional_tracker.cpp
index ad5cee92ea..e9383db941 100644
--- a/servers/xr/xr_positional_tracker.cpp
+++ b/servers/xr/xr_positional_tracker.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,25 +34,25 @@
void XRPositionalTracker::_bind_methods() {
BIND_ENUM_CONSTANT(TRACKER_HAND_UNKNOWN);
- BIND_ENUM_CONSTANT(TRACKER_LEFT_HAND);
- BIND_ENUM_CONSTANT(TRACKER_RIGHT_HAND);
+ BIND_ENUM_CONSTANT(TRACKER_HAND_LEFT);
+ BIND_ENUM_CONSTANT(TRACKER_HAND_RIGHT);
// this class is read only from GDScript, so we only have access to getters..
- ClassDB::bind_method(D_METHOD("get_type"), &XRPositionalTracker::get_type);
+ ClassDB::bind_method(D_METHOD("get_tracker_type"), &XRPositionalTracker::get_tracker_type);
ClassDB::bind_method(D_METHOD("get_tracker_id"), &XRPositionalTracker::get_tracker_id);
- ClassDB::bind_method(D_METHOD("get_name"), &XRPositionalTracker::get_name);
+ ClassDB::bind_method(D_METHOD("get_tracker_name"), &XRPositionalTracker::get_tracker_name);
ClassDB::bind_method(D_METHOD("get_joy_id"), &XRPositionalTracker::get_joy_id);
- ClassDB::bind_method(D_METHOD("get_tracks_orientation"), &XRPositionalTracker::get_tracks_orientation);
+ ClassDB::bind_method(D_METHOD("is_tracking_orientation"), &XRPositionalTracker::is_tracking_orientation);
ClassDB::bind_method(D_METHOD("get_orientation"), &XRPositionalTracker::get_orientation);
- ClassDB::bind_method(D_METHOD("get_tracks_position"), &XRPositionalTracker::get_tracks_position);
+ ClassDB::bind_method(D_METHOD("is_tracking_position"), &XRPositionalTracker::is_tracking_position);
ClassDB::bind_method(D_METHOD("get_position"), &XRPositionalTracker::get_position);
- ClassDB::bind_method(D_METHOD("get_hand"), &XRPositionalTracker::get_hand);
+ ClassDB::bind_method(D_METHOD("get_tracker_hand"), &XRPositionalTracker::get_tracker_hand);
ClassDB::bind_method(D_METHOD("get_transform", "adjust_by_reference_frame"), &XRPositionalTracker::get_transform);
ClassDB::bind_method(D_METHOD("get_mesh"), &XRPositionalTracker::get_mesh);
// these functions we don't want to expose to normal users but do need to be callable from GDNative
- ClassDB::bind_method(D_METHOD("_set_type", "type"), &XRPositionalTracker::set_type);
- ClassDB::bind_method(D_METHOD("_set_name", "name"), &XRPositionalTracker::set_name);
+ ClassDB::bind_method(D_METHOD("_set_tracker_type", "type"), &XRPositionalTracker::set_tracker_type);
+ ClassDB::bind_method(D_METHOD("_set_tracker_name", "name"), &XRPositionalTracker::set_tracker_name);
ClassDB::bind_method(D_METHOD("_set_joy_id", "joy_id"), &XRPositionalTracker::set_joy_id);
ClassDB::bind_method(D_METHOD("_set_orientation", "orientation"), &XRPositionalTracker::set_orientation);
ClassDB::bind_method(D_METHOD("_set_rw_position", "rw_position"), &XRPositionalTracker::set_rw_position);
@@ -63,7 +63,7 @@ void XRPositionalTracker::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rumble"), "set_rumble", "get_rumble");
};
-void XRPositionalTracker::set_type(XRServer::TrackerType p_type) {
+void XRPositionalTracker::set_tracker_type(XRServer::TrackerType p_type) {
if (type != p_type) {
type = p_type;
hand = XRPositionalTracker::TRACKER_HAND_UNKNOWN;
@@ -77,15 +77,15 @@ void XRPositionalTracker::set_type(XRServer::TrackerType p_type) {
};
};
-XRServer::TrackerType XRPositionalTracker::get_type() const {
+XRServer::TrackerType XRPositionalTracker::get_tracker_type() const {
return type;
};
-void XRPositionalTracker::set_name(const String &p_name) {
+void XRPositionalTracker::set_tracker_name(const String &p_name) {
name = p_name;
};
-StringName XRPositionalTracker::get_name() const {
+StringName XRPositionalTracker::get_tracker_name() const {
return name;
};
@@ -101,14 +101,14 @@ int XRPositionalTracker::get_joy_id() const {
return joy_id;
};
-bool XRPositionalTracker::get_tracks_orientation() const {
- return tracks_orientation;
+bool XRPositionalTracker::is_tracking_orientation() const {
+ return tracking_orientation;
};
void XRPositionalTracker::set_orientation(const Basis &p_orientation) {
_THREAD_SAFE_METHOD_
- tracks_orientation = true; // obviously we have this
+ tracking_orientation = true; // obviously we have this
orientation = p_orientation;
};
@@ -118,8 +118,8 @@ Basis XRPositionalTracker::get_orientation() const {
return orientation;
};
-bool XRPositionalTracker::get_tracks_position() const {
- return tracks_position;
+bool XRPositionalTracker::is_tracking_position() const {
+ return tracking_position;
};
void XRPositionalTracker::set_position(const Vector3 &p_position) {
@@ -130,7 +130,7 @@ void XRPositionalTracker::set_position(const Vector3 &p_position) {
real_t world_scale = xr_server->get_world_scale();
ERR_FAIL_COND(world_scale == 0);
- tracks_position = true; // obviously we have this
+ tracking_position = true; // obviously we have this
rw_position = p_position / world_scale;
};
@@ -147,7 +147,7 @@ Vector3 XRPositionalTracker::get_position() const {
void XRPositionalTracker::set_rw_position(const Vector3 &p_rw_position) {
_THREAD_SAFE_METHOD_
- tracks_position = true; // obviously we have this
+ tracking_position = true; // obviously we have this
rw_position = p_rw_position;
};
@@ -169,11 +169,11 @@ Ref<Mesh> XRPositionalTracker::get_mesh() const {
return mesh;
};
-XRPositionalTracker::TrackerHand XRPositionalTracker::get_hand() const {
+XRPositionalTracker::TrackerHand XRPositionalTracker::get_tracker_hand() const {
return hand;
};
-void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand) {
+void XRPositionalTracker::set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand) {
XRServer *xr_server = XRServer::get_singleton();
ERR_FAIL_NULL(xr_server);
@@ -182,11 +182,11 @@ void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand
ERR_FAIL_COND((type != XRServer::TRACKER_CONTROLLER) && (p_hand != XRPositionalTracker::TRACKER_HAND_UNKNOWN));
hand = p_hand;
- if (hand == XRPositionalTracker::TRACKER_LEFT_HAND) {
+ if (hand == XRPositionalTracker::TRACKER_HAND_LEFT) {
if (!xr_server->is_tracker_id_in_use_for_type(type, 1)) {
tracker_id = 1;
};
- } else if (hand == XRPositionalTracker::TRACKER_RIGHT_HAND) {
+ } else if (hand == XRPositionalTracker::TRACKER_HAND_RIGHT) {
if (!xr_server->is_tracker_id_in_use_for_type(type, 2)) {
tracker_id = 2;
};
@@ -194,8 +194,8 @@ void XRPositionalTracker::set_hand(const XRPositionalTracker::TrackerHand p_hand
};
};
-Transform XRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const {
- Transform new_transform;
+Transform3D XRPositionalTracker::get_transform(bool p_adjust_by_reference_frame) const {
+ Transform3D new_transform;
new_transform.basis = get_orientation();
new_transform.origin = get_position();
@@ -227,8 +227,8 @@ XRPositionalTracker::XRPositionalTracker() {
name = "Unknown";
joy_id = -1;
tracker_id = 0;
- tracks_orientation = false;
- tracks_position = false;
+ tracking_orientation = false;
+ tracking_position = false;
hand = TRACKER_HAND_UNKNOWN;
rumble = 0.0;
};
diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h
index 515359e9b1..5577582929 100644
--- a/servers/xr/xr_positional_tracker.h
+++ b/servers/xr/xr_positional_tracker.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -43,15 +43,15 @@
This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking.
*/
-class XRPositionalTracker : public Object {
- GDCLASS(XRPositionalTracker, Object);
+class XRPositionalTracker : public RefCounted {
+ GDCLASS(XRPositionalTracker, RefCounted);
_THREAD_SAFE_CLASS_
public:
enum TrackerHand {
TRACKER_HAND_UNKNOWN, /* unknown or not applicable */
- TRACKER_LEFT_HAND, /* controller is the left hand controller */
- TRACKER_RIGHT_HAND /* controller is the right hand controller */
+ TRACKER_HAND_LEFT, /* controller is the left hand controller */
+ TRACKER_HAND_RIGHT /* controller is the right hand controller */
};
private:
@@ -59,9 +59,9 @@ private:
StringName name; // (unique) name of the tracker
int tracker_id; // tracker index id that is unique per type
int joy_id; // if we also have a related joystick entity, the id of the joystick
- bool tracks_orientation; // do we track orientation?
+ bool tracking_orientation; // do we track orientation?
Basis orientation; // our orientation
- bool tracks_position; // do we track position?
+ bool tracking_position; // do we track position?
Vector3 rw_position; // our position "in the real world, so without world_scale applied"
Ref<Mesh> mesh; // when available, a mesh that can be used to render this tracker
TrackerHand hand; // if known, the hand this tracker is held in
@@ -71,29 +71,29 @@ protected:
static void _bind_methods();
public:
- void set_type(XRServer::TrackerType p_type);
- XRServer::TrackerType get_type() const;
- void set_name(const String &p_name);
- StringName get_name() const;
+ void set_tracker_type(XRServer::TrackerType p_type);
+ XRServer::TrackerType get_tracker_type() const;
+ void set_tracker_name(const String &p_name);
+ StringName get_tracker_name() const;
int get_tracker_id() const;
void set_joy_id(int p_joy_id);
int get_joy_id() const;
- bool get_tracks_orientation() const;
+ bool is_tracking_orientation() const;
void set_orientation(const Basis &p_orientation);
Basis get_orientation() const;
- bool get_tracks_position() const;
+ bool is_tracking_position() const;
void set_position(const Vector3 &p_position); // set position with world_scale applied
Vector3 get_position() const; // get position with world_scale applied
void set_rw_position(const Vector3 &p_rw_position);
Vector3 get_rw_position() const;
- XRPositionalTracker::TrackerHand get_hand() const;
- void set_hand(const XRPositionalTracker::TrackerHand p_hand);
+ XRPositionalTracker::TrackerHand get_tracker_hand() const;
+ void set_tracker_hand(const XRPositionalTracker::TrackerHand p_hand);
real_t get_rumble() const;
void set_rumble(real_t p_rumble);
void set_mesh(const Ref<Mesh> &p_mesh);
Ref<Mesh> get_mesh() const;
- Transform get_transform(bool p_adjust_by_reference_frame) const;
+ Transform3D get_transform(bool p_adjust_by_reference_frame) const;
XRPositionalTracker();
~XRPositionalTracker() {}