summaryrefslogtreecommitdiff
path: root/platform/android/os_android.cpp
diff options
context:
space:
mode:
authorHein-Pieter van Braam <hp@tmm.cx>2018-08-25 00:04:25 +0200
committerHein-Pieter van Braam <hp@tmm.cx>2018-08-26 16:40:46 +0200
commit08f452d1a95d7f171472c33a60983d95adf1665d (patch)
treeaffda153790d6851509d6a316221dc1ab97d5f0d /platform/android/os_android.cpp
parent8c435a343e9739f30cb2e347df95835c91c1ff1a (diff)
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
Diffstat (limited to 'platform/android/os_android.cpp')
-rw-r--r--platform/android/os_android.cpp64
1 files changed, 50 insertions, 14 deletions
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);