Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable XR server when compiling without 3D #89411

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@
#include "servers/navigation_server_3d.h"
#include "servers/navigation_server_3d_dummy.h"
#include "servers/physics_server_2d.h"
#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#endif // _3D_DISABLED
#include "servers/register_server_types.h"
#include "servers/rendering/rendering_server_default.h"
#include "servers/text/text_server_dummy.h"
#include "servers/text_server.h"

#ifndef _3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/xr_server.h"
#endif // _3D_DISABLED

#ifdef TESTS_ENABLED
#include "tests/test_main.h"
Expand Down Expand Up @@ -144,17 +145,17 @@ static AudioServer *audio_server = nullptr;
static DisplayServer *display_server = nullptr;
static RenderingServer *rendering_server = nullptr;
static CameraServer *camera_server = nullptr;
static XRServer *xr_server = nullptr;
static TextServerManager *tsman = nullptr;
#ifndef _3D_DISABLED
static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
static PhysicsServer3D *physics_server_3d = nullptr;
#endif // _3D_DISABLED
static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
static PhysicsServer2D *physics_server_2d = nullptr;
static NavigationServer3D *navigation_server_3d = nullptr;
static NavigationServer2D *navigation_server_2d = nullptr;
static ThemeDB *theme_db = nullptr;
#ifndef _3D_DISABLED
static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
static PhysicsServer3D *physics_server_3d = nullptr;
static XRServer *xr_server = nullptr;
#endif // _3D_DISABLED
// We error out if setup2() doesn't turn this true
static bool _start_success = false;

