From 08f452d1a95d7f171472c33a60983d95adf1665d Mon Sep 17 00:00:00 2001 From: Hein-Pieter van Braam Date: Sat, 25 Aug 2018 00:04:25 +0200 Subject: Fall back to GLES2 if GLES3 is not working This adds a static is_viable() method to all rasterizers which has to be called before initializing the rasterizer. This allows us to check what rasterizer to use in OS::initialize together with the GL context initialization. This commit also adds a new project setting "rendering/quality/driver/driver_fallback" which allows the creator of a project to specify whether or not fallback to GLES2 is allowed. This setting is ignored for the editor so the editor will always open even if the project itself cannot run. This will hopefully reduce confusion for users downloading projects from the internet. We also no longer crash when GLES3 is not functioning on a platform. This fixes #15324 --- platform/android/os_android.cpp | 64 ++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'platform/android') diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index c8bdf98923..74c40bde72 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -62,12 +62,19 @@ public: int OS_Android::get_video_driver_count() const { - return 1; + return 2; } const char *OS_Android::get_video_driver_name(int p_driver) const { - return "GLES2"; + switch (p_driver) { + case VIDEO_DRIVER_GLES3: + return "GLES3"; + case VIDEO_DRIVER_GLES2: + return "GLES2"; + } + ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); + ERR_FAIL_V(NULL); } int OS_Android::get_audio_driver_count() const { @@ -132,26 +139,55 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int bool use_gl3 = get_gl_version_code_func() >= 0x00030000; use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3"); - use_gl2 = !use_gl3; - - if (gfx_init_func) - gfx_init_func(gfx_init_ud, use_gl2); + bool gl_initialization_error = false; + + while (true) { + if (use_gl3) { + if (RasterizerGLES3::is_viable() == OK) { + if (gfx_init_func) + gfx_init_func(gfx_init_ud, false); + RasterizerGLES3::register_config(); + RasterizerGLES3::make_current(); + break; + } else { + if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best") { + p_video_driver = VIDEO_DRIVER_GLES2; + use_gl3 = false; + continue; + } else { + gl_initialization_error = true; + break; + } + } + } else { + if (RasterizerGLES2::is_viable() == OK) { + if (gfx_init_func) + gfx_init_func(gfx_init_ud, true); + RasterizerGLES2::register_config(); + RasterizerGLES2::make_current(); + break; + } else { + gl_initialization_error = true; + break; + } + } + } - if (use_gl2) { - RasterizerGLES2::register_config(); - RasterizerGLES2::make_current(); - video_driver_index = VIDEO_DRIVER_GLES2; - } else { - RasterizerGLES3::register_config(); - RasterizerGLES3::make_current(); - video_driver_index = VIDEO_DRIVER_GLES3; + if (gl_initialization_error) { + OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.\n" + "Please try updating your Android version.", + "Unable to initialize Video driver"); + return ERR_UNAVAILABLE; } + video_driver_index = p_video_driver; + visual_server = memnew(VisualServerRaster); /* if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { visual_server = memnew(VisualServerWrapMT(visual_server, false)); };*/ + visual_server->init(); // visual_server->cursor_set_visible(false, 0); -- cgit v1.2.3