Skip to content

Commit

Permalink
SDL: try GLES2 context & fix core fallback
Browse files Browse the repository at this point in the history
* When compiled with USING_GLES2, attempt to use an ES 2.0 context.
* For non-ES targets, ensure that lower core profiles are attempted
rather than prematurely returning from the function after the first
failure.

Needed for Raspberry Pi to successfully launch.
  • Loading branch information
psyke83 committed Dec 20, 2017
1 parent 2822a4f commit 8ddf742
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions ext/native/base/PCMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,26 +589,33 @@ int main(int argc, char *argv[]) {
int minor;
};
GLVersionPair attemptVersions[] = {
#ifdef USING_GLES2
{2, 0},
#else
{4, 6}, {4, 5}, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0},
{3, 3}, {3, 2}, {3, 1}, {3, 0},
#endif
};

SDL_GLContext glContext = nullptr;
for (size_t i = 0; i < ARRAY_SIZE(attemptVersions); ++i) {
const auto &ver = attemptVersions[i];
// Make sure to request a somewhat modern GL context at least - the
// latest supported by MacOS X (really, really sad...)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, ver.major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, ver.minor);
#ifdef USING_GLES2
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SetGLCoreContext(false);
#else
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SetGLCoreContext(true);
#endif

g_Screen = SDL_CreateWindow(app_name_nice.c_str(), x,y, pixel_xres, pixel_yres, mode);
if (g_Screen == nullptr) {
NativeShutdown();
fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError());
SDL_Quit();
return 2;
continue;
}

glContext = SDL_GL_CreateContext(g_Screen);
Expand Down

0 comments on commit 8ddf742

Please sign in to comment.