egl-context.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "qemu/osdep.h"
  2. #include "qemu/error-report.h"
  3. #include "ui/egl-context.h"
  4. QEMUGLContext qemu_egl_create_context(DisplayGLCtx *dgc,
  5. QEMUGLParams *params)
  6. {
  7. EGLContext ctx;
  8. EGLint ctx_att_core[] = {
  9. EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT,
  10. EGL_CONTEXT_CLIENT_VERSION, params->major_ver,
  11. EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver,
  12. EGL_NONE
  13. };
  14. EGLint ctx_att_gles[] = {
  15. EGL_CONTEXT_CLIENT_VERSION, params->major_ver,
  16. EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver,
  17. EGL_NONE
  18. };
  19. bool gles = (qemu_egl_mode == DISPLAY_GL_MODE_ES);
  20. ctx = eglCreateContext(qemu_egl_display, qemu_egl_config,
  21. eglGetCurrentContext(),
  22. gles ? ctx_att_gles : ctx_att_core);
  23. return ctx;
  24. }
  25. void qemu_egl_destroy_context(DisplayGLCtx *dgc, QEMUGLContext ctx)
  26. {
  27. eglDestroyContext(qemu_egl_display, ctx);
  28. }
  29. int qemu_egl_make_context_current(DisplayGLCtx *dgc,
  30. QEMUGLContext ctx)
  31. {
  32. if (!eglMakeCurrent(qemu_egl_display,
  33. EGL_NO_SURFACE, EGL_NO_SURFACE, ctx)) {
  34. error_report("egl: eglMakeCurrent failed: %s", qemu_egl_get_error_string());
  35. return -1;
  36. }
  37. return 0;
  38. }