Skip to content

Commit 04f84ad

Browse files
committed
Merge branch 'sdl-force-opengl-version'
2 parents 3a26ff4 + 6868bde commit 04f84ad

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

SDL/SDLGLGraphicsContext.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ bool SDLGLGraphicsContext::InitFromRenderThread(std::string *errorMessage) {
307307
}
308308

309309
// Returns 0 on success.
310-
int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, int h, int mode, std::string *error_message) {
310+
int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, int h, int mode, std::string *error_message, int force_gl_version) {
311311
struct GLVersionPair {
312312
int major;
313313
int minor;
@@ -328,6 +328,12 @@ int SDLGLGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, int h,
328328
SDL_GLContext glContext = nullptr;
329329
for (size_t i = 0; i < ARRAY_SIZE(attemptVersions); ++i) {
330330
const auto &ver = attemptVersions[i];
331+
// If we force a specific OpenGL version, skip the ones
332+
// that do not match, which may be all of them - e.g.
333+
// requesting nonsensical "--graphics=opengl0" reliably
334+
// skips straight to fallback code below.
335+
if (force_gl_version >= 0 && 10 * ver.major + ver.minor != force_gl_version)
336+
continue;
331337
// Make sure to request a somewhat modern GL context at least - the
332338
// latest supported by MacOS X (really, really sad...)
333339
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, ver.major);

SDL/SDLGLGraphicsContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class SDLGLGraphicsContext : public GraphicsContext {
1717
public:
1818
// Returns 0 on success.
19-
int Init(SDL_Window *&window, int x, int y, int w, int h, int mode, std::string *error_message);
19+
int Init(SDL_Window *&window, int x, int y, int w, int h, int mode, std::string *error_message, int force_gl_version);
2020

2121
bool InitFromRenderThread(std::string *errorMessage) override;
2222

SDL/SDLMain.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ static void ProcessSDLEvent(SDL_Window *window, const SDL_Event &event, InputSta
10361036
// Convenience subset of what
10371037
// "Enable standard shortcut keys"
10381038
// does on Windows.
1039-
if(g_Config.bSystemControls) {
1039+
if (g_Config.bSystemControls) {
10401040
bool ctrl = bool(event.key.keysym.mod & KMOD_CTRL);
10411041
if (ctrl && (k == SDLK_w))
10421042
{
@@ -1410,6 +1410,14 @@ int main(int argc, char *argv[]) {
14101410
int remain_argc = 1;
14111411
const char *remain_argv[256] = { argv[0] };
14121412

1413+
// Option to force a specific OpenGL version (42="4.2",
1414+
// etc.; -1 means "try them all").
1415+
// Implemented as a workaround for https://github.com/hrydgard/ppsspp/issues/20687
1416+
// NOTE: this is currently not persistent (doesn't
1417+
// go to config), even though --graphics=openglX.Y
1418+
// also sets the GPU backend which does persist.
1419+
int force_gl_version = -1;
1420+
14131421
Uint32 mode = 0;
14141422
for (int i = 1; i < argc; i++) {
14151423
if (!strcmp(argv[i],"--fullscreen")) {
@@ -1435,7 +1443,27 @@ int main(int argc, char *argv[]) {
14351443
set_ipad = true;
14361444
else if (!strcmp(argv[i],"--portrait"))
14371445
portrait = true;
1438-
else {
1446+
else if (!strncmp(argv[i],"--graphics=", strlen("--graphics="))) {
1447+
const char *restOfOption = argv[i] + strlen("--graphics=");
1448+
double val=-1.0; // Yes, floating point.
1449+
if (!strcmp(restOfOption, "vulkan")) {
1450+
g_Config.iGPUBackend = (int)GPUBackend::VULKAN;
1451+
g_Config.bSoftwareRendering = false;
1452+
} else if (!strcmp(restOfOption, "software")) {
1453+
// Same as on Windows, software presently implies OpenGL.
1454+
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
1455+
g_Config.bSoftwareRendering = true;
1456+
} else if (!strcmp(restOfOption, "gles") || !strcmp(restOfOption, "opengl")) {
1457+
// NOTE: OpenGL and GLES are treated the same for
1458+
// the purposes of option parsing.
1459+
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
1460+
g_Config.bSoftwareRendering = false;
1461+
} else if (sscanf(restOfOption, "gles%lg", &val) == 1 || sscanf(restOfOption, "opengl%lg", &val) == 1) {
1462+
g_Config.iGPUBackend = (int)GPUBackend::OPENGL;
1463+
g_Config.bSoftwareRendering = false;
1464+
force_gl_version = int(10.0 * val + 0.5);
1465+
}
1466+
} else {
14391467
remain_argv[remain_argc++] = argv[i];
14401468
}
14411469
}
@@ -1592,7 +1620,7 @@ int main(int argc, char *argv[]) {
15921620
std::string error_message;
15931621
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
15941622
SDLGLGraphicsContext *glctx = new SDLGLGraphicsContext();
1595-
if (glctx->Init(window, x, y, w, h, mode, &error_message) != 0) {
1623+
if (glctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version) != 0) {
15961624
// Let's try the fallback once per process run.
15971625
printf("GL init error '%s' - falling back to Vulkan\n", error_message.c_str());
15981626
g_Config.iGPUBackend = (int)GPUBackend::VULKAN;
@@ -1622,7 +1650,7 @@ int main(int argc, char *argv[]) {
16221650

16231651
// NOTE : This should match the three lines above in the OpenGL case.
16241652
SDLGLGraphicsContext *glctx = new SDLGLGraphicsContext();
1625-
if (glctx->Init(window, x, y, w, h, mode, &error_message) != 0) {
1653+
if (glctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version) != 0) {
16261654
printf("GL fallback failed: %s\n", error_message.c_str());
16271655
return 1;
16281656
}
@@ -1786,7 +1814,7 @@ int main(int argc, char *argv[]) {
17861814

17871815
if (g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
17881816
SDLGLGraphicsContext *ctx = (SDLGLGraphicsContext *)graphicsContext;
1789-
if (!ctx->Init(window, x, y, w, h, mode, &error_message)) {
1817+
if (!ctx->Init(window, x, y, w, h, mode, &error_message, force_gl_version)) {
17901818
printf("Failed to reinit graphics.\n");
17911819
}
17921820
}

0 commit comments

Comments
 (0)