static gboolean gdk_wayland_gl_context_realize (GdkGLContext *context, GError **error) { GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context); GdkDisplay *display = gdk_gl_context_get_display (context); GdkGLContext *share = gdk_gl_context_get_shared_context (context); GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); EGLContext ctx; EGLint context_attribs[N_EGL_ATTRS]; int major, minor, flags; gboolean debug_bit, forward_bit; int i = 0; gdk_gl_context_get_required_version (context, &major, &minor); debug_bit = gdk_gl_context_get_debug_enabled (context); forward_bit = gdk_gl_context_get_forward_compatible (context); flags = 0; if (debug_bit) flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; if (forward_bit) flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; /* We want a core profile */ context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR; context_attribs[i++] = EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; /* Specify the version */ context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR; context_attribs[i++] = major; context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR; context_attribs[i++] = minor; /* Specify the flags */ context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR; context_attribs[i++] = flags; context_attribs[i++] = EGL_NONE; g_assert (i < N_EGL_ATTRS); ctx = eglCreateContext (display_wayland->egl_display, context_wayland->egl_config, share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context : EGL_NO_CONTEXT, context_attribs); if (ctx == NULL) { g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE, _("Unable to create a GL context")); return FALSE; } GDK_NOTE (OPENGL, g_print ("Created EGL context[%p]\n", ctx)); context_wayland->egl_context = ctx; return TRUE; }
static gboolean gdk_wayland_gl_context_realize (GdkGLContext *context, GError **error) { GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context); GdkDisplay *display = gdk_gl_context_get_display (context); GdkGLContext *share = gdk_gl_context_get_shared_context (context); GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display); EGLContext ctx; EGLint context_attribs[N_EGL_ATTRS]; int major, minor, flags; gboolean debug_bit, forward_bit, legacy_bit, use_es; int i = 0; gdk_gl_context_get_required_version (context, &major, &minor); debug_bit = gdk_gl_context_get_debug_enabled (context); forward_bit = gdk_gl_context_get_forward_compatible (context); legacy_bit = (_gdk_gl_flags & GDK_GL_LEGACY) != 0 || (share != NULL && gdk_gl_context_is_legacy (share)); use_es = (_gdk_gl_flags & GDK_GL_GLES) != 0 || (share != NULL && gdk_gl_context_get_use_es (share)); flags = 0; if (debug_bit) flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR; if (forward_bit) flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR; if (!use_es) { eglBindAPI (EGL_OPENGL_API); /* We want a core profile, unless in legacy mode */ context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR; context_attribs[i++] = legacy_bit ? EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR : EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR; /* Specify the version */ context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR; context_attribs[i++] = legacy_bit ? 3 : major; context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR; context_attribs[i++] = legacy_bit ? 0 : minor; } else { eglBindAPI (EGL_OPENGL_ES_API); context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION; if (major == 3) context_attribs[i++] = 3; else context_attribs[i++] = 2; } /* Specify the flags */ context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR; context_attribs[i++] = flags; context_attribs[i++] = EGL_NONE; g_assert (i < N_EGL_ATTRS); GDK_NOTE (OPENGL, g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)", major, minor, debug_bit ? "yes" : "no", forward_bit ? "yes" : "no", legacy_bit ? "yes" : "no", use_es ? "yes" : "no")); ctx = eglCreateContext (display_wayland->egl_display, context_wayland->egl_config, share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context : EGL_NO_CONTEXT, context_attribs); /* If context creation failed without the legacy bit, let's try again with it */ if (ctx == NULL && !legacy_bit) { /* Ensure that re-ordering does not break the offsets */ g_assert (context_attribs[0] == EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); context_attribs[1] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR; context_attribs[3] = 3; context_attribs[5] = 0; eglBindAPI (EGL_OPENGL_API); legacy_bit = TRUE; use_es = FALSE; GDK_NOTE (OPENGL, g_message ("eglCreateContext failed, switching to legacy")); ctx = eglCreateContext (display_wayland->egl_display, context_wayland->egl_config, share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context : EGL_NO_CONTEXT, context_attribs); } if (ctx == NULL) { g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE, _("Unable to create a GL context")); return FALSE; } GDK_NOTE (OPENGL, g_message ("Created EGL context[%p]", ctx)); context_wayland->egl_context = ctx; gdk_gl_context_set_is_legacy (context, legacy_bit); gdk_gl_context_set_use_es (context, use_es); return TRUE; }