[gtk/gtk-4-6] gdk/gl: handle GL_RGBA/GL_UNSIGNED_NORMALIZED



commit cbd03cda5625ba4a0acfc37395ece2eef1335092
Author: Christian Hergert <chergert redhat com>
Date:   Wed Mar 23 20:20:02 2022 -0700

    gdk/gl: handle GL_RGBA/GL_UNSIGNED_NORMALIZED
    
    WebKit's GTK 4 port can give us textures with an internal format of
    GL_RGBA with GL_UNSIGNED_NORMALIZED and a bit-depth of 8. This fixes
    warnings for every GdkGLTexture created/delivered to the GskGLRenderer.
    
    The format is essentially the same as GL_RGBA8 since it is normalized
    between 0.0..1.0 for 8-bit components.
    
    Fixes #4783

 gdk/gdkgltexture.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
---
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 23bc806c0d..94d877e8a2 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -365,6 +365,42 @@ gdk_gl_texture_determine_format (GdkGLTexture *self)
       texture->format = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
       break;
 
+    case GL_RGBA:
+      {
+        GLint red_size = 0;
+        GLint green_size = 0;
+        GLint blue_size = 0;
+        GLint alpha_size = 0;
+        GLint red_type = 0;
+        GLint green_type = 0;
+        GLint blue_type = 0;
+        GLint alpha_type = 0;
+
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_RED_TYPE, &red_type);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_TYPE, &green_type);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_TYPE, &blue_type);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_TYPE, &alpha_type);
+
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &red_size);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &green_size);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &blue_size);
+        glGetTexLevelParameteriv (GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &alpha_size);
+
+#define CHECK_RGBA(rt,gt,bt,at,rs,gs,bs,as) \
+        (red_type == rt && green_type == gt && blue_type == bt && alpha_type == at && \
+         red_size == rs && green_size == gs && blue_size == bs && alpha_size == as)
+
+        if (CHECK_RGBA (GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, GL_UNSIGNED_NORMALIZED, 
GL_UNSIGNED_NORMALIZED, 8, 8, 8, 8))
+          {
+            texture->format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
+            break;
+          }
+
+#undef CHECK_RGBA
+      }
+
+      G_GNUC_FALLTHROUGH;
+
     default:
       g_warning ("Texture in unexpected format 0x%X (%d). File a bug about adding it to GTK", 
internal_format, internal_format);
       /* fallback to the dumbest possible format


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]