From 6f2688f776ea2500fa2b5055b3de5df1c8473ef5 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 24 Jan 2023 17:47:18 +0400 Subject: ui/sdl: get the GL context from the window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no guarantee to have a current GL context here. The current code seems to rely on the renderer using a GL backend, and to set a current GL context. But this is not always the case, for example if the renderer backend is DirectX. This change is enough to fix using virgl with sdl2 on win32, on my setup. Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- ui/sdl2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui/sdl2.c') diff --git a/ui/sdl2.c b/ui/sdl2.c index 8cb77416af..137f7ab57f 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -101,7 +101,7 @@ void sdl2_window_create(struct sdl2_console *scon) flags); scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0); if (scon->opengl) { - scon->winctx = SDL_GL_GetCurrentContext(); + scon->winctx = SDL_GL_CreateContext(scon->real_window); } sdl_update_caption(scon); } @@ -112,6 +112,8 @@ void sdl2_window_destroy(struct sdl2_console *scon) return; } + SDL_GL_DeleteContext(scon->winctx); + scon->winctx = NULL; SDL_DestroyRenderer(scon->real_renderer); scon->real_renderer = NULL; SDL_DestroyWindow(scon->real_window); -- cgit 1.4.1 From 82f483dd22c15277cea6047fd46671467eb289a9 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 15 Feb 2023 18:27:46 +0400 Subject: ui/sdl: add QEMU_ENABLE_SDL_LOGGING setting/environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable SDL logging when QEMU_ENABLE_SDL_LOGGING variable is set, as suggested by Sam Lantinga, upstream SDL maintainer. Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- ui/sdl2.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ui/sdl2.c') diff --git a/ui/sdl2.c b/ui/sdl2.c index 137f7ab57f..221cdced60 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -843,6 +843,10 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o) } #endif + if (SDL_GetHintBoolean("QEMU_ENABLE_SDL_LOGGING", SDL_FALSE)) { + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE); + } + if (SDL_Init(SDL_INIT_VIDEO)) { fprintf(stderr, "Could not initialize SDL(%s) - exiting\n", SDL_GetError()); -- cgit 1.4.1 From da3f7a3ab9ea0091955b58f8909dfcee01f4043e Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 15 Feb 2023 18:29:29 +0400 Subject: ui/sdl: try to instantiate the matching opengl renderer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -display sdl,gl=es didn't actually use OpenGL ES. Using OpenGL ES allows to use ANGLE, which works generally better than Windows/OEM OpenGL driver. (note: users can still bypass the QEMU choice with SDL_RENDER_DRIVER environment variable) (note: for some reason, specifying a driver disables batching and breaks rendering, so enable it explicitly) Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- ui/sdl2.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ui/sdl2.c') diff --git a/ui/sdl2.c b/ui/sdl2.c index 221cdced60..35c58c1104 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -58,6 +58,11 @@ static Notifier mouse_mode_notifier; #define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \ / SDL2_REFRESH_INTERVAL_BUSY + 1) +/* introduced in SDL 2.0.10 */ +#ifndef SDL_HINT_RENDER_BATCHING +#define SDL_HINT_RENDER_BATCHING "SDL_RENDER_BATCHING" +#endif + static void sdl_update_caption(struct sdl2_console *scon); static struct sdl2_console *get_scon_from_window(uint32_t window_id) @@ -99,7 +104,18 @@ void sdl2_window_create(struct sdl2_console *scon) surface_width(scon->surface), surface_height(scon->surface), flags); + if (scon->opengl) { + const char *driver = "opengl"; + + if (scon->opts->gl == DISPLAYGL_MODE_ES) { + driver = "opengles2"; + } + + SDL_SetHint(SDL_HINT_RENDER_DRIVER, driver); + SDL_SetHint(SDL_HINT_RENDER_BATCHING, "1"); + } scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0); + if (scon->opengl) { scon->winctx = SDL_GL_CreateContext(scon->real_window); } -- cgit 1.4.1