From f8a6c0e8ab7d391fbfd796c65cfff26190654621 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:46:01 +0300 Subject: [PATCH] Enable fallback from ANGLE to native and improve ANGLE error messages. --- doc/classes/ProjectSettings.xml | 4 +- drivers/egl/egl_manager.cpp | 4 +- platform/macos/display_server_macos.mm | 6 ++- platform/windows/display_server_windows.cpp | 44 +++++++++++++++------ 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 252574c419c..efca7adb925 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -2526,8 +2526,8 @@ [b]Note:[/b] This setting is implemented only on Linux/X11. - If [code]true[/code], the compatibility renderer will fall back to native OpenGL if ANGLE over Metal is not supported. - [b]Note:[/b] This setting is implemented only on macOS. + If [code]true[/code], the compatibility renderer will fall back to native OpenGL if ANGLE is not supported, or ANGLE dynamic libraries aren't found. + [b]Note:[/b] This setting is implemented on macOS and Windows. An [Array] of devices which should always use the ANGLE renderer. diff --git a/drivers/egl/egl_manager.cpp b/drivers/egl/egl_manager.cpp index 9c1d08331d2..4477ba7752c 100644 --- a/drivers/egl/egl_manager.cpp +++ b/drivers/egl/egl_manager.cpp @@ -357,7 +357,7 @@ Error EGLManager::initialize(void *p_native_display) { // have to temporarily get a proper display and reload EGL once again to // initialize everything else. if (!gladLoaderLoadEGL(EGL_NO_DISPLAY)) { - ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL."); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL dynamic library."); } EGLDisplay tmp_display = EGL_NO_DISPLAY; @@ -387,7 +387,7 @@ Error EGLManager::initialize(void *p_native_display) { int version = gladLoaderLoadEGL(tmp_display); if (!version) { eglTerminate(tmp_display); - ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL."); + ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "Can't load EGL dynamic library."); } int major = GLAD_VERSION_MAJOR(version); diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 3e0a5efe526..989a9dcf6c5 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3609,7 +3609,11 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM gl_manager_angle = nullptr; bool fallback = GLOBAL_GET("rendering/gl_compatibility/fallback_to_native"); if (fallback) { - WARN_PRINT("Your video card drivers seem not to support the required Metal version, switching to native OpenGL."); +#ifdef EGL_STATIC + WARN_PRINT("Your video card drivers seem not to support GLES3 / ANGLE, switching to native OpenGL."); +#else + 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"; } else { r_error = ERR_UNAVAILABLE; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index b55eda0e51d..6fa3f2c9d60 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -6183,10 +6183,12 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win #endif } + bool gl_supported = true; if (fallback && (rendering_driver == "opengl3")) { Dictionary gl_info = detect_wgl(); bool force_angle = false; + gl_supported = gl_info["version"].operator int() >= 30003; Vector2i device_id = _get_device_ids(gl_info["name"]); Array device_list = GLOBAL_GET("rendering/gl_compatibility/force_angle_on_devices"); @@ -6210,12 +6212,37 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win if (force_angle || (gl_info["version"].operator int() < 30003)) { tested_drivers.set_flag(DRIVER_ID_COMPAT_OPENGL3); if (show_warning) { - WARN_PRINT("Your video card drivers seem not to support the required OpenGL 3.3 version, switching to ANGLE."); + if (gl_info["version"].operator int() < 30003) { + WARN_PRINT("Your video card drivers seem not to support the required OpenGL 3.3 version, switching to ANGLE."); + } else { + WARN_PRINT("Your video card drivers are known to have low quality OpenGL 3.3 support, switching to ANGLE."); + } } rendering_driver = "opengl3_angle"; } } + if (rendering_driver == "opengl3_angle") { + gl_manager_angle = memnew(GLManagerANGLE_Windows); + tested_drivers.set_flag(DRIVER_ID_COMPAT_ANGLE_D3D11); + + if (gl_manager_angle->initialize() != OK) { + memdelete(gl_manager_angle); + gl_manager_angle = nullptr; + bool fallback_to_native = GLOBAL_GET("rendering/gl_compatibility/fallback_to_native"); + if (fallback_to_native && gl_supported) { +#ifdef EGL_STATIC + WARN_PRINT("Your video card drivers seem not to support GLES3 / ANGLE, switching to native OpenGL."); +#else + WARN_PRINT("Your video card drivers seem not to support GLES3 / ANGLE or ANGLE dynamic libraries (libEGL.dll and libGLESv2.dll) are missing, switching to native OpenGL."); +#endif + rendering_driver = "opengl3"; + } else { + r_error = ERR_UNAVAILABLE; + ERR_FAIL_MSG("Could not initialize ANGLE OpenGL."); + } + } + } if (rendering_driver == "opengl3") { gl_manager_native = memnew(GLManagerNative_Windows); tested_drivers.set_flag(DRIVER_ID_COMPAT_OPENGL3); @@ -6224,26 +6251,17 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win memdelete(gl_manager_native); gl_manager_native = nullptr; r_error = ERR_UNAVAILABLE; - return; + ERR_FAIL_MSG("Could not initialize native OpenGL."); } + } + if (rendering_driver == "opengl3") { RasterizerGLES3::make_current(true); } if (rendering_driver == "opengl3_angle") { - gl_manager_angle = memnew(GLManagerANGLE_Windows); - tested_drivers.set_flag(DRIVER_ID_COMPAT_ANGLE_D3D11); - - if (gl_manager_angle->initialize() != OK) { - memdelete(gl_manager_angle); - gl_manager_angle = nullptr; - r_error = ERR_UNAVAILABLE; - return; - } - RasterizerGLES3::make_current(false); } #endif - String appname; if (Engine::get_singleton()->is_editor_hint()) { appname = "Godot.GodotEditor." + String(VERSION_FULL_CONFIG);