Skip to content

Commit 041a619

Browse files
mohd-akramVisualEhrmanntraut
authored andcommitted
ui/sdl2: Fix using GL display on macOS
SDL_GL_CONTEXT_PROFILE_MASK needs to be set before creating the window so that SDL can load the ANGLE library for GL ES support. The shader source version also needs to match the library used.
1 parent e3c6b14 commit 041a619

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

ui/sdl2-gl.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ QEMUGLContext sdl2_gl_create_context(DisplayGLCtx *dgc,
150150
SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
151151

152152
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
153-
if (scon->opts->gl == DISPLAY_GL_MODE_ON ||
154-
scon->opts->gl == DISPLAY_GL_MODE_CORE) {
155-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
156-
SDL_GL_CONTEXT_PROFILE_CORE);
157-
} else if (scon->opts->gl == DISPLAY_GL_MODE_ES) {
158-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
159-
SDL_GL_CONTEXT_PROFILE_ES);
160-
}
161153
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, params->major_ver);
162154
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, params->minor_ver);
163155

ui/sdl2.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ void sdl2_window_create(struct sdl2_console *scon)
100100
#ifdef CONFIG_OPENGL
101101
if (scon->opengl) {
102102
flags |= SDL_WINDOW_OPENGL;
103+
if (scon->opts->gl == DISPLAY_GL_MODE_ON ||
104+
scon->opts->gl == DISPLAY_GL_MODE_CORE) {
105+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
106+
SDL_GL_CONTEXT_PROFILE_CORE);
107+
} else if (scon->opts->gl == DISPLAY_GL_MODE_ES) {
108+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
109+
SDL_GL_CONTEXT_PROFILE_ES);
110+
}
103111
}
104112
#endif
105113

ui/shader.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,24 @@ QemuGLShader *qemu_gl_init_shader(void)
153153
{
154154
QemuGLShader *gls = g_new0(QemuGLShader, 1);
155155

156+
const char *fmt = "#version %s\n%s";
157+
158+
const char *version = epoxy_is_desktop_gl() ? "140" : "300 es";
159+
160+
g_autofree const char *blit_vert_src = g_strdup_printf(
161+
fmt, version, texture_blit_vert_src);
162+
163+
g_autofree const char *blit_flip_vert_src = g_strdup_printf(
164+
fmt, version, texture_blit_flip_vert_src);
165+
166+
g_autofree const char *blit_frag_src = g_strdup_printf(
167+
fmt, version, texture_blit_frag_src);
168+
156169
gls->texture_blit_prog = qemu_gl_create_compile_link_program
157-
(texture_blit_vert_src, texture_blit_frag_src);
170+
(blit_vert_src, blit_frag_src);
158171
gls->texture_blit_flip_prog = qemu_gl_create_compile_link_program
159-
(texture_blit_flip_vert_src, texture_blit_frag_src);
172+
(blit_flip_vert_src, blit_frag_src);
173+
160174
if (!gls->texture_blit_prog || !gls->texture_blit_flip_prog) {
161175
exit(1);
162176
}

ui/shader/texture-blit-flip.vert

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#version 300 es
2-
31
in vec2 in_position;
42
out vec2 ex_tex_coord;
53

ui/shader/texture-blit.frag

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#version 300 es
2-
31
uniform sampler2D image;
42
in mediump vec2 ex_tex_coord;
53
out mediump vec4 out_frag_color;

ui/shader/texture-blit.vert

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#version 300 es
2-
31
in vec2 in_position;
42
out vec2 ex_tex_coord;
53

0 commit comments

Comments
 (0)