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
This commit is contained in:
Rui Matos 2016-05-24 19:37:02 +02:00
parent 0f2be43af4
commit d4d2bf0f6c
11 changed files with 56 additions and 69 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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",

View File

@ -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);

View File

@ -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
{

View File

@ -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,

View File

@ -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);

View File

@ -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;

View File

@ -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,

View File

@ -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 */

View File

@ -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 */