summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2022-07-24 20:43:30 +1000
committerBastiaan Olij <mux213@gmail.com>2022-07-28 11:50:34 +1000
commit1dd671014bdfc714687f91914755ad925aabda5f (patch)
tree4c03669e8695c9900dfe1b6fe8b26c8757bbeb29
parenteac22e3eb489b4a50bb274f10e8a8d4eb795fa99 (diff)
Add startup flag to override XR mode settings
-rw-r--r--main/main.cpp20
-rw-r--r--modules/openxr/openxr_api.cpp15
-rw-r--r--servers/rendering/renderer_compositor.cpp7
-rw-r--r--servers/xr_server.cpp10
-rw-r--r--servers/xr_server.h11
5 files changed, 52 insertions, 11 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 3f9fe34545..3e29323337 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -343,6 +343,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(" --resolution <W>x<H> Request window resolution.\n");
OS::get_singleton()->print(" --position <X>,<Y> Request window position.\n");
OS::get_singleton()->print(" --single-window Use a single window (no separate subwindows).\n");
+ OS::get_singleton()->print(" --xr-mode <mode> Select XR mode (default/off/on).\n");
OS::get_singleton()->print("\n");
OS::get_singleton()->print("Debug options:\n");
@@ -1181,6 +1182,25 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->disable_crash_handler();
} else if (I->get() == "--skip-breakpoints") {
skip_breakpoints = true;
+ } else if (I->get() == "--xr-mode") {
+ if (I->next()) {
+ String xr_mode = I->next()->get().to_lower();
+ N = I->next()->next();
+ if (xr_mode == "default") {
+ XRServer::set_xr_mode(XRServer::XRMODE_DEFAULT);
+ } else if (xr_mode == "off") {
+ XRServer::set_xr_mode(XRServer::XRMODE_OFF);
+ } else if (xr_mode == "on") {
+ XRServer::set_xr_mode(XRServer::XRMODE_ON);
+ } else {
+ OS::get_singleton()->print("Unknown --xr-mode argument \"%s\", aborting.\n", xr_mode.ascii().get_data());
+ goto error;
+ }
+ } else {
+ OS::get_singleton()->print("Missing --xr-mode argument, aborting.\n");
+ goto error;
+ }
+
} else {
main_args.push_back(I->get());
}
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp
index 938b017e3a..92d074cb75 100644
--- a/modules/openxr/openxr_api.cpp
+++ b/modules/openxr/openxr_api.cpp
@@ -58,19 +58,14 @@ bool OpenXRAPI::openxr_is_enabled(bool p_check_run_in_editor) {
// @TODO we need an overrule switch so we can force enable openxr, i.e run "godot --openxr_enabled"
if (Engine::get_singleton()->is_editor_hint() && p_check_run_in_editor) {
-#ifdef TOOLS_ENABLED
// Disabled for now, using XR inside of the editor we'll be working on during the coming months.
return false;
-
- // bool enabled = GLOBAL_GET("xr/openxr/in_editor"); // EDITOR_GET("xr/openxr/in_editor");
- // return enabled;
-#else
- // we should never get here, editor hint won't be true if the editor isn't compiled in.
- return false;
-#endif
} else {
- bool enabled = GLOBAL_GET("xr/openxr/enabled");
- return enabled;
+ if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {
+ return GLOBAL_GET("xr/openxr/enabled");
+ } else {
+ return XRServer::get_xr_mode() == XRServer::XRMODE_ON;
+ }
}
}
diff --git a/servers/rendering/renderer_compositor.cpp b/servers/rendering/renderer_compositor.cpp
index b331ec2c1d..80e71a0df3 100644
--- a/servers/rendering/renderer_compositor.cpp
+++ b/servers/rendering/renderer_compositor.cpp
@@ -33,6 +33,7 @@
#include "core/config/project_settings.h"
#include "core/os/os.h"
#include "core/string/print_string.h"
+#include "servers/xr_server.h"
RendererCompositor *(*RendererCompositor::_create_func)() = nullptr;
bool RendererCompositor::low_end = false;
@@ -46,7 +47,11 @@ bool RendererCompositor::is_xr_enabled() const {
}
RendererCompositor::RendererCompositor() {
- xr_enabled = GLOBAL_GET("xr/shaders/enabled");
+ if (XRServer::get_xr_mode() == XRServer::XRMODE_DEFAULT) {
+ xr_enabled = GLOBAL_GET("xr/shaders/enabled");
+ } else {
+ xr_enabled = XRServer::get_xr_mode() == XRServer::XRMODE_ON;
+ }
}
RendererCanvasRender *RendererCanvasRender::singleton = nullptr;
diff --git a/servers/xr_server.cpp b/servers/xr_server.cpp
index ad61aa94bc..990281d96d 100644
--- a/servers/xr_server.cpp
+++ b/servers/xr_server.cpp
@@ -33,6 +33,16 @@
#include "xr/xr_interface.h"
#include "xr/xr_positional_tracker.h"
+XRServer::XRMode XRServer::xr_mode = XRMODE_DEFAULT;
+
+XRServer::XRMode XRServer::get_xr_mode() {
+ return xr_mode;
+}
+
+void XRServer::set_xr_mode(XRServer::XRMode p_mode) {
+ xr_mode = p_mode;
+}
+
XRServer *XRServer::singleton = nullptr;
XRServer *XRServer::get_singleton() {
diff --git a/servers/xr_server.h b/servers/xr_server.h
index d9188d2de1..74128bfb54 100644
--- a/servers/xr_server.h
+++ b/servers/xr_server.h
@@ -57,6 +57,12 @@ class XRServer : public Object {
_THREAD_SAFE_CLASS_
public:
+ enum XRMode {
+ XRMODE_DEFAULT, /* Default behaviour, means we check project settings */
+ XRMODE_OFF, /* Ignore project settings, disable OpenXR, disable shaders */
+ XRMODE_ON, /* Ignore project settings, enable OpenXR, enable shaders, run editor in VR (if applicable) */
+ };
+
enum TrackerType {
TRACKER_HEAD = 0x01, /* tracks the position of the players head (or in case of handheld AR, location of the phone) */
TRACKER_CONTROLLER = 0x02, /* tracks a controller */
@@ -75,6 +81,8 @@ public:
};
private:
+ static XRMode xr_mode;
+
Vector<Ref<XRInterface>> interfaces;
Dictionary trackers;
@@ -90,6 +98,9 @@ protected:
static void _bind_methods();
public:
+ static XRMode get_xr_mode();
+ static void set_xr_mode(XRMode p_mode);
+
static XRServer *get_singleton();
/*