diff options
author | Thaddeus Crews <repiteo@outlook.com> | 2024-10-29 19:25:48 -0500 |
---|---|---|
committer | Thaddeus Crews <repiteo@outlook.com> | 2024-10-29 19:25:48 -0500 |
commit | 05a4620e88fc454e844f69e87a6eb444426c2a6e (patch) | |
tree | 2af7c1e884e874234cfec77b3e8d8c4667435f02 /platform | |
parent | 73830b3c120406b10b344063783ba32bbbc2110f (diff) | |
parent | 6d14cd6ff96f74199acea2ad449ec2e1d2dcceab (diff) | |
download | redot-engine-05a4620e88fc454e844f69e87a6eb444426c2a6e.tar.gz |
Merge pull request #98615 from Summersay415/three-opengls-please
Fix fallbacks to OpenGL
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/display_server_android.cpp | 19 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/Godot.kt | 18 | ||||
-rw-r--r-- | platform/ios/display_server_ios.mm | 7 | ||||
-rw-r--r-- | platform/linuxbsd/wayland/display_server_wayland.cpp | 5 | ||||
-rw-r--r-- | platform/linuxbsd/x11/display_server_x11.cpp | 5 | ||||
-rw-r--r-- | platform/macos/display_server_macos.mm | 62 | ||||
-rw-r--r-- | platform/windows/display_server_windows.cpp | 2 |
7 files changed, 76 insertions, 42 deletions
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index a7f10ea83a..f5032eaa40 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -625,12 +625,6 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis native_menu = memnew(NativeMenu); -#if defined(GLES3_ENABLED) - if (rendering_driver == "opengl3") { - RasterizerGLES3::make_current(false); - } -#endif - #if defined(RD_ENABLED) rendering_context = nullptr; rendering_device = nullptr; @@ -645,19 +639,24 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; +#if defined(GLES3_ENABLED) bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); 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); - } else { + } else +#endif + { ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); r_error = ERR_UNAVAILABLE; return; } } + } + if (rendering_context) { union { #ifdef VULKAN_ENABLED RenderingContextDriverVulkanAndroid::WindowPlatformData vulkan; @@ -697,6 +696,12 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis } #endif +#if defined(GLES3_ENABLED) + if (rendering_driver == "opengl3") { + RasterizerGLES3::make_current(false); + } +#endif + Input::get_singleton()->set_event_dispatch_function(_dispatch_input_events); r_error = OK; diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt index f4b9771128..9ad1e0b740 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/Godot.kt +++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.kt @@ -479,12 +479,17 @@ class Godot(private val context: Context) { // ...add to FrameLayout containerLayout?.addView(editText) renderView = if (usesVulkan()) { - if (!meetsVulkanRequirements(activity.packageManager)) { + if (meetsVulkanRequirements(activity.packageManager)) { + GodotVulkanRenderView(host, this, godotInputHandler) + } else if (canFallbackToOpenGL()) { + // Fallback to OpenGl. + GodotGLRenderView(host, this, godotInputHandler, xrMode, useDebugOpengl) + } else { throw IllegalStateException(activity.getString(R.string.error_missing_vulkan_requirements_message)) } - GodotVulkanRenderView(host, this, godotInputHandler) + } else { - // Fallback to openGl + // Fallback to OpenGl. GodotGLRenderView(host, this, godotInputHandler, xrMode, useDebugOpengl) } @@ -819,6 +824,13 @@ class Godot(private val context: Context) { } /** + * Returns true if can fallback to OpenGL. + */ + private fun canFallbackToOpenGL(): Boolean { + return java.lang.Boolean.parseBoolean(GodotLib.getGlobal("rendering/rendering_device/fallback_to_opengl3")) + } + + /** * Returns true if the device meets the base requirements for Vulkan support, false otherwise. */ private fun meetsVulkanRequirements(packageManager: PackageManager?): Boolean { diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index dcc6ce9218..7649828189 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -111,19 +111,24 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; +#if defined(GLES3_ENABLED) bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); 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); - } else { + } else +#endif + { ERR_PRINT(vformat("Failed to initialize %s context", rendering_driver)); r_error = ERR_UNAVAILABLE; return; } } + } + if (rendering_context) { if (rendering_context->window_create(MAIN_WINDOW_ID, &wpd) != OK) { ERR_PRINT(vformat("Failed to create %s window.", rendering_driver)); memdelete(rendering_context); diff --git a/platform/linuxbsd/wayland/display_server_wayland.cpp b/platform/linuxbsd/wayland/display_server_wayland.cpp index 0a87c4a517..d5271f9ad4 100644 --- a/platform/linuxbsd/wayland/display_server_wayland.cpp +++ b/platform/linuxbsd/wayland/display_server_wayland.cpp @@ -1356,13 +1356,16 @@ DisplayServerWayland::DisplayServerWayland(const String &p_rendering_driver, Win if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; +#if defined(GLES3_ENABLED) bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); 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); - } else { + } else +#endif // GLES3_ENABLED + { r_error = ERR_CANT_CREATE; if (p_rendering_driver == "vulkan") { diff --git a/platform/linuxbsd/x11/display_server_x11.cpp b/platform/linuxbsd/x11/display_server_x11.cpp index f1be5d83dc..48ff06cad2 100644 --- a/platform/linuxbsd/x11/display_server_x11.cpp +++ b/platform/linuxbsd/x11/display_server_x11.cpp @@ -6168,13 +6168,16 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode if (rendering_context->initialize() != OK) { memdelete(rendering_context); rendering_context = nullptr; +#if defined(GLES3_ENABLED) bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); 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); - } else { + } else +#endif // GLES3_ENABLED + { r_error = ERR_CANT_CREATE; if (p_rendering_driver == "vulkan") { diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm index 43469d981b..714df18228 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -3623,6 +3623,39 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM //TODO - do Vulkan and OpenGL support checks, driver selection and fallback rendering_driver = p_rendering_driver; +#if defined(RD_ENABLED) +#if defined(VULKAN_ENABLED) + if (rendering_driver == "vulkan") { + rendering_context = memnew(RenderingContextDriverVulkanMacOS); + } +#endif +#if defined(METAL_ENABLED) + if (rendering_driver == "metal") { + rendering_context = memnew(RenderingContextDriverMetal); + } +#endif + + if (rendering_context) { + if (rendering_context->initialize() != OK) { + memdelete(rendering_context); + rendering_context = nullptr; +#if defined(GLES3_ENABLED) + bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); + 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); + } else +#endif + { + r_error = ERR_CANT_CREATE; + ERR_FAIL_MSG("Could not initialize " + rendering_driver); + } + } + } +#endif + #if defined(GLES3_ENABLED) if (rendering_driver == "opengl3_angle") { gl_manager_angle = memnew(GLManagerANGLE_MacOS); @@ -3655,35 +3688,6 @@ DisplayServerMacOS::DisplayServerMacOS(const String &p_rendering_driver, WindowM } } #endif -#if defined(RD_ENABLED) -#if defined(VULKAN_ENABLED) - if (rendering_driver == "vulkan") { - rendering_context = memnew(RenderingContextDriverVulkanMacOS); - } -#endif -#if defined(METAL_ENABLED) - if (rendering_driver == "metal") { - rendering_context = memnew(RenderingContextDriverMetal); - } -#endif - - if (rendering_context) { - if (rendering_context->initialize() != OK) { - memdelete(rendering_context); - rendering_context = nullptr; - bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); - 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); - } else { - r_error = ERR_CANT_CREATE; - ERR_FAIL_MSG("Could not initialize " + rendering_driver); - } - } - } -#endif Point2i window_position; if (p_position != nullptr) { diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 12c58a4f25..07424a3b4c 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -6238,6 +6238,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win } } #endif +#if defined(GLES3_ENABLED) bool fallback_to_opengl3 = GLOBAL_GET("rendering/rendering_device/fallback_to_opengl3"); if (failed && fallback_to_opengl3 && rendering_driver != "opengl3") { memdelete(rendering_context); @@ -6249,6 +6250,7 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win OS::get_singleton()->set_current_rendering_driver_name(rendering_driver); failed = false; } +#endif if (failed) { memdelete(rendering_context); rendering_context = nullptr; |