Expand Down Expand Up @@ -1646,6 +1647,7 @@ 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;
#ifndef _3D_DISABLED
} else if (I->get() == "--xr-mode") {
if (I->next()) {
String xr_mode = I->next()->get().to_lower();
Expand All @@ -1664,7 +1666,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
OS::get_singleton()->print("Missing --xr-mode argument, aborting.\n");
goto error;
}

#endif // _3D_DISABLED
} else if (I->get() == "--benchmark") {
OS::get_singleton()->set_use_benchmark(true);
} else if (I->get() == "--benchmark-file") {
Expand Down Expand Up @@ -2788,6 +2790,7 @@ Error Main::setup2() {
OS::get_singleton()->benchmark_end_measure("Servers", "Audio");
}

#ifndef _3D_DISABLED
/* Initialize XR Server */

{
Expand All @@ -2797,6 +2800,7 @@ Error Main::setup2() {

OS::get_singleton()->benchmark_end_measure("Servers", "XR");
}
#endif // _3D_DISABLED

OS::get_singleton()->benchmark_end_measure("Startup", "Servers");

Expand Down Expand Up @@ -3942,7 +3946,9 @@ bool Main::iteration() {
bool exit = false;

// process all our active interfaces
#ifndef _3D_DISABLED
XRServer::get_singleton()->_process();
#endif // _3D_DISABLED

NavigationServer2D::get_singleton()->sync();
NavigationServer3D::get_singleton()->sync();
Expand Down Expand Up @@ -4161,11 +4167,13 @@ void Main::cleanup(bool p_force) {
//clear global shader variables before scene and other graphics stuff are deinitialized.
rendering_server->global_shader_parameters_clear();

#ifndef _3D_DISABLED
if (xr_server) {
// Now that we're unregistering properly in plugins we need to keep access to xr_server for a little longer
// We do however unset our primary interface
xr_server->set_primary_interface(Ref<XRInterface>());
}
#endif // _3D_DISABLED

#ifdef TOOLS_ENABLED
GDExtensionManager::get_singleton()->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
Expand Down Expand Up @@ -4195,9 +4203,11 @@ void Main::cleanup(bool p_force) {

EngineDebugger::deinitialize();

#ifndef _3D_DISABLED
if (xr_server) {
memdelete(xr_server);
}
#endif // _3D_DISABLED

if (audio_server) {
audio_server->finish();
Expand Down
22 changes: 12 additions & 10 deletions servers/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp")
env.add_source_files(env.servers_sources, "register_server_types.cpp")
env.add_source_files(env.servers_sources, "rendering_server.cpp")
env.add_source_files(env.servers_sources, "text_server.cpp")
env.add_source_files(env.servers_sources, "xr_server.cpp")

SConscript("xr/SCsub")
SConscript("camera/SCsub")
if not env["disable_3d"]:
SConscript("physics_3d/SCsub")
env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
SConscript("physics_2d/SCsub")
SConscript("rendering/SCsub")
SConscript("audio/SCsub")
SConscript("text/SCsub")
SConscript("camera/SCsub")
SConscript("debugger/SCsub")
SConscript("extensions/SCsub")
SConscript("movie_writer/SCsub")
SConscript("navigation/SCsub")
SConscript("rendering/SCsub")
SConscript("text/SCsub")

SConscript("physics_2d/SCsub")

if not env["disable_3d"]:
SConscript("physics_3d/SCsub")
env.add_source_files(env.servers_sources, "physics_server_3d.cpp")
env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp")
SConscript("xr/SCsub")
env.add_source_files(env.servers_sources, "xr_server.cpp")

lib = env.add_library("servers", env.servers_sources)

Expand Down
60 changes: 31 additions & 29 deletions servers/register_server_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@
#include "text/text_server_dummy.h"
#include "text/text_server_extension.h"
#include "text_server.h"
#include "xr/xr_body_tracker.h"
#include "xr/xr_face_tracker.h"
#include "xr/xr_hand_tracker.h"
#include "xr/xr_interface.h"
#include "xr/xr_interface_extension.h"
#include "xr/xr_positional_tracker.h"
#include "xr_server.h"

// 2D physics and navigation.
#include "navigation_server_2d.h"
Expand All @@ -99,6 +92,13 @@
#include "physics_server_3d.h"
#include "physics_server_3d_wrap_mt.h"
#include "servers/extensions/physics_server_3d_extension.h"
#include "xr/xr_body_tracker.h"
#include "xr/xr_face_tracker.h"
#include "xr/xr_hand_tracker.h"
#include "xr/xr_interface.h"
#include "xr/xr_interface_extension.h"
#include "xr/xr_positional_tracker.h"
#include "xr_server.h"
#endif // _3D_DISABLED

ShaderTypes *shader_types = nullptr;
Expand Down Expand Up @@ -165,26 +165,10 @@ void register_server_types() {

GDREGISTER_CLASS(NativeMenu);

GDREGISTER_ABSTRACT_CLASS(NavigationServer2D);
GDREGISTER_ABSTRACT_CLASS(NavigationServer3D);
GDREGISTER_CLASS(NavigationPathQueryParameters2D);
GDREGISTER_CLASS(NavigationPathQueryParameters3D);
GDREGISTER_CLASS(NavigationPathQueryResult2D);
GDREGISTER_CLASS(NavigationPathQueryResult3D);

GDREGISTER_CLASS(XRServer);
GDREGISTER_CLASS(CameraServer);

GDREGISTER_ABSTRACT_CLASS(RenderingDevice);

GDREGISTER_CLASS(XRBodyTracker);
GDREGISTER_ABSTRACT_CLASS(XRInterface);
GDREGISTER_CLASS(XRHandTracker);
GDREGISTER_CLASS(XRInterfaceExtension); // can't register this as virtual because we need a creation function for our extensions.
GDREGISTER_CLASS(XRPose);
GDREGISTER_CLASS(XRPositionalTracker);
GDREGISTER_CLASS(XRFaceTracker);

GDREGISTER_CLASS(AudioStream);
GDREGISTER_CLASS(AudioStreamPlayback);
GDREGISTER_VIRTUAL_CLASS(AudioStreamPlaybackResampled);
Expand Down Expand Up @@ -303,6 +287,10 @@ void register_server_types() {
PhysicsServer2DManager::get_singleton()->register_server("GodotPhysics2D", callable_mp_static(_createGodotPhysics2DCallback));
PhysicsServer2DManager::get_singleton()->set_default_server("GodotPhysics2D");

GDREGISTER_ABSTRACT_CLASS(NavigationServer2D);
GDREGISTER_CLASS(NavigationPathQueryParameters2D);
GDREGISTER_CLASS(NavigationPathQueryResult2D);

#ifndef _3D_DISABLED
// Physics 3D
GDREGISTER_CLASS(PhysicsServer3DManager);
Expand Down Expand Up @@ -332,8 +320,21 @@ void register_server_types() {

PhysicsServer3DManager::get_singleton()->register_server("GodotPhysics3D", callable_mp_static(_createGodotPhysics3DCallback));
PhysicsServer3DManager::get_singleton()->set_default_server("GodotPhysics3D");

GDREGISTER_ABSTRACT_CLASS(XRInterface);
GDREGISTER_CLASS(XRBodyTracker);
GDREGISTER_CLASS(XRFaceTracker);
GDREGISTER_CLASS(XRHandTracker);
GDREGISTER_CLASS(XRInterfaceExtension); // can't register this as virtual because we need a creation function for our extensions.
GDREGISTER_CLASS(XRPose);
GDREGISTER_CLASS(XRPositionalTracker);
GDREGISTER_CLASS(XRServer);
#endif // _3D_DISABLED

GDREGISTER_ABSTRACT_CLASS(NavigationServer3D);
GDREGISTER_CLASS(NavigationPathQueryParameters3D);
GDREGISTER_CLASS(NavigationPathQueryResult3D);

writer_mjpeg = memnew(MovieWriterMJPEG);
MovieWriter::add_writer(writer_mjpeg);

Expand All @@ -357,18 +358,19 @@ void unregister_server_types() {
void register_server_singletons() {
OS::get_singleton()->benchmark_begin_measure("Servers", "Register Singletons");

Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("NativeMenu", NativeMenu::get_singleton(), "NativeMenu"));
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D"));
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));

Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D"));
#ifndef _3D_DISABLED
Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D"));
#endif // _3D_DISABLED
Engine::get_singleton()->add_singleton(Engine::Singleton("NativeMenu", NativeMenu::get_singleton(), "NativeMenu"));
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D"));
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
#endif // _3D_DISABLED

OS::get_singleton()->benchmark_end_measure("Servers", "Register Singletons");
}
2 changes: 2 additions & 0 deletions servers/rendering/renderer_compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ bool RendererCompositor::is_xr_enabled() const {
RendererCompositor::RendererCompositor() {
singleton = this;

#ifndef _3D_DISABLED
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;
}
#endif // _3D_DISABLED
}
5 changes: 5 additions & 0 deletions servers/rendering/renderer_rd/effects/vrs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
#include "../renderer_compositor_rd.h"
#include "../storage_rd/texture_storage.h"
#include "../uniform_set_cache_rd.h"

#ifndef _3D_DISABLED
#include "servers/xr_server.h"
#endif // _3D_DISABLED

using namespace RendererRD;

Expand Down Expand Up @@ -124,6 +127,7 @@ void VRS::update_vrs_texture(RID p_vrs_fb, RID p_render_target) {
copy_vrs(rd_texture, p_vrs_fb, layers > 1);
}
}
#ifndef _3D_DISABLED
} else if (vrs_mode == RS::VIEWPORT_VRS_XR) {
Ref<XRInterface> interface = XRServer::get_singleton()->get_primary_interface();
if (interface.is_valid()) {
Expand All @@ -138,6 +142,7 @@ void VRS::update_vrs_texture(RID p_vrs_fb, RID p_render_target) {
}
}
}
#endif // _3D_DISABLED
}

RD::get_singleton()->draw_command_end_label();
Expand Down
3 changes: 3 additions & 0 deletions servers/rendering/renderer_scene_cull.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
#include "servers/rendering/rendering_method.h"
#include "servers/rendering/rendering_server_globals.h"
#include "servers/rendering/storage/utilities.h"

#ifndef _3D_DISABLED
#include "servers/xr/xr_interface.h"
#endif // _3D_DISABLED

class RenderingLightCuller;

Expand Down
14 changes: 12 additions & 2 deletions servers/rendering/renderer_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void RendererViewport::_configure_3d_render_buffers(Viewport *p_viewport) {
}

void RendererViewport::_draw_3d(Viewport *p_viewport) {
#ifndef _3D_DISABLED
RENDER_TIMESTAMP("> Render 3D Scene");

Ref<XRInterface> xr_interface;
Expand All @@ -246,6 +247,7 @@ void RendererViewport::_draw_3d(Viewport *p_viewport) {
RSG::scene->render_camera(p_viewport->render_buffers, p_viewport->camera, p_viewport->scenario, p_viewport->self, p_viewport->internal_size, p_viewport->jitter_phase_count, screen_mesh_lod_threshold, p_viewport->shadow_atlas, xr_interface, &p_viewport->render_info);

RENDER_TIMESTAMP("< Render 3D Scene");
#endif // _3D_DISABLED
}

void RendererViewport::_draw_viewport(Viewport *p_viewport) {
Expand Down Expand Up @@ -629,6 +631,7 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) {
void RendererViewport::draw_viewports(bool p_swap_buffers) {
timestamp_vp_map.clear();

#ifndef _3D_DISABLED
// get our xr interface in case we need it
Ref<XRInterface> xr_interface;
XRServer *xr_server = XRServer::get_singleton();
Expand All @@ -639,6 +642,7 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
// retrieve the interface responsible for rendering
xr_interface = xr_server->get_primary_interface();
}
#endif // _3D_DISABLED

if (Engine::get_singleton()->is_editor_hint()) {
set_default_clear_color(GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
Expand Down Expand Up @@ -671,6 +675,7 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {

bool visible = vp->viewport_to_screen_rect != Rect2();

#ifndef _3D_DISABLED
if (vp->use_xr) {
if (xr_interface.is_valid()) {
// Ignore update mode we have to commit frames to our XR interface
Expand All @@ -684,7 +689,9 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
visible = false;
vp->size = Size2();
}
} else {
} else
#endif // _3D_DISABLED
{
if (vp->update_mode == RS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == RS::VIEWPORT_UPDATE_ONCE) {
visible = true;
}
Expand Down Expand Up @@ -722,6 +729,7 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
RENDER_TIMESTAMP("> Render Viewport " + itos(i));

RSG::texture_storage->render_target_set_as_unused(vp->render_target);
#ifndef _3D_DISABLED
if (vp->use_xr && xr_interface.is_valid()) {
// Inform XR interface we're about to render its viewport,
// if this returns false we don't render.
Expand Down Expand Up @@ -758,7 +766,9 @@ void RendererViewport::draw_viewports(bool p_swap_buffers) {
RSG::rasterizer->end_viewport(p_swap_buffers && blits.size() > 0);
}
}
} else {
} else
#endif // _3D_DISABLED
{
RSG::texture_storage->render_target_set_override(vp->render_target, RID(), RID(), RID());

RSG::scene->set_debug_draw_mode(vp->debug_draw);
Expand Down
5 changes: 4 additions & 1 deletion servers/rendering/renderer_viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
#include "servers/rendering/renderer_scene_render.h"
#include "servers/rendering/rendering_method.h"
#include "servers/rendering_server.h"
#include "servers/xr/xr_interface.h"
#include "storage/render_scene_buffers.h"

#ifndef _3D_DISABLED
#include "servers/xr/xr_interface.h"
#endif // _3D_DISABLED

class RendererViewport {
public:
struct CanvasBase {
Expand Down
Loading
Loading