macOS: Fix OpenGL 3 support.

This commit is contained in:
C.W. Betts 2021-05-22 11:35:59 -06:00
commit 366529ca35

View file

@ -769,6 +769,12 @@ int gl3_init(SDL_Window* window, sdl_render_driver requested_render_driver, SDL_
strcpy(current_render_driver_name, requested_render_driver.name); strcpy(current_render_driver_name, requested_render_driver.name);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#ifdef __APPLE__
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
context = SDL_GL_CreateContext(window); context = SDL_GL_CreateContext(window);
@ -1637,12 +1643,21 @@ int gl3_renderer_available(struct sdl_render_driver* driver)
if (available < 0) if (available < 0)
{ {
available = 0; available = 0;
// GL SetAttribute should be done *before* window creation for the attributes to apply on
// context creation (seems to depend on OpenGL impl. but it souldn't hurt other platforms
// to do it here (earlier than before)
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
#ifdef __APPLE__
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
#endif
SDL_Window* window = SDL_CreateWindow("GL3 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL); SDL_Window* window = SDL_CreateWindow("GL3 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
if (window) if (window)
{ {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GLContext context = SDL_GL_CreateContext(window); SDL_GLContext context = SDL_GL_CreateContext(window);
if (context) if (context)
{ {