mirror of
https://github.com/perfect-dark-pc-port/perfect_dark.git
synced 2026-10-23 15:52:41 +02:00
port: gl: allow user to override context version
This commit is contained in:
1 parent
abf5703036
commit
6f0cb752aa
1 file changed
+19
-3
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user