blob: aed3e3ba1f3f433da8a7087d0634b54fdb2bd6d0 [file] [log] [blame]
Peter Maydelle16f4c82016-01-29 17:49:51 +00001#include "qemu/osdep.h"
Marc-André Lureau1d48c9f2023-06-06 15:56:39 +04002#include "qemu/error-report.h"
Gerd Hoffmann6c187442015-04-29 10:08:04 +02003#include "ui/egl-context.h"
4
Marc-André Lureau5e79d512021-10-09 23:48:46 +04005QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
Gerd Hoffmann6c187442015-04-29 10:08:04 +02006 QEMUGLParams *params)
7{
8 EGLContext ctx;
Gerd Hoffmann54d208f2018-06-18 13:21:41 +02009 EGLint ctx_att_core[] = {
Gerd Hoffmannbc8c9462017-05-05 12:41:00 +020010 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 Hoffmann6c187442015-04-29 10:08:04 +020014 };
Gerd Hoffmann54d208f2018-06-18 13:21:41 +020015 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 Armbruster154fd4d2024-09-04 13:18:25 +020020 bool gles = (qemu_egl_mode == DISPLAY_GL_MODE_ES);
Gerd Hoffmann6c187442015-04-29 10:08:04 +020021
22 ctx = eglCreateContext(qemu_egl_display, qemu_egl_config,
Gerd Hoffmann54d208f2018-06-18 13:21:41 +020023 eglGetCurrentContext(),
24 gles ? ctx_att_gles : ctx_att_core);
Gerd Hoffmann6c187442015-04-29 10:08:04 +020025 return ctx;
26}
27
Marc-André Lureau5e79d512021-10-09 23:48:46 +040028void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)
Gerd Hoffmann6c187442015-04-29 10:08:04 +020029{
30 eglDestroyContext(qemu_egl_display, ctx);
31}
32
Marc-André Lureau5e79d512021-10-09 23:48:46 +040033int qemu_egl_make_context_current(DisplayGLCtx *dgc,
Gerd Hoffmann6c187442015-04-29 10:08:04 +020034 QEMUGLContext ctx)
35{
Marc-André Lureau1d48c9f2023-06-06 15:56:39 +040036 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 Hoffmann6c187442015-04-29 10:08:04 +020043}