Skip to content

Commit ff8b3b3

Browse files
committed
Experimental OpenGL 3 support for Mac
1 parent 11eb37c commit ff8b3b3

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/wx-sdl2-video-gl3.c

+35-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ extern int video_refresh_rate;
5757
static int glsl_version[2];
5858

5959
const char* vertex_shader_default_tex_src =
60+
#ifdef __APPLE__
61+
"#version 150\n"
62+
#else
6063
"#version 130\n"
64+
#endif
6165
"\n"
6266
"in vec4 VertexCoord;\n"
6367
"in vec2 TexCoord;\n"
@@ -71,7 +75,11 @@ const char* vertex_shader_default_tex_src =
7175
"}\n";
7276

7377
const char* fragment_shader_default_tex_src =
78+
#ifdef __APPLE__
79+
"#version 150\n"
80+
#else
7481
"#version 130\n"
82+
#endif
7583
"\n"
7684
"in vec2 texCoord;\n"
7785
"uniform sampler2D Texture;\n"
@@ -84,7 +92,11 @@ const char* fragment_shader_default_tex_src =
8492
"}\n";
8593

8694
const char* vertex_shader_default_color_src =
95+
#ifdef __APPLE__
96+
"#version 150\n"
97+
#else
8798
"#version 130\n"
99+
#endif
88100
"\n"
89101
"in vec4 VertexCoord;\n"
90102
"in vec4 Color;\n"
@@ -98,7 +110,11 @@ const char* vertex_shader_default_color_src =
98110
"}\n";
99111

100112
const char* fragment_shader_default_color_src =
113+
#ifdef __APPLE__
114+
"#version 150\n"
115+
#else
101116
"#version 130\n"
117+
#endif
102118
"\n"
103119
"in vec4 color;\n"
104120
"\n"
@@ -770,6 +786,13 @@ int gl3_init(SDL_Window* window, sdl_render_driver requested_render_driver, SDL_
770786

771787
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
772788

789+
#ifdef __APPLE__
790+
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
791+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
792+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
793+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
794+
#endif
795+
773796
context = SDL_GL_CreateContext(window);
774797

775798
if (!context)
@@ -1637,11 +1660,21 @@ int gl3_renderer_available(struct sdl_render_driver* driver)
16371660
if (available < 0)
16381661
{
16391662
available = 0;
1663+
1664+
// GL SetAttribute should be done *before* window creation for the attributes to apply on
1665+
// context creation (seems to depend on OpenGL impl. but it souldn't hurt other platforms
1666+
// to do it here (earlier than before)
1667+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
1668+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
1669+
1670+
#ifdef __APPLE__
1671+
// without an explicit request for the core profile 3.0 macOS falls back to default ancient 2.1
1672+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
1673+
#endif
1674+
16401675
SDL_Window* window = SDL_CreateWindow("GL3 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1, 1, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
16411676
if (window)
16421677
{
1643-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
1644-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
16451678

16461679
SDL_GLContext context = SDL_GL_CreateContext(window);
16471680
if (context)

0 commit comments

Comments
 (0)