glcontext/egl: Prefer GLES2 over GL/GL3 by default

From a multimedia perspective GLES >= 2 has the big advantage of
supporting external textures (`OES_EGL_image_external` /
`OES_EGL_image_external_essl3`), allowing various YUV formats to be
imported directly by drivers.

It appears unlikely by now that the extension will ever be ported to
GL with Vulkan becoming more popular, leaving GL without an "official"
way to import YUV formats.

Further more, for Gst internal purposes it's likely that GLES2 works
equally well if not better on most drivers these days, especially on
embedded devices.

Thus switch the default for EGL context creation to GLES2. This won't
affect apps that create their own context, but `gst-launch-1.0` etc.,
which are often used for testing so people don't have to pass
`GST_GL_API=gles2`.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5509>
This commit is contained in:
Robert Mader 2023-10-19 00:55:58 +02:00 committed by GStreamer Marge Bot
parent 38a8411bdf
commit 414512d922

View file

@ -925,7 +925,55 @@ gst_gl_context_egl_create_context (GstGLContext * context,
gst_gl_context_egl_dump_all_configs (egl);
if (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3)) {
if (gl_api & GST_GL_API_GLES2) {
gint i;
try_gles2:
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
"Failed to bind OpenGL|ES API: %s",
gst_egl_get_error_string (eglGetError ()));
goto failure;
}
GST_INFO ("Bound OpenGL|ES");
for (i = 0; i < G_N_ELEMENTS (gles2_versions); i++) {
gint profileMask = 0;
gint contextFlags = 0;
guint maj = gles2_versions[i].major;
guint min = gles2_versions[i].minor;
if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_GLES2, maj, error)) {
GST_DEBUG_OBJECT (context, "Failed to choose a GLES%d config: %s",
maj, error && *error ? (*error)->message : "Unknown");
g_clear_error (error);
continue;
}
#if defined(EGL_KHR_create_context)
/* try a debug context */
contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
egl->egl_context =
_create_context_with_flags (egl, (EGLContext) external_gl_context,
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
if (egl->egl_context)
break;
/* try without a debug context */
contextFlags &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
#endif
egl->egl_context =
_create_context_with_flags (egl, (EGLContext) external_gl_context,
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
if (egl->egl_context)
break;
}
egl->gl_api = GST_GL_API_GLES2;
} else if (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3)) {
GstGLAPI chosen_gl_api = 0;
gint i;
@ -1015,54 +1063,6 @@ gst_gl_context_egl_create_context (GstGLContext * context,
}
egl->gl_api = chosen_gl_api;
} else if (gl_api & GST_GL_API_GLES2) {
gint i;
try_gles2:
if (!eglBindAPI (EGL_OPENGL_ES_API)) {
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
"Failed to bind OpenGL|ES API: %s",
gst_egl_get_error_string (eglGetError ()));
goto failure;
}
GST_INFO ("Bound OpenGL|ES");
for (i = 0; i < G_N_ELEMENTS (gles2_versions); i++) {
gint profileMask = 0;
gint contextFlags = 0;
guint maj = gles2_versions[i].major;
guint min = gles2_versions[i].minor;
if (!gst_gl_context_egl_choose_config (egl, GST_GL_API_GLES2, maj, error)) {
GST_DEBUG_OBJECT (context, "Failed to choose a GLES%d config: %s",
maj, error && *error ? (*error)->message : "Unknown");
g_clear_error (error);
continue;
}
#if defined(EGL_KHR_create_context)
/* try a debug context */
contextFlags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
egl->egl_context =
_create_context_with_flags (egl, (EGLContext) external_gl_context,
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
if (egl->egl_context)
break;
/* try without a debug context */
contextFlags &= ~EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
#endif
egl->egl_context =
_create_context_with_flags (egl, (EGLContext) external_gl_context,
GST_GL_API_GLES2, maj, min, contextFlags, profileMask);
if (egl->egl_context)
break;
}
egl->gl_api = GST_GL_API_GLES2;
}
if (egl->egl_context != EGL_NO_CONTEXT) {