Blame SOURCES/video-memory-purge.patch

821e46
From c0bc9bef7fb7bb416acff6160338664a17874773 Mon Sep 17 00:00:00 2001
821e46
From: Adel Gadllah <adel.gadllah@gmail.com>
821e46
Date: Sun, 26 Jul 2015 11:27:00 +0200
821e46
Subject: [PATCH 1/5] winsys-glx: Add error traps in create_context
821e46
821e46
Both create_gl3_context and glXCreateNewContext can fail with an X error.
821e46
821e46
https://bugzilla.gnome.org/show_bug.cgi?id=742678
821e46
---
821e46
 cogl/winsys/cogl-winsys-glx.c | 5 ++++-
821e46
 1 file changed, 4 insertions(+), 1 deletion(-)
821e46
821e46
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
821e46
index 0487b79..4f7abfb 100644
821e46
--- a/cogl/winsys/cogl-winsys-glx.c
821e46
+++ b/cogl/winsys/cogl-winsys-glx.c
821e46
@@ -1075,6 +1075,8 @@ create_context (CoglDisplay *display, CoglError **error)
821e46
   COGL_NOTE (WINSYS, "Creating GLX Context (display: %p)",
821e46
              xlib_renderer->xdpy);
821e46
 
821e46
+  _cogl_xlib_renderer_trap_errors (display->renderer, &old_state);
821e46
+
821e46
   if (display->renderer->driver == COGL_DRIVER_GL3)
821e46
     glx_display->glx_context = create_gl3_context (display, config);
821e46
   else
821e46
@@ -1085,7 +1087,8 @@ create_context (CoglDisplay *display, CoglError **error)
821e46
                                          NULL,
821e46
                                          True);
821e46
 
