[mutter] cogl: Ignore GL_CONTEXT_LOST when checking for GL errors
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] cogl: Ignore GL_CONTEXT_LOST when checking for GL errors
- Date: Tue, 28 Jun 2016 17:54:49 +0000 (UTC)
commit d4d2bf0f6c1737256b921c4f1dedd3a95138cab9
Author: Rui Matos <tiagomatos gmail com>
Date: Tue May 24 19:37:02 2016 +0200
cogl: Ignore GL_CONTEXT_LOST when checking for GL errors
When using a context with robustness, glGetError() may return
GL_CONTEXT_LOST at any time and this error doesn't get cleared until
the application calls glGetGraphicsResetStatus() . This means that our
error checking can't call glGetError() in a loop without checking for
that return value and returning in that case.
https://bugzilla.gnome.org/show_bug.cgi?id=739178
cogl/cogl/cogl-texture-3d.c | 4 +--
cogl/cogl/cogl-texture-rectangle.c | 10 ++------
cogl/cogl/deprecated/cogl-shader.c | 5 +--
cogl/cogl/driver/gl/cogl-buffer-gl.c | 15 +++----------
cogl/cogl/driver/gl/cogl-pipeline-opengl.c | 7 +----
cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 16 ++++----------
cogl/cogl/driver/gl/cogl-util-gl-private.h | 10 +++++++-
cogl/cogl/driver/gl/cogl-util-gl.c | 22 +++++++++++++++++++-
.../driver/gl/gl/cogl-pipeline-fragend-arbfp.c | 6 +---
cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c | 12 ++--------
.../cogl/driver/gl/gles/cogl-texture-driver-gles.c | 18 ++++-----------
11 files changed, 56 insertions(+), 69 deletions(-)
---
diff --git a/cogl/cogl/cogl-texture-3d.c b/cogl/cogl/cogl-texture-3d.c
index 8e2ff08..31d2941 100644
--- a/cogl/cogl/cogl-texture-3d.c
+++ b/cogl/cogl/cogl-texture-3d.c
@@ -361,7 +361,6 @@ allocate_with_size (CoglTexture3D *tex_3d,
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
- GLenum gl_error;
GLenum gl_texture;
internal_format =
@@ -387,8 +386,7 @@ allocate_with_size (CoglTexture3D *tex_3d,
gl_texture,
FALSE);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage3D (GL_TEXTURE_3D, 0, gl_intformat,
width, height, depth,
diff --git a/cogl/cogl/cogl-texture-rectangle.c b/cogl/cogl/cogl-texture-rectangle.c
index 65d2f06..da5f1f0 100644
--- a/cogl/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl/cogl-texture-rectangle.c
@@ -228,7 +228,6 @@ allocate_with_size (CoglTextureRectangle *tex_rect,
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
- GLenum gl_error;
GLenum gl_texture;
internal_format =
@@ -256,8 +255,7 @@ allocate_with_size (CoglTextureRectangle *tex_rect,
tex_rect->is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
width, height, 0, gl_format, gl_type, NULL);
@@ -361,7 +359,6 @@ allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
CoglTexture *tex = COGL_TEXTURE (tex_rect);
CoglContext *ctx = tex->context;
CoglPixelFormat format = loader->src.gl_foreign.format;
- GLenum gl_error = 0;
GLint gl_compressed = GL_FALSE;
GLenum gl_int_format = 0;
@@ -377,12 +374,11 @@ allocate_from_gl_foreign (CoglTextureRectangle *tex_rect,
}
/* Make sure binding succeeds */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
loader->src.gl_foreign.gl_handle, TRUE);
- if (ctx->glGetError () != GL_NO_ERROR)
+ if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
diff --git a/cogl/cogl/deprecated/cogl-shader.c b/cogl/cogl/deprecated/cogl-shader.c
index 08dcb82..d4b687c 100644
--- a/cogl/cogl/deprecated/cogl-shader.c
+++ b/cogl/cogl/deprecated/cogl-shader.c
@@ -213,15 +213,14 @@ _cogl_shader_compile_real (CoglHandle handle,
g_message ("user ARBfp program:\n%s", shader->source);
#ifdef COGL_GL_DEBUG
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
#endif
ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
strlen (shader->source),
shader->source);
#ifdef COGL_GL_DEBUG
- gl_error = ctx->glGetError ();
+ gl_error = _cogl_gl_util_get_error (ctx);
if (gl_error != GL_NO_ERROR)
{
g_warning ("%s: GL error (%d): Failed to compile ARBfp:\n%s\n%s",
diff --git a/cogl/cogl/driver/gl/cogl-buffer-gl.c b/cogl/cogl/driver/gl/cogl-buffer-gl.c
index 0f98406..b8cd03f 100644
--- a/cogl/cogl/driver/gl/cogl-buffer-gl.c
+++ b/cogl/cogl/driver/gl/cogl-buffer-gl.c
@@ -142,7 +142,6 @@ recreate_store (CoglBuffer *buffer,
CoglContext *ctx = buffer->context;
GLenum gl_target;
GLenum gl_enum;
- GLenum gl_error;
/* This assumes the buffer is already bound */
@@ -150,8 +149,7 @@ recreate_store (CoglBuffer *buffer,
gl_enum = update_hints_to_gl_enum (buffer);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glBufferData (gl_target,
buffer->size,
@@ -216,7 +214,6 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
CoglBufferBindTarget target;
GLenum gl_target;
CoglContext *ctx = buffer->context;
- GLenum gl_error;
if (((access & COGL_BUFFER_ACCESS_READ) &&
!cogl_has_feature (ctx, COGL_FEATURE_ID_MAP_BUFFER_FOR_READ)) ||
@@ -282,8 +279,7 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
}
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
data = ctx->glMapBufferRange (gl_target,
offset,
@@ -314,8 +310,7 @@ _cogl_buffer_gl_map_range (CoglBuffer *buffer,
}
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
data = ctx->glMapBuffer (gl_target,
_cogl_buffer_access_to_gl_enum (access));
@@ -363,7 +358,6 @@ _cogl_buffer_gl_set_data (CoglBuffer *buffer,
CoglBufferBindTarget target;
GLenum gl_target;
CoglContext *ctx = buffer->context;
- GLenum gl_error;
CoglBool status = TRUE;
CoglError *internal_error = NULL;
@@ -384,8 +378,7 @@ _cogl_buffer_gl_set_data (CoglBuffer *buffer,
gl_target = convert_bind_target_to_gl_target (target);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glBufferSubData (gl_target, offset, size, data);
diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
index c7b44ee..52c2392 100644
--- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
+++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c
@@ -253,12 +253,9 @@ set_glsl_program (GLuint gl_program)
if (ctx->current_gl_program != gl_program)
{
- GLenum gl_error;
-
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glUseProgram (gl_program);
- if (ctx->glGetError () == GL_NO_ERROR)
+ if (_cogl_gl_util_get_error (ctx) == GL_NO_ERROR)
ctx->current_gl_program = gl_program;
else
{
diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
index 8675f52..1cae680 100644
--- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
+++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c
@@ -116,7 +116,6 @@ allocate_with_size (CoglTexture2D *tex_2d,
GLenum gl_intformat;
GLenum gl_format;
GLenum gl_type;
- GLenum gl_error;
GLenum gl_texture;
internal_format =
@@ -149,8 +148,7 @@ allocate_with_size (CoglTexture2D *tex_2d,
tex_2d->is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage2D (GL_TEXTURE_2D, 0, gl_intformat,
width, height, 0, gl_format, gl_type, NULL);
@@ -286,18 +284,16 @@ allocate_from_egl_image (CoglTexture2D *tex_2d,
CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context;
CoglPixelFormat internal_format = loader->src.egl_image.format;
- GLenum gl_error;
tex_2d->gl_texture =
ctx->texture_driver->gen (ctx, GL_TEXTURE_2D, internal_format);
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
tex_2d->gl_texture,
FALSE);
+ _cogl_gl_util_clear_gl_errors (ctx);
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
ctx->glEGLImageTargetTexture2D (GL_TEXTURE_2D, loader->src.egl_image.image);
- if (ctx->glGetError () != GL_NO_ERROR)
+ if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
{
_cogl_set_error (error,
COGL_TEXTURE_ERROR,
@@ -327,7 +323,6 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context;
CoglPixelFormat format = loader->src.gl_foreign.format;
- GLenum gl_error = 0;
GLint gl_compressed = GL_FALSE;
GLenum gl_int_format = 0;
@@ -342,12 +337,11 @@ allocate_from_gl_foreign (CoglTexture2D *tex_2d,
}
/* Make sure binding succeeds */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
loader->src.gl_foreign.gl_handle, TRUE);
- if (ctx->glGetError () != GL_NO_ERROR)
+ if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
diff --git a/cogl/cogl/driver/gl/cogl-util-gl-private.h b/cogl/cogl/driver/gl/cogl-util-gl-private.h
index dcc61c0..1407e0f 100644
--- a/cogl/cogl/driver/gl/cogl-util-gl-private.h
+++ b/cogl/cogl/driver/gl/cogl-util-gl-private.h
@@ -45,7 +45,7 @@ _cogl_gl_error_to_string (GLenum error_code);
#define GE(ctx, x) G_STMT_START { \
GLenum __err; \
(ctx)->x; \
- while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
+ while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR && __err != GL_CONTEXT_LOST) \
{ \
g_warning ("%s: GL error (%d): %s\n", \
G_STRLOC, \
@@ -56,7 +56,7 @@ _cogl_gl_error_to_string (GLenum error_code);
#define GE_RET(ret, ctx, x) G_STMT_START { \
GLenum __err; \
ret = (ctx)->x; \
- while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR) \
+ while ((__err = (ctx)->glGetError ()) != GL_NO_ERROR && __err != GL_CONTEXT_LOST) \
{ \
g_warning ("%s: GL error (%d): %s\n", \
G_STRLOC, \
@@ -71,6 +71,12 @@ _cogl_gl_error_to_string (GLenum error_code);
#endif /* COGL_GL_DEBUG */
+GLenum
+_cogl_gl_util_get_error (CoglContext *ctx);
+
+void
+_cogl_gl_util_clear_gl_errors (CoglContext *ctx);
+
CoglBool
_cogl_gl_util_catch_out_of_memory (CoglContext *ctx, CoglError **error);
diff --git a/cogl/cogl/driver/gl/cogl-util-gl.c b/cogl/cogl/driver/gl/cogl-util-gl.c
index a50a8a3..add2574 100644
--- a/cogl/cogl/driver/gl/cogl-util-gl.c
+++ b/cogl/cogl/driver/gl/cogl-util-gl.c
@@ -77,13 +77,33 @@ _cogl_gl_error_to_string (GLenum error_code)
}
#endif /* COGL_GL_DEBUG */
+GLenum
+_cogl_gl_util_get_error (CoglContext *ctx)
+{
+ GLenum gl_error = ctx->glGetError ();
+
+ if (gl_error != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
+ return gl_error;
+ else
+ return GL_NO_ERROR;
+}
+
+void
+_cogl_gl_util_clear_gl_errors (CoglContext *ctx)
+{
+ GLenum gl_error;
+
+ while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
+ ;
+}
+
CoglBool
_cogl_gl_util_catch_out_of_memory (CoglContext *ctx, CoglError **error)
{
GLenum gl_error;
CoglBool out_of_memory = FALSE;
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
+ while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR && gl_error != GL_CONTEXT_LOST)
{
if (gl_error == GL_OUT_OF_MEMORY)
out_of_memory = TRUE;
diff --git a/cogl/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
b/cogl/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
index 16b13be..7be4a3f 100644
--- a/cogl/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
+++ b/cogl/cogl/driver/gl/gl/cogl-pipeline-fragend-arbfp.c
@@ -837,7 +837,6 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
if (shader_state->source)
{
- GLenum gl_error;
COGL_STATIC_COUNTER (fragend_arbfp_compile_counter,
"arbfp compile counter",
"Increments each time a new ARBfp "
@@ -857,14 +856,13 @@ _cogl_pipeline_fragend_arbfp_end (CoglPipeline *pipeline,
GE (ctx, glBindProgram (GL_FRAGMENT_PROGRAM_ARB,
shader_state->gl_program));
+ _cogl_gl_util_clear_gl_errors (ctx);
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
ctx->glProgramString (GL_FRAGMENT_PROGRAM_ARB,
GL_PROGRAM_FORMAT_ASCII_ARB,
shader_state->source->len,
shader_state->source->str);
- if (ctx->glGetError () != GL_NO_ERROR)
+ if (_cogl_gl_util_get_error (ctx) != GL_NO_ERROR)
{
g_warning ("\n%s\n%s",
shader_state->source->str,
diff --git a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c
index 109af81..1113966 100644
--- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c
+++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c
@@ -207,7 +207,6 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
uint8_t *data;
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- GLenum gl_error;
CoglBool status = TRUE;
CoglError *internal_error = NULL;
int level_width;
@@ -237,8 +236,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
_cogl_texture_get_level_size (texture,
level,
@@ -315,7 +313,6 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
uint8_t *data;
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- GLenum gl_error;
CoglBool status = TRUE;
CoglError *internal_error = NULL;
@@ -341,8 +338,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage2D (gl_target, 0,
internal_gl_format,
@@ -377,7 +373,6 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
uint8_t *data;
CoglPixelFormat source_format = cogl_bitmap_get_format (source_bmp);
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
- GLenum gl_error;
CoglBool status = TRUE;
data = _cogl_bitmap_gl_bind (source_bmp, COGL_BUFFER_ACCESS_READ, 0, error);
@@ -394,8 +389,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage3D (gl_target,
0, /* level */
diff --git a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c
b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c
index f87f1e9..85412a8 100644
--- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c
+++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c
@@ -201,7 +201,6 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
int bpp = _cogl_pixel_format_get_bytes_per_pixel (source_format);
CoglBitmap *slice_bmp;
int rowstride;
- GLenum gl_error;
CoglBool status = TRUE;
CoglError *internal_error = NULL;
int level_width;
@@ -265,8 +264,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
_cogl_texture_get_level_size (texture,
level,
@@ -348,7 +346,6 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
int bmp_height = cogl_bitmap_get_height (source_bmp);
CoglBitmap *bmp;
uint8_t *data;
- GLenum gl_error;
CoglError *internal_error = NULL;
CoglBool status = TRUE;
@@ -379,8 +376,7 @@ _cogl_texture_driver_upload_to_gl (CoglContext *ctx,
}
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage2D (gl_target, 0,
internal_gl_format,
@@ -419,7 +415,6 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
int bmp_width = cogl_bitmap_get_width (source_bmp);
int bmp_height = cogl_bitmap_get_height (source_bmp);
uint8_t *data;
- GLenum gl_error;
_cogl_bind_gl_texture_transient (gl_target, gl_handle, is_foreign);
@@ -440,8 +435,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
image with a sub-region update */
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage3D (gl_target,
0, /* level */
@@ -488,8 +482,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
}
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexSubImage3D (gl_target,
0, /* level */
@@ -524,8 +517,7 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
_cogl_texture_driver_prep_gl_for_pixels_upload (ctx, rowstride, bpp);
/* Clear any GL errors */
- while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
- ;
+ _cogl_gl_util_clear_gl_errors (ctx);
ctx->glTexImage3D (gl_target,
0, /* level */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]