egl: fallback to a non-debug context if a debug one fails
authorMatthew Waters <ystreet00@gmail.com>
Fri, 22 Aug 2014 06:49:10 +0000 (16:49 +1000)
committerMatthew Waters <ystreet00@gmail.com>
Fri, 22 Aug 2014 06:51:29 +0000 (16:51 +1000)
The text for EGL_KHR_create_context added the possiblity for ES
contexts to ask for a debug context however that has not been
fully realized by all implementations.  Fallback to a non-debug
context when the implementation errors.

gst-libs/gst/gl/egl/gstglcontext_egl.c

index ab5d0e3..7ff5ae9 100644 (file)
@@ -328,6 +328,8 @@ gst_gl_context_egl_create_context (GstGLContext * context,
     goto failure;
   }
 
+  egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS);
+
   GST_DEBUG ("about to create gl context\n");
 
   if (egl->gl_api & GST_GL_API_GLES2) {
@@ -335,8 +337,10 @@ gst_gl_context_egl_create_context (GstGLContext * context,
     context_attrib[i++] = 2;
   }
 #if !defined(GST_DISABLE_GST_DEBUG)
-  context_attrib[i++] = EGL_CONTEXT_FLAGS_KHR;
-  context_attrib[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
+  if (gst_gl_check_extension ("EGL_KHR_create_context", egl_exts)) {
+    context_attrib[i++] = EGL_CONTEXT_FLAGS_KHR;
+    context_attrib[i++] = EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
+  }
 #endif
   context_attrib[i++] = EGL_NONE;
 
@@ -344,6 +348,21 @@ gst_gl_context_egl_create_context (GstGLContext * context,
       eglCreateContext (egl->egl_display, egl->egl_config,
       (EGLContext) external_gl_context, context_attrib);
 
+  if (egl->egl_context == EGL_NO_CONTEXT && egl->gl_api & GST_GL_API_GLES2
+      && eglGetError () != EGL_SUCCESS) {
+    /* try without EGL_CONTEXT_FLAGS flags as it was added to
+     * EGL_KHR_create_context for gles contexts */
+    int i;
+    for (i = 0; i < G_N_ELEMENTS (context_attrib); i++) {
+      if (context_attrib[i] == EGL_CONTEXT_FLAGS_KHR ||
+          context_attrib[i] == EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR)
+        context_attrib[i] = EGL_NONE;
+    }
+    egl->egl_context =
+        eglCreateContext (egl->egl_display, egl->egl_config,
+        (EGLContext) external_gl_context, context_attrib);
+  }
+
   if (egl->egl_context != EGL_NO_CONTEXT) {
     GST_INFO ("gl context created: %" G_GUINTPTR_FORMAT,
         (guintptr) egl->egl_context);
@@ -355,8 +374,6 @@ gst_gl_context_egl_create_context (GstGLContext * context,
     goto failure;
   }
 
-  egl_exts = eglQueryString (egl->egl_display, EGL_EXTENSIONS);
-
   if (other_context == NULL) {
     /* FIXME do we want a window vfunc ? */
 #if GST_GL_HAVE_WINDOW_X11