Skip to content

Commit

Permalink
Actually move rendering method/driver methods from OS to `Rendering…
Browse files Browse the repository at this point in the history
…Server`

Also moves the recently introduced `get_gles_over_gl` (not exposed) and removes
the unused `get_display_driver_id`.
  • Loading branch information
akien-mga committed Nov 11, 2024
1 parent 2295cd6 commit 3a94368
Show file tree
Hide file tree
Showing 33 changed files with 81 additions and 104 deletions.
19 changes: 0 additions & 19 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ class OS {
bool restart_on_exit = false;
List<String> restart_commandline;

// for the user interface we keep a record of the current display driver
// so we can retrieve the rendering drivers available
int _display_driver_id = -1;
String _current_rendering_driver_name;
String _current_rendering_method;
bool _is_gles_over_gl = false;

RemoteFilesystemClient default_rfs;

// For tracking benchmark data
Expand Down Expand Up @@ -111,8 +104,6 @@ class OS {
virtual void initialize() = 0;
virtual void initialize_joypads() = 0;

void set_display_driver_id(int p_display_driver_id) { _display_driver_id = p_display_driver_id; }

virtual void set_main_loop(MainLoop *p_main_loop) = 0;
virtual void delete_main_loop() = 0;

Expand All @@ -128,16 +119,6 @@ class OS {

static OS *get_singleton();

void set_current_rendering_driver_name(const String &p_driver_name) { _current_rendering_driver_name = p_driver_name; }
void set_current_rendering_method(const String &p_name) { _current_rendering_method = p_name; }
void set_gles_over_gl(bool p_enabled) { _is_gles_over_gl = p_enabled; }

String get_current_rendering_driver_name() const { return _current_rendering_driver_name; }
String get_current_rendering_method() const { return _current_rendering_method; }
bool get_gles_over_gl() const { return _is_gles_over_gl; }

int get_display_driver_id() const { return _display_driver_id; }

virtual Vector<String> get_video_adapter_driver_info() const = 0;
virtual bool get_user_prefers_integrated_gpu() const { return false; }

Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_gles3.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class RasterizerGLES3 : public RendererCompositor {

static void make_current(bool p_gles_over_gl) {
gles_over_gl = p_gles_over_gl;
OS::get_singleton()->set_gles_over_gl(gles_over_gl);
RenderingServer::get_singleton()->set_gles_over_gl(gles_over_gl);
_create_func = _create_current;
low_end = true;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Config::Config() {
disable_transform_feedback_shader_cache = true;
}

if (OS::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
if (RenderingServer::get_singleton()->get_current_rendering_driver_name() == "opengl3_angle") {
polyfill_half2float = false;
}
#ifdef WEB_ENABLED
Expand Down
17 changes: 8 additions & 9 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4962,8 +4962,8 @@ String EditorNode::_get_system_info() const {
// `replace` is necessary, because `capitalize` introduces a whitespace between "x" and "11".
display_session_type = OS::get_singleton()->get_environment("XDG_SESSION_TYPE").capitalize().replace(" ", "");
#endif // LINUXBSD_ENABLED
String driver_name = OS::get_singleton()->get_current_rendering_driver_name().to_lower();
String rendering_method = OS::get_singleton()->get_current_rendering_method().to_lower();
String driver_name = RenderingServer::get_singleton()->get_current_rendering_driver_name().to_lower();
String rendering_method = RenderingServer::get_singleton()->get_current_rendering_method().to_lower();

const String rendering_device_name = RenderingServer::get_singleton()->get_video_adapter_name();

Expand Down Expand Up @@ -5009,7 +5009,7 @@ String EditorNode::_get_system_info() const {
} else if (driver_name == "opengl3_es") {
driver_name = "OpenGL ES 3";
} else if (driver_name == "opengl3") {
if (OS::get_singleton()->get_gles_over_gl()) {
if (RenderingServer::get_singleton()->get_gles_over_gl()) {
driver_name = "OpenGL 3";
} else {
driver_name = "OpenGL ES 3";
Expand Down Expand Up @@ -7457,12 +7457,11 @@ EditorNode::EditorNode() {
title_bar->add_child(right_menu_spacer);
}

String current_renderer_ps = GLOBAL_GET("rendering/renderer/rendering_method");
current_renderer_ps = current_renderer_ps.to_lower();
String current_renderer_os = OS::get_singleton()->get_current_rendering_method().to_lower();
String current_renderer_ps = String(GLOBAL_GET("rendering/renderer/rendering_method")).to_lower();
String current_renderer_rs = RenderingServer::get_singleton()->get_current_rendering_method().to_lower();

// Add the renderers name to the UI.
if (current_renderer_ps == current_renderer_os) {
if (current_renderer_ps == current_renderer_rs) {
renderer->connect(SceneStringName(item_selected), callable_mp(this, &EditorNode::_renderer_selected));
// As we are doing string comparisons, keep in standard case to prevent problems with capitals
// "vulkan" in particular uses lowercase "v" in the code, and uppercase in the UI.
Expand All @@ -7480,8 +7479,8 @@ EditorNode::EditorNode() {
}
} else {
// It's an CLI-overridden rendering method.
_add_renderer_entry(current_renderer_os, true);
renderer->set_item_metadata(0, current_renderer_os);
_add_renderer_entry(current_renderer_rs, true);
renderer->set_item_metadata(0, current_renderer_rs);
renderer->select(0);
renderer_current = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_shader_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static String _include_function(const String &p_path, void *userpointer) {

Error ResourceImporterShaderFile::import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
/* STEP 1, Read shader code */
ERR_FAIL_COND_V_EDMSG((OS::get_singleton()->get_current_rendering_method() == "gl_compatibility"), ERR_UNAVAILABLE, "Cannot import custom .glsl shaders when using the gl_compatibility rendering_method. Please switch to the forward_plus or mobile rendering methods to use custom shaders.");
ERR_FAIL_COND_V_EDMSG((RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility"), ERR_UNAVAILABLE, "Cannot import custom .glsl shaders when using the gl_compatibility rendering_method. Please switch to the forward_plus or mobile rendering methods to use custom shaders.");
ERR_FAIL_COND_V_EDMSG((DisplayServer::get_singleton()->get_name() == "headless"), ERR_UNAVAILABLE, "Cannot import custom .glsl shaders when running in headless mode.");

Error err;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/node_3d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8545,7 +8545,7 @@ void Node3DEditor::_load_default_preview_settings() {
environ_sky_color->set_pick_color(Color(0.385, 0.454, 0.55));
environ_ground_color->set_pick_color(Color(0.2, 0.169, 0.133));
environ_energy->set_value(1.0);
if (OS::get_singleton()->get_current_rendering_method() != "gl_compatibility") {
if (RenderingServer::get_singleton()->get_current_rendering_method() != "gl_compatibility") {
environ_glow_button->set_pressed(true);
}
environ_tonemap_button->set_pressed(true);
Expand Down
8 changes: 2 additions & 6 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,8 +2386,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// always convert to lower case for consistency in the code
rendering_driver = rendering_driver.to_lower();

OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
OS::get_singleton()->set_current_rendering_method(rendering_method);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method(rendering_method);

if (use_custom_res) {
if (!force_res) {
Expand Down Expand Up @@ -2943,10 +2943,6 @@ Error Main::setup2(bool p_show_boot_logo) {
}
}

// Store this in a globally accessible place, so we can retrieve the rendering drivers
// list from the display driver for the editor UI.
OS::get_singleton()->set_display_driver_id(display_driver_idx);

Vector2i *window_position = nullptr;
Vector2i position = init_custom_pos;
if (init_use_custom_pos) {
Expand Down
4 changes: 2 additions & 2 deletions platform/android/display_server_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your device seem not to support Vulkan, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif
{
Expand Down
4 changes: 2 additions & 2 deletions platform/ios/display_server_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your device seem not to support MoltenVK or Metal, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif
{
Expand Down
6 changes: 3 additions & 3 deletions platform/linuxbsd/wayland/display_server_wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,8 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your video card drivers seem not to support the required Vulkan version, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif // GLES3_ENABLED
{
Expand Down Expand Up @@ -1450,7 +1450,7 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win
if (fallback) {
WARN_PRINT("Your video card drivers seem not to support the required OpenGL version, switching to OpenGLES.");
rendering_driver = "opengl3_es";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else {
r_error = ERR_UNAVAILABLE;

Expand Down
6 changes: 3 additions & 3 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6174,8 +6174,8 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your video card drivers seem not to support the required Vulkan version, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif // GLES3_ENABLED
{
Expand Down Expand Up @@ -6251,7 +6251,7 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
if (fallback) {
WARN_PRINT("Your video card drivers seem not to support the required OpenGL version, switching to OpenGLES.");
rendering_driver = "opengl3_es";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else {
r_error = ERR_UNAVAILABLE;

Expand Down
6 changes: 3 additions & 3 deletions platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3645,8 +3645,8 @@
if (fallback_to_opengl3 && rendering_driver != "opengl3") {
WARN_PRINT("Your device seem not to support MoltenVK or Metal, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else
#endif
{
Expand All @@ -3671,7 +3671,7 @@
WARN_PRINT("Your video card drivers seem not to support GLES3 / ANGLE or ANGLE dynamic libraries (libEGL.dylib and libGLESv2.dylib) are missing, switching to native OpenGL.");
#endif
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
} else {
r_error = ERR_UNAVAILABLE;
ERR_FAIL_MSG("Could not initialize ANGLE OpenGL.");
Expand Down
10 changes: 5 additions & 5 deletions platform/windows/display_server_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6210,7 +6210,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
if (rendering_context->initialize() == OK) {
WARN_PRINT("Your video card drivers seem not to support Direct3D 12, switching to Vulkan.");
rendering_driver = "vulkan";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
failed = false;
}
}
Expand All @@ -6224,7 +6224,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
if (rendering_context->initialize() == OK) {
WARN_PRINT("Your video card drivers seem not to support Vulkan, switching to Direct3D 12.");
rendering_driver = "d3d12";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
failed = false;
}
}
Expand All @@ -6237,8 +6237,8 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
tested_drivers.set_flag(DRIVER_ID_COMPAT_OPENGL3);
WARN_PRINT("Your video card drivers seem not to support Direct3D 12 or Vulkan, switching to OpenGL 3.");
rendering_driver = "opengl3";
OS::get_singleton()->set_current_rendering_method("gl_compatibility");
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_method("gl_compatibility");
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
failed = false;
}
#endif
Expand Down Expand Up @@ -6316,7 +6316,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
}
}
rendering_driver = "opengl3_angle";
OS::get_singleton()->set_current_rendering_driver_name(rendering_driver);
RenderingServer::get_singleton()->set_current_rendering_driver_name(rendering_driver);
}
}

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ PackedStringArray GPUParticles2D::get_configuration_warnings() const {
}
}

if (trail_enabled && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (trail_enabled && RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Particle trails are only available when using the Forward+ or Mobile rendering backends."));
}

if (sub_emitter != NodePath() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (sub_emitter != NodePath() && RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Particle sub-emitters are not available when using the GL Compatibility rendering backend."));
}

Expand Down
2 changes: 1 addition & 1 deletion scene/3d/decal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void Decal::_validate_property(PropertyInfo &p_property) const {
PackedStringArray Decal::get_configuration_warnings() const {
PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();

if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Decals are only available when using the Forward+ or Mobile rendering backends."));
return warnings;
}
Expand Down
2 changes: 1 addition & 1 deletion scene/3d/fog_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ PackedStringArray FogVolume::get_configuration_warnings() const {

Ref<Environment> environment = get_viewport()->find_world_3d()->get_environment();

if (OS::get_singleton()->get_current_rendering_method() != "forward_plus") {
if (RenderingServer::get_singleton()->get_current_rendering_method() != "forward_plus") {
warnings.push_back(RTR("Fog Volumes are only visible when using the Forward+ backend."));
return warnings;
}
Expand Down
4 changes: 2 additions & 2 deletions scene/3d/gpu_particles_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ PackedStringArray GPUParticles3D::get_configuration_warnings() const {
if ((dp_count || !skin.is_null()) && (missing_trails || no_materials)) {
warnings.push_back(RTR("Trails enabled, but one or more mesh materials are either missing or not set for trails rendering."));
}
if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Particle trails are only available when using the Forward+ or Mobile rendering backends."));
}
}

if (sub_emitter != NodePath() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (sub_emitter != NodePath() && RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Particle sub-emitters are only available when using the Forward+ or Mobile rendering backends."));
}

Expand Down
4 changes: 2 additions & 2 deletions scene/3d/light_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ PackedStringArray OmniLight3D::get_configuration_warnings() const {
warnings.push_back(RTR("Projector texture only works with shadows active."));
}

if (get_projector().is_valid() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (get_projector().is_valid() && RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Projector textures are not supported when using the GL Compatibility backend yet. Support will be added in a future release."));
}

Expand Down Expand Up @@ -652,7 +652,7 @@ PackedStringArray SpotLight3D::get_configuration_warnings() const {
warnings.push_back(RTR("Projector texture only works with shadows active."));
}

if (get_projector().is_valid() && OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (get_projector().is_valid() && RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("Projector textures are not supported when using the GL Compatibility backend yet. Support will be added in a future release."));
}

Expand Down
4 changes: 2 additions & 2 deletions scene/3d/visual_instance_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,11 @@ PackedStringArray GeometryInstance3D::get_configuration_warnings() const {
warnings.push_back(RTR("The GeometryInstance3D is configured to fade out smoothly over distance, but the fade transition distance is set to 0.\nTo resolve this, increase Visibility Range End Margin above 0."));
}

if (!Math::is_zero_approx(transparency) && OS::get_singleton()->get_current_rendering_method() != "forward_plus") {
if (!Math::is_zero_approx(transparency) && RenderingServer::get_singleton()->get_current_rendering_method() != "forward_plus") {
warnings.push_back(RTR("GeometryInstance3D transparency is only available when using the Forward+ rendering method."));
}

if ((visibility_range_fade_mode == VISIBILITY_RANGE_FADE_SELF || visibility_range_fade_mode == VISIBILITY_RANGE_FADE_DEPENDENCIES) && OS::get_singleton()->get_current_rendering_method() != "forward_plus") {
if ((visibility_range_fade_mode == VISIBILITY_RANGE_FADE_SELF || visibility_range_fade_mode == VISIBILITY_RANGE_FADE_DEPENDENCIES) && RenderingServer::get_singleton()->get_current_rendering_method() != "forward_plus") {
warnings.push_back(RTR("GeometryInstance3D visibility range transparency fade is only available when using the Forward+ rendering method."));
}

Expand Down
2 changes: 1 addition & 1 deletion scene/3d/voxel_gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ AABB VoxelGI::get_aabb() const {
PackedStringArray VoxelGI::get_configuration_warnings() const {
PackedStringArray warnings = VisualInstance3D::get_configuration_warnings();

if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
if (RenderingServer::get_singleton()->get_current_rendering_method() == "gl_compatibility") {
warnings.push_back(RTR("VoxelGI nodes are not supported when using the GL Compatibility backend yet. Support will be added in a future release."));
} else if (probe_data.is_null()) {
warnings.push_back(RTR("No VoxelGI data set, so this node is disabled. Bake static objects to enable GI."));
Expand Down
Loading

0 comments on commit 3a94368

Please sign in to comment.