From 65e44b8ec187e7f0d95fa940bfcc1315e3597102 Mon Sep 17 00:00:00 2001 From: fp64 <106717720+fp64@users.noreply.github.com> Date: Fri, 22 Aug 2025 17:32:55 +0300 Subject: [PATCH] Update SDLMain.cpp --- SDL/SDLMain.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 35680171b2..afa17c31c7 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -1410,6 +1410,14 @@ int main(int argc, char *argv[]) { int remain_argc = 1; const char *remain_argv[256] = { argv[0] }; + // Option to force a specific OpenGL version (42="4.2", + // etc.; -1 means "try them all"). + // Implemented as a workaround for https://github.com/hrydgard/ppsspp/issues/20687 + // NOTE: this is currently not persistent (doesn't + // go to config), even though --graphics=openglX.Y + // also sets the GPU backend which does persist. + int force_gl_version = -1; + Uint32 mode = 0; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i],"--fullscreen")) { @@ -1435,6 +1443,33 @@ int main(int argc, char *argv[]) { set_ipad = true; else if (!strcmp(argv[i],"--portrait")) portrait = true; + else if (!strncmp(argv[i],"--graphics=",strlen("--graphics="))) { + const char *restOfOption = argv[i] + strlen("--graphics="); + double val=-1.0; // Yes, floating point. + if (!strcmp(restOfOption,"vulkan")) { + g_Config.iGPUBackend = (int)GPUBackend::VULKAN; + g_Config.bSoftwareRendering = false; + } + else if (!strcmp(restOfOption,"software")) { + // Same as on Windows, software presently implies OpenGL. + g_Config.iGPUBackend = (int)GPUBackend::OPENGL; + g_Config.bSoftwareRendering = true; + } + // NOTE: OpenGL and GLES are treated the same for + // the purposes of option parsing. + else if (!strcmp(restOfOption,"gles") || + !strcmp(restOfOption,"opengl")) { + g_Config.iGPUBackend = (int)GPUBackend::OPENGL; + g_Config.bSoftwareRendering = false; + } + else if (sscanf(restOfOption,"gles%lg",&val) == 1 || + sscanf(restOfOption,"opengl%lg",&val) == 1) + { + g_Config.iGPUBackend = (int)GPUBackend::OPENGL; + g_Config.bSoftwareRendering = false; + force_gl_version = int(10.0*val+0.5); + } + } else { remain_argv[remain_argc++] = argv[i]; } @@ -1592,7 +1627,7 @@ int main(int argc, char *argv[]) { std::string error_message; if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { SDLGLGraphicsContext *glctx = new SDLGLGraphicsContext(); - if (glctx->Init(window, x, y, w, h, mode, &error_message) != 0) { + if (glctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version) != 0) { // Let's try the fallback once per process run. printf("GL init error '%s' - falling back to Vulkan\n", error_message.c_str()); g_Config.iGPUBackend = (int)GPUBackend::VULKAN; @@ -1622,7 +1657,7 @@ int main(int argc, char *argv[]) { // NOTE : This should match the three lines above in the OpenGL case. SDLGLGraphicsContext *glctx = new SDLGLGraphicsContext(); - if (glctx->Init(window, x, y, w, h, mode, &error_message) != 0) { + if (glctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version) != 0) { printf("GL fallback failed: %s\n", error_message.c_str()); return 1; } @@ -1786,7 +1821,7 @@ int main(int argc, char *argv[]) { if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) { SDLGLGraphicsContext *ctx = (SDLGLGraphicsContext *)graphicsContext; - if (!ctx->Init(window, x, y, w, h, mode, &error_message)) { + if (!ctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version)) { printf("Failed to reinit graphics.\n"); } }