From 673bd650906a1cb8e11eee8916fcf0e594a7f83b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Potomski?= Date: Sun, 19 Nov 2023 17:18:05 +0000 Subject: [PATCH] gl: Limit glGetTexLevelParameteriv use to supported platforms --- gdk/gdkgl.c | 15 +++++++++++++-- gdk/gdkglcontext.c | 12 ++++++++++++ gdk/gdkglcontextprivate.h | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gdk/gdkgl.c b/gdk/gdkgl.c index 62eeada105..7c423b3dfb 100644 --- a/gdk/gdkgl.c +++ b/gdk/gdkgl.c @@ -392,7 +392,17 @@ gdk_cairo_draw_from_gl (cairo_t *cr, else if (source_type == GL_TEXTURE) { glBindTexture (GL_TEXTURE_2D, source); - glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size); + if (gdk_gl_context_has_tex_param (paint_context)) + { + glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size); + } + else + { + alpha_size = 1; + if (gdk_gl_context_has_tex_param (paint_context)) + glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size); + else + alpha_size = 1; } else { @@ -538,7 +548,8 @@ gdk_cairo_draw_from_gl (cairo_t *cr, glBindTexture (GL_TEXTURE_2D, source); - if (gdk_gl_context_get_use_es (paint_context)) + if (gdk_gl_context_get_use_es (paint_context) || + !gdk_gl_context_has_tex_param (paint_context)) { texture_width = width; texture_height = height; diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index 80d126f2de..cb0ed906e8 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -107,6 +107,7 @@ typedef struct { guint debug_enabled : 1; guint forward_compatible : 1; guint is_legacy : 1; + guint has_tex_param : 1; int use_es; @@ -435,6 +436,14 @@ gdk_gl_context_has_frame_terminator (GdkGLContext *context) return priv->has_frame_terminator; } +gboolean +gdk_gl_context_has_tex_param (GdkGLContext *context) +{ + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + return priv->has_tex_param; +} + gboolean gdk_gl_context_has_unpack_subimage (GdkGLContext *context) { @@ -829,6 +838,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context) priv->has_unpack_subimage = epoxy_has_gl_extension ("GL_EXT_unpack_subimage"); priv->has_sync = priv->gl_version >= 30; priv->has_texture_format_bgra = epoxy_has_gl_extension ("GL_EXT_texture_format_BGRA8888"); + priv->has_tex_param = priv->gl_version >= 31; } else { @@ -838,6 +848,8 @@ gdk_gl_context_check_extensions (GdkGLContext *context) priv->has_gl_framebuffer_blit = priv->gl_version >= 30 || epoxy_has_gl_extension ("GL_EXT_framebuffer_blit"); priv->has_frame_terminator = epoxy_has_gl_extension ("GL_GREMEDY_frame_terminator"); priv->has_unpack_subimage = TRUE; + priv->has_tex_param = priv->gl_version >= 10 && + epoxy_is_desktop_gl (); priv->has_sync = priv->gl_version >= 32 || epoxy_has_gl_extension ("GL_ARB_sync") || epoxy_has_gl_extension ("GL_APPLE_sync"); diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h index 731bf3e384..7578a6b27b 100644 --- a/gdk/gdkglcontextprivate.h +++ b/gdk/gdkglcontextprivate.h @@ -85,6 +85,7 @@ GdkGLContextPaintData * gdk_gl_context_get_paint_data (GdkGLContext gboolean gdk_gl_context_use_texture_rectangle (GdkGLContext *context); gboolean gdk_gl_context_has_framebuffer_blit (GdkGLContext *context); gboolean gdk_gl_context_has_frame_terminator (GdkGLContext *context); +gboolean gdk_gl_context_has_tex_param (GdkGLContext *context); gboolean gdk_gl_context_has_unpack_subimage (GdkGLContext *context); gboolean gdk_gl_context_has_sync (GdkGLContext *context); gboolean gdk_gl_context_has_texture_format_bgra (GdkGLContext *context);