浏览代码

ui/sdl: try to instantiate the matching opengl renderer

-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 <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Marc-André Lureau 2 年之前
父节点
当前提交
da3f7a3ab9
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      ui/sdl2.c

+ 16 - 0
ui/sdl2.c

@@ -58,6 +58,11 @@ static Notifier mouse_mode_notifier;
 #define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
 #define SDL2_MAX_IDLE_COUNT (2 * GUI_REFRESH_INTERVAL_DEFAULT \
                              / SDL2_REFRESH_INTERVAL_BUSY + 1)
                              / 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 void sdl_update_caption(struct sdl2_console *scon);
 
 
 static struct sdl2_console *get_scon_from_window(uint32_t window_id)
 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_width(scon->surface),
                                          surface_height(scon->surface),
                                          surface_height(scon->surface),
                                          flags);
                                          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);
     scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
+
     if (scon->opengl) {
     if (scon->opengl) {
         scon->winctx = SDL_GL_CreateContext(scon->real_window);
         scon->winctx = SDL_GL_CreateContext(scon->real_window);
     }
     }