From 6f0cb752aafc009073135c89730de6fc39a32c59 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Thu, 19 Oct 2023 13:36:40 +0200 Subject: [PATCH] port: gl: allow user to override context version --- port/fast3d/gfx_sdl2.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/port/fast3d/gfx_sdl2.cpp b/port/fast3d/gfx_sdl2.cpp index 7127d0e38..d6eefb1c6 100644 --- a/port/fast3d/gfx_sdl2.cpp +++ b/port/fast3d/gfx_sdl2.cpp @@ -94,15 +94,30 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s // ideally we need 3.0 compat // if that doesn't work, try 3.2 core in case we're on mac, 2.1 compat as a last resort - static const u32 glver[][3] = { + static u32 glver[][3] = { + { 0, 0, 0 }, // for command line override { 3, 0, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY }, { 3, 2, SDL_GL_CONTEXT_PROFILE_CORE }, { 2, 1, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY }, }; + u32 glcore = false; + u32 verstart = 1; + const u32 verend = sizeof(glver) / sizeof(*glver); + const char *verstr = sysArgGetString("--gl-version"); + if (verstr && *verstr) { + // user override + glver[0][2] = strstr(verstr, "core") ? SDL_GL_CONTEXT_PROFILE_CORE : + SDL_GL_CONTEXT_PROFILE_COMPATIBILITY; + sscanf(verstr, "%d.%d", &glver[0][0], &glver[0][1]); + if (glver[0][0] >= 1 && glver[0][0] <= 4 && glver[0][1] < 9) { + verstart = 0; + } + } + ctx = NULL; u32 vmin = 0, vmaj = 0; - for (u32 i = 0; i < sizeof(glver) / sizeof(*glver); ++i) { + for (u32 i = verstart; i < verend; ++i) { vmaj = glver[i][0]; vmin = glver[i][1]; SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, vmaj); @@ -112,6 +127,7 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s if (!ctx) { sysLogPrintf(LOG_WARNING, "GL: could not create GL%d.%d context: %s", vmaj, vmin, SDL_GetError()); } else { + glcore = (glver[i][2] == SDL_GL_CONTEXT_PROFILE_CORE); break; } } @@ -119,7 +135,7 @@ static void gfx_sdl_init(const char* game_name, const char* gfx_api_name, bool s if (!ctx) { sysFatalError("Could not create an OpenGL context of any supported version.\nSDL error: %s", SDL_GetError()); } else { - sysLogPrintf(LOG_NOTE, "GL: created GL%d.%d context", vmaj, vmin); + sysLogPrintf(LOG_NOTE, "GL: created GL%d.%d%s context", vmaj, vmin, glcore ? "core" : ""); } SDL_GL_MakeCurrent(wnd, ctx);