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:
@ -1273,21 +1273,74 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
|
||||
}
|
||||
|
||||
#if defined(OPENGL_ENABLED)
|
||||
|
||||
bool gles3_context = true;
|
||||
if (p_video_driver == VIDEO_DRIVER_GLES2) {
|
||||
gl_context = memnew(ContextGL_Win(hWnd, false));
|
||||
gl_context->initialize();
|
||||
|
||||
RasterizerGLES2::register_config();
|
||||
RasterizerGLES2::make_current();
|
||||
} else {
|
||||
gl_context = memnew(ContextGL_Win(hWnd, true));
|
||||
gl_context->initialize();
|
||||
|
||||
RasterizerGLES3::register_config();
|
||||
RasterizerGLES3::make_current();
|
||||
gles3_context = false;
|
||||
}
|
||||
|
||||
video_driver_index = p_video_driver; // FIXME TODO - FIX IF DRIVER DETECTION HAPPENS AND GLES2 MUST BE USED
|
||||
bool editor = Engine::get_singleton()->is_editor_hint();
|
||||
bool gl_initialization_error = false;
|
||||
|
||||
gl_context = NULL;
|
||||
while (!gl_context) {
|
||||
gl_context = memnew(ContextGL_Win(hWnd, gles3_context));
|
||||
|
||||
if (gl_context->initialize() != OK) {
|
||||
memdelete(gl_context);
|
||||
gl_context = 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;
|
||||
gles3_context = false;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (gles3_context) {
|
||||
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;
|
||||
gles3_context = false;
|
||||
continue;
|
||||
} else {
|
||||
gl_initialization_error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
|
||||
gl_context->set_use_vsync(video_mode.use_vsync);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user