Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 1 | #include "qemu/osdep.h" |
Marc-André Lureau | 1d48c9f | 2023-06-06 15:56:39 +0400 | [diff] [blame] | 2 | #include "qemu/error-report.h" |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 3 | #include "ui/egl-context.h" |
| 4 | |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 5 | QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc, |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 6 | QEMUGLParams *params) |
| 7 | { |
| 8 | EGLContext ctx; |
Gerd Hoffmann | 54d208f | 2018-06-18 13:21:41 +0200 | [diff] [blame] | 9 | EGLint ctx_att_core[] = { |
Gerd Hoffmann | bc8c946 | 2017-05-05 12:41:00 +0200 | [diff] [blame] | 10 | EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT, |
| 11 | EGL_CONTEXT_CLIENT_VERSION, params->major_ver, |
| 12 | EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver, |
| 13 | EGL_NONE |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 14 | }; |
Gerd Hoffmann | 54d208f | 2018-06-18 13:21:41 +0200 | [diff] [blame] | 15 | EGLint ctx_att_gles[] = { |
| 16 | EGL_CONTEXT_CLIENT_VERSION, params->major_ver, |
| 17 | EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver, |
| 18 | EGL_NONE |
| 19 | }; |
Markus Armbruster | 154fd4d | 2024-09-04 13:18:25 +0200 | [diff] [blame] | 20 | bool gles = (qemu_egl_mode == DISPLAY_GL_MODE_ES); |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 21 | |
| 22 | ctx = eglCreateContext(qemu_egl_display, qemu_egl_config, |
Gerd Hoffmann | 54d208f | 2018-06-18 13:21:41 +0200 | [diff] [blame] | 23 | eglGetCurrentContext(), |
| 24 | gles ? ctx_att_gles : ctx_att_core); |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 25 | return ctx; |
| 26 | } |
| 27 | |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 28 | void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx) |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 29 | { |
| 30 | eglDestroyContext(qemu_egl_display, ctx); |
| 31 | } |
| 32 | |
Marc-André Lureau | 5e79d51 | 2021-10-09 23:48:46 +0400 | [diff] [blame] | 33 | int qemu_egl_make_context_current(DisplayGLCtx *dgc, |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 34 | QEMUGLContext ctx) |
| 35 | { |
Marc-André Lureau | 1d48c9f | 2023-06-06 15:56:39 +0400 | [diff] [blame] | 36 | if (!eglMakeCurrent(qemu_egl_display, |
| 37 | EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) { |
| 38 | error_report("egl: eglMakeCurrent failed: %s", qemu_egl_get_error_string()); |
| 39 | return -1; |
| 40 | } |
| 41 | |
| 42 | return 0; |
Gerd Hoffmann | 6c18744 | 2015-04-29 10:08:04 +0200 | [diff] [blame] | 43 | } |