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
This commit is contained in:
Hein-Pieter van Braam
2018-08-25 00:04:25 +02:00
parent 8c435a343e
commit 08f452d1a9
16 changed files with 417 additions and 171 deletions

View File

@ -274,21 +274,70 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
}
context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
context_gl->initialize();
bool editor = Engine::get_singleton()->is_editor_hint();
bool gl_initialization_error = false;
switch (opengl_api_type) {
case ContextGL_X11::GLES_2_0_COMPATIBLE: {
RasterizerGLES2::register_config();
RasterizerGLES2::make_current();
} break;
case ContextGL_X11::GLES_3_0_COMPATIBLE: {
RasterizerGLES3::register_config();
RasterizerGLES3::make_current();
} break;
context_gl = NULL;
while (!context_gl) {
context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
if (context_gl->initialize() != OK) {
memdelete(context_gl);
context_gl = NULL;
if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
if (p_video_driver == VIDEO_DRIVER_GLES2) {
gl_initialization_error = true;
break;
}
p_video_driver = VIDEO_DRIVER_GLES2;
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
} else {
gl_initialization_error = true;
break;
}
}
}
video_driver_index = p_video_driver; // FIXME TODO - FIX IF DRIVER DETECTION HAPPENS AND GLES2 MUST BE USED
while (true) {
if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
if (RasterizerGLES3::is_viable() == OK) {
RasterizerGLES3::register_config();
RasterizerGLES3::make_current();
break;
} else {
if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best" || editor) {
p_video_driver = VIDEO_DRIVER_GLES2;
opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
continue;
} else {
gl_initialization_error = true;
break;
}
}
}
if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
if (RasterizerGLES2::is_viable() == OK) {
RasterizerGLES2::register_config();
RasterizerGLES2::make_current();
break;
} else {
gl_initialization_error = true;
break;
}
}
}
if (gl_initialization_error) {
OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
"Please update your drivers or if you have a very old or integrated GPU upgrade it.",
"Unable to initialize Video driver");
return ERR_UNAVAILABLE;
}
video_driver_index = p_video_driver;
context_gl->set_use_vsync(current_videomode.use_vsync);
@ -339,8 +388,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
set_window_always_on_top(true);
}
AudioDriverManager::initialize(p_audio_driver);
ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
@ -510,6 +557,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
visual_server->init();
AudioDriverManager::initialize(p_audio_driver);
input = memnew(InputDefault);
window_has_focus = true; // Set focus to true at init