821e46
-  if (glx_display->glx_context == NULL)
821e46
+  if (_cogl_xlib_renderer_untrap_errors (display->renderer, &old_state) ||
821e46
+      glx_display->glx_context == NULL)
821e46
     {
821e46
       _cogl_set_error (error, COGL_WINSYS_ERROR,
821e46
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
821e46
-- 
821e46
2.7.4
821e46
821e46
821e46
From 55af12d4ec146c610dd3c05d777f1ae33738c218 Mon Sep 17 00:00:00 2001
821e46
From: Emmanuele Bassi <ebassi@gnome.org>
821e46
Date: Thu, 6 Aug 2015 12:19:52 +0100
821e46
Subject: [PATCH 2/5] gl: Do not use deprecated constants with the GL3 driver
821e46
821e46
glGetIntegerv (GL_DEPTH_BITS, ...) and friends are deprecated in GL3; we
821e46
have to use glGetFramebufferAttachmentParameteriv() instead, like we do
821e46
for offscreen framebuffers.
821e46
821e46
Based on a patch by: Adel Gadllah <adel.gadllah@gmail.com>
821e46
Signed-off-by: Emmanuele Bassi <ebassi@gnome.org>
821e46
821e46
https://bugzilla.gnome.org/show_bug.cgi?id=753295
821e46
---
821e46
 cogl/driver/gl/cogl-framebuffer-gl.c | 46 ++++++++++++++++++++----------------
821e46
 1 file changed, 26 insertions(+), 20 deletions(-)
821e46
821e46
diff --git a/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/driver/gl/cogl-framebuffer-gl.c
821e46
index 793b10b..26bcc5f 100644
821e46
--- a/cogl/driver/gl/cogl-framebuffer-gl.c
821e46
+++ b/cogl/driver/gl/cogl-framebuffer-gl.c
821e46
@@ -1028,29 +1028,35 @@ _cogl_framebuffer_init_bits (CoglFramebuffer *framebuffer)
821e46
                                  COGL_FRAMEBUFFER_STATE_BIND);
821e46
 
821e46
 #ifdef HAVE_COGL_GL
821e46
-  if (_cogl_has_private_feature
821e46
-      (ctx, COGL_PRIVATE_FEATURE_QUERY_FRAMEBUFFER_BITS) &&
821e46
-      framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN)
821e46
+  if ((ctx->driver == COGL_DRIVER_GL3 &&
821e46
+       framebuffer->type == COGL_FRAMEBUFFER_TYPE_ONSCREEN) ||
821e46
+      (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_QUERY_FRAMEBUFFER_BITS) &&
821e46
+       framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN))
821e46
     {
821e46
-      static const struct
821e46
-      {
821e46
+      gboolean is_offscreen = framebuffer->type == COGL_FRAMEBUFFER_TYPE_OFFSCREEN;
821e46
+      const struct {
821e46
         GLenum attachment, pname;
821e46
         size_t offset;
821e46
-      } params[] =
821e46
-          {
821e46
-            { GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE,
821e46
-              offsetof (CoglFramebufferBits, red) },
821e46
-            { GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE,
821e46
-              offsetof (CoglFramebufferBits, green) },
821e46
-            { GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE,
821e46
-              offsetof (CoglFramebufferBits, blue) },
821e46
-            { GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE,
821e46
-              offsetof (CoglFramebufferBits, alpha) },
821e46
-            { GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
821e46
-              offsetof (CoglFramebufferBits, depth) },
821e46
-            { GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
821e46
-              offsetof (CoglFramebufferBits, stencil) },
821e46
-          };
821e46
+      } params[] = {
821e46
+        { is_offscreen ? GL_COLOR_ATTACHMENT0 : GL_BACK_LEFT,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE,
821e46
+          offsetof (CoglFramebufferBits, red) },
821e46
+        { is_offscreen ? GL_COLOR_ATTACHMENT0 : GL_BACK_LEFT,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE,
821e46
+          offsetof (CoglFramebufferBits, green) },
821e46
+        { is_offscreen ? GL_COLOR_ATTACHMENT0 : GL_BACK_LEFT,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE,
821e46
+          offsetof (CoglFramebufferBits, blue) },
821e46
+        { is_offscreen ? GL_COLOR_ATTACHMENT0 : GL_BACK_LEFT,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE,
821e46
+          offsetof (CoglFramebufferBits, alpha) },
821e46
+        { is_offscreen ? GL_DEPTH_ATTACHMENT : GL_DEPTH,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
821e46
+          offsetof (CoglFramebufferBits, depth) },
821e46
+        { is_offscreen ? GL_STENCIL_ATTACHMENT : GL_STENCIL,
821e46
+          GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
821e46
+          offsetof (CoglFramebufferBits, stencil) },
821e46
+      };
821e46
       int i;
821e46
 
821e46
       for (i = 0; i < G_N_ELEMENTS (params); i++)
821e46
-- 
821e46
2.7.4
821e46
821e46
821e46
From 067d3cb0f8a67a1c5ba144505c124ec42f409aaf Mon Sep 17 00:00:00 2001
821e46
From: Rui Matos <tiagomatos@gmail.com>
821e46
Date: Wed, 29 Jun 2016 15:37:14 +0200
821e46
Subject: [PATCH 3/5] cogl-winsys-glx: Add support for
821e46
 NV_robustness_video_memory_purge
821e46
821e46
This adds API to allow callers to specify that they're interested in
821e46
video memory purge errors.
821e46
821e46
https://bugzilla.gnome.org/show_bug.cgi?id=739178
821e46
---
821e46
 cogl/cogl-renderer-private.h            |  1 +
821e46
 cogl/cogl-renderer.c                    | 10 ++++++++
821e46
 cogl/cogl-xlib-renderer.h               | 41 +++++++++++++++++++++++++++++++
821e46
 cogl/cogl.symbols                       |  1 +
821e46
 cogl/gl-prototypes/cogl-all-functions.h |  8 ++++++
821e46
 cogl/winsys/cogl-winsys-glx.c           | 43 +++++++++++++++++++++++++++++++++
821e46
 6 files changed, 104 insertions(+)
821e46
821e46
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
821e46
index 3871d91..4a2fa6e 100644
821e46
--- a/cogl/cogl-renderer-private.h
821e46
+++ b/cogl/cogl-renderer-private.h
821e46
@@ -70,6 +70,7 @@ struct _CoglRenderer
821e46
 #ifdef COGL_HAS_XLIB_SUPPORT
821e46
   Display *foreign_xdpy;
821e46
   CoglBool xlib_enable_event_retrieval;
821e46
+  CoglBool xlib_want_reset_on_video_memory_purge;
821e46
 #endif
821e46
 
821e46
 #ifdef COGL_HAS_WIN32_SUPPORT
821e46
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
821e46
index ef6e900..52a4732 100644
821e46
--- a/cogl/cogl-renderer.c
821e46
+++ b/cogl/cogl-renderer.c
821e46
@@ -347,6 +347,16 @@ cogl_xlib_renderer_set_event_retrieval_enabled (CoglRenderer *renderer,
821e46
 
821e46
   renderer->xlib_enable_event_retrieval = enable;
821e46
 }
821e46
+
821e46
+void
821e46
+cogl_xlib_renderer_request_reset_on_video_memory_purge (CoglRenderer *renderer,
821e46
+                                                        CoglBool enable)
821e46
+{
821e46
+  _COGL_RETURN_IF_FAIL (cogl_is_renderer (renderer));
821e46
+  _COGL_RETURN_IF_FAIL (!renderer->connected);
821e46
+
821e46
+  renderer->xlib_want_reset_on_video_memory_purge = enable;
821e46
+}
821e46
 #endif /* COGL_HAS_XLIB_SUPPORT */
821e46
 
821e46
 CoglBool
821e46
diff --git a/cogl/cogl-xlib-renderer.h b/cogl/cogl-xlib-renderer.h
821e46
index 6318957..a81f275 100644
821e46
--- a/cogl/cogl-xlib-renderer.h
821e46
+++ b/cogl/cogl-xlib-renderer.h
821e46
@@ -169,6 +169,47 @@ cogl_xlib_renderer_set_event_retrieval_enabled (CoglRenderer *renderer,
821e46
 Display *
821e46
 cogl_xlib_renderer_get_display (CoglRenderer *renderer);
821e46
 
821e46
+/**
821e46
+ * cogl_xlib_renderer_request_reset_on_video_memory_purge:
821e46
+ * @renderer: a #CoglRenderer
821e46
+ * @enable: The new value
821e46
+ *
821e46
+ * Sets whether Cogl should make use of the
821e46
+ * NV_robustness_video_memory_purge extension, if exposed by the
821e46
+ * driver, by initializing the GLX context appropriately.
821e46
+ *
821e46
+ * The extension is only useful when running on certain versions of
821e46
+ * the NVIDIA driver. Quoting from the spec:
821e46
+ *
821e46
+ * "The NVIDIA OpenGL driver architecture on Linux has a limitation:
821e46
+ *  resources located in video memory are not persistent across certain
821e46
+ *  events. VT switches, suspend/resume events, and mode switching
821e46
+ *  events may erase the contents of video memory. Any resource that
821e46
+ *  is located exclusively in video memory, such as framebuffer objects
821e46
+ *  (FBOs), will be lost."
821e46
+ *
821e46
+ * "This extension provides a way for applications to discover when video
821e46
+ *  memory content has been lost, so that the application can re-populate
821e46
+ *  the video memory content as necessary."
821e46
+ *
821e46
+ * "Any driver that exposes this extension is a driver that considers
821e46
+ *  video memory to be volatile. Once the driver stack has been
821e46
+ *  improved, the extension will no longer be exposed."
821e46
+ *
821e46
+ * cogl_get_graphics_reset_status() needs to be called at least once
821e46
+ * every frame to find out if video memory was purged.
821e46
+ *
821e46
+ * Note that this doesn't cause Cogl to enable robust buffer access
821e46
+ * but other context reset errors may still happen and be reported via
821e46
+ * cogl_get_graphics_reset_status() if external factors cause the
821e46
+ * driver to trigger them.
821e46
+ *
821e46
+ * This defaults to %FALSE and is effective only if called before
821e46
+ * cogl_display_setup() .
821e46
+ */
821e46
+void
821e46
+cogl_xlib_renderer_request_reset_on_video_memory_purge (CoglRenderer *renderer,
821e46
+                                                        CoglBool enable);
821e46
 COGL_END_DECLS
821e46
 
821e46
 /* The gobject introspection scanner seems to parse public headers in
821e46
diff --git a/cogl/cogl.symbols b/cogl/cogl.symbols
821e46
index c48314a..feb9e65 100644
821e46
--- a/cogl/cogl.symbols
821e46
+++ b/cogl/cogl.symbols
821e46
@@ -1065,6 +1065,7 @@ cogl_xlib_renderer_get_display
821e46
 cogl_xlib_renderer_get_foreign_display
821e46
 cogl_xlib_renderer_handle_event
821e46
 cogl_xlib_renderer_remove_filter
821e46
+cogl_xlib_renderer_request_reset_on_video_memory_purge
821e46
 cogl_xlib_renderer_set_event_retrieval_enabled
821e46
 cogl_xlib_renderer_set_foreign_display
821e46
 cogl_xlib_set_display
821e46
diff --git a/cogl/gl-prototypes/cogl-all-functions.h b/cogl/gl-prototypes/cogl-all-functions.h
821e46
index dda08f7..c1c5462 100644
821e46
--- a/cogl/gl-prototypes/cogl-all-functions.h
821e46
+++ b/cogl/gl-prototypes/cogl-all-functions.h
821e46
@@ -326,3 +326,11 @@ COGL_EXT_BEGIN (draw_buffers, 2, 0,
821e46
 COGL_EXT_FUNCTION (void, glDrawBuffers,
821e46
                    (GLsizei n, const GLenum *bufs))
821e46
 COGL_EXT_END ()
821e46
+
821e46
+COGL_EXT_BEGIN (robustness, 255, 255,
821e46
+                0,
821e46
+                "ARB\0",
821e46
+                "robustness\0")
821e46
+COGL_EXT_FUNCTION (GLenum, glGetGraphicsResetStatus,
821e46
+                   (void))
821e46
+COGL_EXT_END ()
821e46
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
821e46
index 4f7abfb..097589f 100644
821e46
--- a/cogl/winsys/cogl-winsys-glx.c
821e46
+++ b/cogl/winsys/cogl-winsys-glx.c
821e46
@@ -71,6 +71,11 @@
821e46
 #include <GL/glx.h>
821e46
 #include <X11/Xlib.h>
821e46
 
821e46
+/* This is a relatively new extension */
821e46
+#ifndef GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV
821e46
+#define GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV 0x20F7
821e46
+#endif
821e46
+
821e46
 #define COGL_ONSCREEN_X11_EVENT_MASK (StructureNotifyMask | ExposureMask)
821e46
 #define MAX_GLX_CONFIG_ATTRIBS 30
821e46
 
821e46
@@ -1025,12 +1030,50 @@ create_gl3_context (CoglDisplay *display,
821e46
       GLX_CONTEXT_FLAGS_ARB,         GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
821e46
       None
821e46
     };
821e46
+  /* NV_robustness_video_memory_purge relies on GLX_ARB_create_context
821e46
+     and in part on ARB_robustness. Namely, it needs the notification
821e46
+     strategy to be set to GLX_LOSE_CONTEXT_ON_RESET_ARB and that the
821e46
+     driver exposes the GetGraphicsResetStatusARB function. This means
821e46
+     we don't actually enable robust buffer access. */
821e46
+  static const int attrib_list_reset_on_purge[] =
821e46
+    {
821e46
+      GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
821e46
+      GLX_CONTEXT_MINOR_VERSION_ARB, 1,
821e46
+      GLX_CONTEXT_PROFILE_MASK_ARB,  GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
821e46
+      GLX_CONTEXT_FLAGS_ARB,         GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
821e46
+      GLX_GENERATE_RESET_ON_VIDEO_MEMORY_PURGE_NV,
821e46
+                                     GL_TRUE,
821e46
+      GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
821e46
+                                     GLX_LOSE_CONTEXT_ON_RESET_ARB,
821e46
+      None
821e46
+    };
821e46
 
821e46
   /* Make sure that the display supports the GLX_ARB_create_context
821e46
      extension */
821e46
   if (glx_renderer->glXCreateContextAttribs == NULL)
821e46
     return NULL;
821e46
 
821e46
+  /* We can't check the presence of this extension with the usual
821e46
+     COGL_WINSYS_FEATURE machinery because that only gets initialized
821e46
+     later when the CoglContext is created. */
821e46
+  if (display->renderer->xlib_want_reset_on_video_memory_purge &&
821e46
+      strstr (glx_renderer->glXQueryExtensionsString (xlib_renderer->xdpy,
821e46
+                                                      DefaultScreen (xlib_renderer->xdpy)),
821e46
+              "GLX_NV_robustness_video_memory_purge"))
821e46
+    {
821e46
+      CoglXlibTrapState old_state;
821e46
+      GLXContext ctx;
821e46
+
821e46
+      _cogl_xlib_renderer_trap_errors (display->renderer, &old_state);
821e46
+      ctx = glx_renderer->glXCreateContextAttribs (xlib_renderer->xdpy,
821e46
+                                                   fb_config,
821e46
+                                                   NULL /* share_context */,
821e46
+                                                   True, /* direct */
821e46
+                                                   attrib_list_reset_on_purge);
821e46
+      if (!_cogl_xlib_renderer_untrap_errors (display->renderer, &old_state) && ctx)
821e46
+        return ctx;
821e46
+    }
821e46
+
821e46
   return glx_renderer->glXCreateContextAttribs (xlib_renderer->xdpy,
821e46
                                                 fb_config,
821e46
                                                 NULL /* share_context */,
821e46
-- 
821e46
2.7.4
821e46
821e46
821e46
From e91a1f5217d28e8e181e4fd98b78ec180d601228 Mon Sep 17 00:00:00 2001
821e46
From: Rui Matos <tiagomatos@gmail.com>
821e46
Date: Sun, 29 May 2016 20:30:36 +0200
821e46
Subject: [PATCH 4/5] cogl-context: Add a cogl_get_graphics_reset_status API
821e46
821e46
If the driver supports the GL_ARB_robustness extension we can expose
821e46
the graphics reset status this way.
821e46
821e46
https://bugzilla.gnome.org/show_bug.cgi?id=739178
821e46
---
821e46
 cogl/cogl-context.c | 30 ++++++++++++++++++++++++++++++
821e46
 cogl/cogl-context.h | 42 ++++++++++++++++++++++++++++++++++++++++++
821e46
 cogl/cogl.symbols   |  1 +
821e46
 3 files changed, 73 insertions(+)
821e46
821e46
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
821e46
index a7eed29..4b1af61 100644
821e46
--- a/cogl/cogl-context.c
821e46
+++ b/cogl/cogl-context.c
821e46
@@ -76,6 +76,11 @@
821e46
 #define GL_NUM_EXTENSIONS 0x821D
821e46
 #endif
821e46
 
821e46
+/* This is a relatively new extension */
821e46
+#ifndef GL_PURGED_CONTEXT_RESET_NV
821e46
+#define GL_PURGED_CONTEXT_RESET_NV 0x92BB
821e46
+#endif
821e46
+
821e46
 static void _cogl_context_free (CoglContext *context);
821e46
 
821e46
 COGL_OBJECT_DEFINE (Context, context);
821e46
@@ -784,3 +789,28 @@ cogl_get_clock_time (CoglContext *context)
821e46
   else
821e46
     return 0;
821e46
 }
821e46
+
821e46
+CoglGraphicsResetStatus
821e46
+cogl_get_graphics_reset_status (CoglContext *context)
821e46
+{
821e46
+  if (!context->glGetGraphicsResetStatus)
821e46
+    return COGL_GRAPHICS_RESET_STATUS_NO_ERROR;
821e46
+
821e46
+  switch (context->glGetGraphicsResetStatus ())
821e46
+    {
821e46
+    case GL_GUILTY_CONTEXT_RESET_ARB:
821e46
+      return COGL_GRAPHICS_RESET_STATUS_GUILTY_CONTEXT_RESET;
821e46
+
821e46
+    case GL_INNOCENT_CONTEXT_RESET_ARB:
821e46
+      return COGL_GRAPHICS_RESET_STATUS_INNOCENT_CONTEXT_RESET;
821e46
+
821e46
+    case GL_UNKNOWN_CONTEXT_RESET_ARB:
821e46
+      return COGL_GRAPHICS_RESET_STATUS_UNKNOWN_CONTEXT_RESET;
821e46
+
821e46
+    case GL_PURGED_CONTEXT_RESET_NV:
821e46
+      return COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET;
821e46
+
821e46
+    default:
821e46
+      return COGL_GRAPHICS_RESET_STATUS_NO_ERROR;
821e46
+    }
821e46
+}
821e46
diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h
821e46
index 07badeb..cab586b 100644
821e46
--- a/cogl/cogl-context.h
821e46
+++ b/cogl/cogl-context.h
821e46
@@ -393,6 +393,48 @@ cogl_foreach_feature (CoglContext *context,
821e46
 int64_t
821e46
 cogl_get_clock_time (CoglContext *context);
821e46
 
821e46
+/**
821e46
+ * CoglGraphicsResetStatus:
821e46
+ * @COGL_GRAPHICS_RESET_STATUS_NO_ERROR:
821e46
+ * @COGL_GRAPHICS_RESET_STATUS_GUILTY_CONTEXT_RESET:
821e46
+ * @COGL_GRAPHICS_RESET_STATUS_INNOCENT_CONTEXT_RESET:
821e46
+ * @COGL_GRAPHICS_RESET_STATUS_UNKNOWN_CONTEXT_RESET:
821e46
+ * @COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET:
821e46
+ *
821e46
+ * All the error values that might be returned by
821e46
+ * cogl_get_graphics_reset_status(). Each value's meaning corresponds
821e46
+ * to the similarly named value defined in the ARB_robustness and
821e46
+ * NV_robustness_video_memory_purge extensions.
821e46
+ */
821e46
+typedef enum _CoglGraphicsResetStatus
821e46
+{
821e46
+  COGL_GRAPHICS_RESET_STATUS_NO_ERROR,
821e46
+  COGL_GRAPHICS_RESET_STATUS_GUILTY_CONTEXT_RESET,
821e46
+  COGL_GRAPHICS_RESET_STATUS_INNOCENT_CONTEXT_RESET,
821e46
+  COGL_GRAPHICS_RESET_STATUS_UNKNOWN_CONTEXT_RESET,
821e46
+  COGL_GRAPHICS_RESET_STATUS_PURGED_CONTEXT_RESET,
821e46
+} CoglGraphicsResetStatus;
821e46
+
821e46
+/**
821e46
+ * cogl_get_graphics_reset_status:
821e46
+ * @context: a #CoglContext pointer
821e46
+ *
821e46
+ * Returns the graphics reset status as reported by
821e46
+ * GetGraphicsResetStatusARB defined in the ARB_robustness extension.
821e46
+ *
821e46
+ * Note that Cogl doesn't normally enable the ARB_robustness
821e46
+ * extension in which case this will only ever return
821e46
+ * #COGL_GRAPHICS_RESET_STATUS_NO_ERROR.
821e46
+ *
821e46
+ * Applications must explicitly use a backend specific method to
821e46
+ * request that errors get reported such as X11's
821e46
+ * cogl_xlib_renderer_request_reset_on_video_memory_purge().
821e46
+ *
821e46
+ * Return value: a #CoglGraphicsResetStatus
821e46
+ */
821e46
+CoglGraphicsResetStatus
821e46
+cogl_get_graphics_reset_status (CoglContext *context);
821e46
+
821e46
 #endif /* COGL_ENABLE_EXPERIMENTAL_API */
821e46
 
821e46
 COGL_END_DECLS
821e46
diff --git a/cogl/cogl.symbols b/cogl/cogl.symbols
821e46
index feb9e65..eb72407 100644
821e46
--- a/cogl/cogl.symbols
821e46
+++ b/cogl/cogl.symbols
821e46
@@ -334,6 +334,7 @@ cogl_get_clock_time
821e46
 cogl_get_depth_test_enabled
821e46
 cogl_get_draw_framebuffer
821e46
 cogl_get_features
821e46
+cogl_get_graphics_reset_status
821e46
 cogl_get_modelview_matrix
821e46
 cogl_get_option_group
821e46
 cogl_get_proc_address
821e46
-- 
821e46
2.7.4
821e46
821e46
821e46
From 6361d971c0775b4d7c20e3c2deb8c87ce546a94d Mon Sep 17 00:00:00 2001
821e46
From: Rui Matos <tiagomatos@gmail.com>
821e46
Date: Tue, 24 May 2016 19:37:02 +0200
821e46
Subject: [PATCH 5/5] cogl: Ignore GL_CONTEXT_LOST when checking for GL errors
821e46
821e46
When using a context with robustness, glGetError() may return
821e46
GL_CONTEXT_LOST at any time and this error doesn't get cleared until
821e46
the application calls glGetGraphicsResetStatus() . This means that our
821e46
error checking can't call glGetError() in a loop without checking for
821e46
that return value and returning in that case.
821e46
821e46
https://bugzilla.gnome.org/show_bug.cgi?id=739178
821e46
---
821e46
 cogl/cogl-texture-3d.c                          |  4 +---
821e46
 cogl/cogl-texture-rectangle.c                   | 10 +++-------
821e46
 cogl/deprecated/cogl-shader.c                   |  5 ++---
821e46
 cogl/driver/gl/cogl-buffer-gl.c                 | 15 ++++-----------
821e46
 cogl/driver/gl/cogl-pipeline-opengl.c           |  7 ++-----
821e46
 cogl/driver/gl/cogl-texture-2d-gl.c             | 16 +++++-----------
821e46
 cogl/driver/gl/cogl-util-gl-private.h           | 10 ++++++++--
821e46
 cogl/driver/gl/cogl-util-gl.c                   | 22 +++++++++++++++++++++-
821e46
 cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c |  6 ++----
821e46
 cogl/driver/gl/gl/cogl-texture-driver-gl.c      | 12 +++---------
821e46
 cogl/driver/gl/gles/cogl-texture-driver-gles.c  | 18 +++++-------------
821e46
 11 files changed, 56 insertions(+), 69 deletions(-)
821e46
821e46
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
821e46
index 8e2ff08..31d2941 100644
821e46
--- a/cogl/cogl-texture-3d.c
821e46
+++ b/cogl/cogl-texture-3d.c
821e46
@@ -361,7 +361,6 @@ allocate_with_size (CoglTexture3D *tex_3d,
821e46
   GLenum gl_intformat;
821e46
   GLenum gl_format;
821e46
   GLenum gl_type;
821e46
-  GLenum gl_error;
821e46
   GLenum gl_texture;
821e46
 
821e46
   internal_format =
821e46
@@ -387,8 +386,7 @@ allocate_with_size (CoglTexture3D *tex_3d,
821e46
                                    gl_texture,
821e46
                                    FALSE);
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage3D (GL_TEXTURE_3D, 0, gl_intformat,
821e46
                      width, height, depth,
821e46
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
821e46
index 65d2f06..da5f1f0 100644
821e46
--- a/cogl/cogl-texture-rectangle.c
821e46
+++ b/cogl/cogl-texture-rectangle.c
821e46
@@ -228,7 +228,6 @@ allocate_with_size (CoglTextureRectangle *tex_rect,
821e46
   GLenum gl_intformat;
821e46
   GLenum gl_format;
821e46
   GLenum gl_type;
821e46
-  GLenum gl_error;
821e46
   GLenum gl_texture;
821e46
 
821e46
   internal_format =
821e46
@@ -256,8 +255,7 @@ allocate_with_size (CoglTextureRectangle *tex_rect,
821e46
                                    tex_rect->is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
821e46
                      width, height, 0, gl_format, gl_type, NULL);
821e46
@@ -361,7 +359,6 @@ allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
821e46
   CoglTexture *tex = COGL_TEXTURE (tex_rect);
821e46
   CoglContext *ctx = tex->context;
821e46
   CoglPixelFormat format = loader->src.gl_foreign.format;
821e46
-  GLenum gl_error = 0;
821e46
   GLint gl_compressed = GL_FALSE;
821e46
   GLenum gl_int_format = 0;
821e46
 
821e46
@@ -377,12 +374,11 @@ allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
821e46
     }
821e46
 
821e46
   /* Make sure binding succeeds */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
821e46
                                    loader->src.gl_foreign.gl_handle, TRUE);
821e46
-  if (ctx->glGetError () != GL_NO_ERROR)
821e46
+  if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
821e46
     {
821e46
       _cogl_set_error (error,
821e46
                        COGL_SYSTEM_ERROR,
821e46
diff --git a/cogl/deprecated/cogl-shader.c b/cogl/deprecated/cogl-shader.c
821e46
index 08dcb82..d4b687c 100644
821e46
--- a/cogl/deprecated/cogl-shader.c
821e46
+++ b/cogl/deprecated/cogl-shader.c
821e46
@@ -213,15 +213,14 @@ _cogl_shader_compile_real (CoglHandle handle,
821e46
         g_message ("user ARBfp program:\n%s", shader->source);
821e46
 
821e46
 #ifdef COGL_GL_DEBUG
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 #endif
821e46
       ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
821e46
                             GL_PROGRAM_FORMAT_ASCII_ARB,
821e46
                             strlen (shader->source),
821e46
                             shader->source);
821e46
 #ifdef COGL_GL_DEBUG
821e46
-      gl_error = ctx->glGetError ();
821e46
+      gl_error = _cogl_gl_util_get_error (ctx);
821e46
       if (gl_error != GL_NO_ERROR)
821e46
         {
821e46
           g_warning ("%s: GL error (%d): Failed to compile ARBfp:\n%s\n%s",
821e46
diff --git a/cogl/driver/gl/cogl-buffer-gl.c b/cogl/driver/gl/cogl-buffer-gl.c
821e46
index 0f98406..b8cd03f 100644
821e46
--- a/cogl/driver/gl/cogl-buffer-gl.c
821e46
+++ b/cogl/driver/gl/cogl-buffer-gl.c
821e46
@@ -142,7 +142,6 @@ recreate_store (CoglBuffer *buffer,
821e46
   CoglContext *ctx = buffer->context;
821e46
   GLenum gl_target;
821e46
   GLenum gl_enum;
821e46
-  GLenum gl_error;
821e46
 
821e46
   /* This assumes the buffer is already bound */
821e46
 
821e46
@@ -150,8 +149,7 @@ recreate_store (CoglBuffer *buffer,
821e46
   gl_enum = update_hints_to_gl_enum (buffer);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glBufferData (gl_target,
821e46
                      buffer->size,
821e46
@@ -216,7 +214,6 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
821e46
   CoglBufferBindTarget target;
821e46
   GLenum gl_target;
821e46
   CoglContext *ctx = buffer->context;
821e46
-  GLenum gl_error;
821e46
 
821e46
   if (((access & COGL_BUFFER_ACCESS_READ) &&
821e46
        !cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_READ)) ||
821e46
@@ -282,8 +279,7 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
821e46
         }
821e46
 
821e46
       /* Clear any GL errors */
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
       data = ctx->glMapBufferRange (gl_target,
821e46
                                     offset,
821e46
@@ -314,8 +310,7 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
821e46
         }
821e46
 
821e46
       /* Clear any GL errors */
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
       data = ctx->glMapBuffer (gl_target,
821e46
                                _cogl_buffer_access_to_gl_enum (access));
821e46
@@ -363,7 +358,6 @@ _cogl_buffer_gl_set_data (CoglBuffer *buffer,
821e46
   CoglBufferBindTarget target;
821e46
   GLenum gl_target;
821e46
   CoglContext *ctx = buffer->context;
821e46
-  GLenum gl_error;
821e46
   CoglBool status = TRUE;
821e46
   CoglError *internal_error = NULL;
821e46
 
821e46
@@ -384,8 +378,7 @@ _cogl_buffer_gl_set_data (CoglBuffer *buffer,
821e46
   gl_target = convert_bind_target_to_gl_target (target);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glBufferSubData (gl_target, offset, size, data);
821e46
 
821e46
diff --git a/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/driver/gl/cogl-pipeline-opengl.c
821e46
index c7b44ee..52c2392 100644
821e46
--- a/cogl/driver/gl/cogl-pipeline-opengl.c
821e46
+++ b/cogl/driver/gl/cogl-pipeline-opengl.c
821e46
@@ -253,12 +253,9 @@ set_glsl_program (GLuint gl_program)
821e46
 
821e46
   if (ctx->current_gl_program != gl_program)
821e46
     {
821e46
-      GLenum gl_error;
821e46
-
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
       ctx->glUseProgram (gl_program);
821e46
-      if (ctx->glGetError () == GL_NO_ERROR)
821e46
+      if (_cogl_gl_util_get_error (ctx) == GL_NO_ERROR)
821e46
         ctx->current_gl_program = gl_program;
821e46
       else
821e46
         {
821e46
diff --git a/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/driver/gl/cogl-texture-2d-gl.c
821e46
index 8675f52..1cae680 100644
821e46
--- a/cogl/driver/gl/cogl-texture-2d-gl.c
821e46
+++ b/cogl/driver/gl/cogl-texture-2d-gl.c
821e46
@@ -116,7 +116,6 @@ allocate_with_size (CoglTexture2D *tex_2d,
821e46
   GLenum gl_intformat;
821e46
   GLenum gl_format;
821e46
   GLenum gl_type;
821e46
-  GLenum gl_error;
821e46
   GLenum gl_texture;
821e46
 
821e46
   internal_format =
821e46
@@ -149,8 +148,7 @@ allocate_with_size (CoglTexture2D *tex_2d,
821e46
                                    tex_2d->is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat,
821e46
                      width, height, 0, gl_format, gl_type, NULL);
821e46
@@ -286,18 +284,16 @@ allocate_from_egl_image (CoglTexture2D *tex_2d,
821e46
   CoglTexture *tex = COGL_TEXTURE (tex_2d);
821e46
   CoglContext *ctx = tex->context;
821e46
   CoglPixelFormat internal_format = loader->src.egl_image.format;
821e46
-  GLenum gl_error;
821e46
 
821e46
   tex_2d->gl_texture =
821e46
     ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
821e46
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
821e46
                                    tex_2d->gl_texture,
821e46
                                    FALSE);
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
   ctx->glEGLImageTargetTexture2D (GL_TEXTURE_2D, loader->src.egl_image.image);
821e46
-  if (ctx->glGetError () != GL_NO_ERROR)
821e46
+  if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
821e46
     {
821e46
       _cogl_set_error (error,
821e46
                        COGL_TEXTURE_ERROR,
821e46
@@ -327,7 +323,6 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
821e46
   CoglTexture *tex = COGL_TEXTURE (tex_2d);
821e46
   CoglContext *ctx = tex->context;
821e46
   CoglPixelFormat format = loader->src.gl_foreign.format;
821e46
-  GLenum gl_error = 0;
821e46
   GLint gl_compressed = GL_FALSE;
821e46
   GLenum gl_int_format = 0;
821e46
 
821e46
@@ -342,12 +337,11 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
821e46
     }
821e46
 
821e46
   /* Make sure binding succeeds */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
821e46
                                    loader->src.gl_foreign.gl_handle, TRUE);
821e46
-  if (ctx->glGetError () != GL_NO_ERROR)
821e46
+  if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
821e46
     {
821e46
       _cogl_set_error (error,
821e46
                        COGL_SYSTEM_ERROR,
821e46
diff --git a/cogl/driver/gl/cogl-util-gl-private.h b/cogl/driver/gl/cogl-util-gl-private.h
821e46
index dcc61c0..1407e0f 100644
821e46
--- a/cogl/driver/gl/cogl-util-gl-private.h
821e46
+++ b/cogl/driver/gl/cogl-util-gl-private.h
821e46
@@ -45,7 +45,7 @@ _cogl_gl_error_to_string (GLenum error_code);
821e46
 #define GE(ctx, x)                      G_STMT_START {  \
821e46
   GLenum __err;                                         \
821e46
   (ctx)->x;                                             \
821e46
-  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
821e46
+  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR && __err != GL_CONTEXT_LOST) \
821e46
     {                                                   \
821e46
       g_warning ("%s: GL error (%d): %s\n",             \
821e46
                  G_STRLOC,                              \
821e46
@@ -56,7 +56,7 @@ _cogl_gl_error_to_string (GLenum error_code);
821e46
 #define GE_RET(ret, ctx, x)             G_STMT_START {  \
821e46
   GLenum __err;                                         \
821e46
   ret = (ctx)->x;                                       \
821e46
-  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
821e46
+  while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR && __err != GL_CONTEXT_LOST) \
821e46
     {                                                   \
821e46
       g_warning ("%s: GL error (%d): %s\n",             \
821e46
                  G_STRLOC,                              \
821e46
@@ -71,6 +71,12 @@ _cogl_gl_error_to_string (GLenum error_code);
821e46
 
821e46
 #endif /* COGL_GL_DEBUG */
821e46
 
821e46
+GLenum
821e46
+_cogl_gl_util_get_error (CoglContext *ctx);
821e46
+
821e46
+void
821e46
+_cogl_gl_util_clear_gl_errors (CoglContext *ctx);
821e46
+
821e46
 CoglBool
821e46
 _cogl_gl_util_catch_out_of_memory (CoglContext *ctx, CoglError **error);
821e46
 
821e46
diff --git a/cogl/driver/gl/cogl-util-gl.c b/cogl/driver/gl/cogl-util-gl.c
821e46
index 814621a..f136673 100644
821e46
--- a/cogl/driver/gl/cogl-util-gl.c
821e46
+++ b/cogl/driver/gl/cogl-util-gl.c
821e46
@@ -77,13 +77,33 @@ _cogl_gl_error_to_string (GLenum error_code)
821e46
 }
821e46
 #endif /* COGL_GL_DEBUG */
821e46
 
821e46
+GLenum
821e46
+_cogl_gl_util_get_error (CoglContext *ctx)
821e46
+{
821e46
+  GLenum gl_error = ctx->glGetError ();
821e46
+
821e46
+  if (gl_error != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
821e46
+    return gl_error;
821e46
+  else
821e46
+    return GL_NO_ERROR;
821e46
+}
821e46
+
821e46
+void
821e46
+_cogl_gl_util_clear_gl_errors (CoglContext *ctx)
821e46
+{
821e46
+  GLenum gl_error;
821e46
+
821e46
+  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
821e46
+    ;
821e46
+}
821e46
+
821e46
 CoglBool
821e46
 _cogl_gl_util_catch_out_of_memory (CoglContext *ctx, CoglError **error)
821e46
 {
821e46
   GLenum gl_error;
821e46
   CoglBool out_of_memory = FALSE;
821e46
 
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
+  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
821e46
     {
821e46
       if (gl_error == GL_OUT_OF_MEMORY)
821e46
         out_of_memory = TRUE;
821e46
diff --git a/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c b/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
821e46
index 16b13be..7be4a3f 100644
821e46
--- a/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
821e46
+++ b/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
821e46
@@ -837,7 +837,6 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
821e46
 
821e46
   if (shader_state->source)
821e46
     {
821e46
-      GLenum gl_error;
821e46
       COGL_STATIC_COUNTER (fragend_arbfp_compile_counter,
821e46
                            "arbfp compile counter",
821e46
                            "Increments each time a new ARBfp "
821e46
@@ -857,14 +856,13 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
821e46
 
821e46
       GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB,
821e46
                               shader_state->gl_program));
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
       ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
821e46
                             GL_PROGRAM_FORMAT_ASCII_ARB,
821e46
                             shader_state->source->len,
821e46
                             shader_state->source->str);
821e46
-      if (ctx->glGetError () != GL_NO_ERROR)
821e46
+      if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
821e46
         {
821e46
           g_warning ("\n%s\n%s",
821e46
                      shader_state->source->str,
821e46
diff --git a/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/driver/gl/gl/cogl-texture-driver-gl.c
821e46
index 109af81..1113966 100644
821e46
--- a/cogl/driver/gl/gl/cogl-texture-driver-gl.c
821e46
+++ b/cogl/driver/gl/gl/cogl-texture-driver-gl.c
821e46
@@ -207,7 +207,6 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
821e46
   uint8_t *data;
821e46
   CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
821e46
   int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
821e46
-  GLenum gl_error;
821e46
   CoglBool status = TRUE;
821e46
   CoglError *internal_error = NULL;
821e46
   int level_width;
821e46
@@ -237,8 +236,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
821e46
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   _cogl_texture_get_level_size (texture,
821e46
                                 level,
821e46
@@ -315,7 +313,6 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
821e46
   uint8_t *data;
821e46
   CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
821e46
   int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
821e46
-  GLenum gl_error;
821e46
   CoglBool status = TRUE;
821e46
   CoglError *internal_error = NULL;
821e46
 
821e46
@@ -341,8 +338,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
821e46
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage2D (gl_target, 0,
821e46
                      internal_gl_format,
821e46
@@ -377,7 +373,6 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
   uint8_t *data;
821e46
   CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
821e46
   int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
821e46
-  GLenum gl_error;
821e46
   CoglBool status = TRUE;
821e46
 
821e46
   data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
821e46
@@ -394,8 +389,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage3D (gl_target,
821e46
                      0, /* level */
821e46
diff --git a/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
821e46
index f87f1e9..85412a8 100644
821e46
--- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c
821e46
+++ b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
821e46
@@ -201,7 +201,6 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
821e46
   int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
821e46
   CoglBitmap *slice_bmp;
821e46
   int rowstride;
821e46
-  GLenum gl_error;
821e46
   CoglBool status = TRUE;
821e46
   CoglError *internal_error = NULL;
821e46
   int level_width;
821e46
@@ -265,8 +264,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
821e46
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   _cogl_texture_get_level_size (texture,
821e46
                                 level,
821e46
@@ -348,7 +346,6 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
821e46
   int bmp_height = cogl_bitmap_get_height (source_bmp);
821e46
   CoglBitmap *bmp;
821e46
   uint8_t *data;
821e46
-  GLenum gl_error;
821e46
   CoglError *internal_error = NULL;
821e46
   CoglBool status = TRUE;
821e46
 
821e46
@@ -379,8 +376,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
821e46
     }
821e46
 
821e46
   /* Clear any GL errors */
821e46
-  while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-    ;
821e46
+  _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
   ctx->glTexImage2D (gl_target, 0,
821e46
                      internal_gl_format,
821e46
@@ -419,7 +415,6 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
   int bmp_width = cogl_bitmap_get_width (source_bmp);
821e46
   int bmp_height = cogl_bitmap_get_height (source_bmp);
821e46
   uint8_t *data;
821e46
-  GLenum gl_error;
821e46
 
821e46
   _cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
821e46
 
821e46
@@ -440,8 +435,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
          image with a sub-region update */
821e46
 
821e46
       /* Clear any GL errors */
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
       ctx->glTexImage3D (gl_target,
821e46
                          0, /* level */
821e46
@@ -488,8 +482,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
             }
821e46
 
821e46
           /* Clear any GL errors */
821e46
-          while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-            ;
821e46
+          _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
           ctx->glTexSubImage3D (gl_target,
821e46
                                 0, /* level */
821e46
@@ -524,8 +517,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
821e46
       _cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
821e46
 
821e46
       /* Clear any GL errors */
821e46
-      while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
821e46
-        ;
821e46
+      _cogl_gl_util_clear_gl_errors (ctx);
821e46
 
821e46
       ctx->glTexImage3D (gl_target,
821e46
                          0, /* level */
821e46
-- 
821e46
2.7.4
821e46