[gtk/gamma-shenanigans: 1/3] gdk: Upload 16bit images without conversion




commit 4273a2e658cde654d4c66dbaff81a243de4f8aac
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 5 19:50:53 2021 -0400

    gdk: Upload 16bit images without conversion
    
    GL can do this for us, so don't do extra work.

 gdk/gdkglcontext.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 58dba198ab..fbb2385d19 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -273,6 +273,12 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
           gl_type = GL_UNSIGNED_BYTE;
           bpp = 3;
         }
+      else if (data_format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
+        {
+          gl_format = GL_RGBA16;
+          gl_type = GL_UNSIGNED_SHORT;
+          bpp = 8;
+        }
       else /* Fall-back, convert to cairo-surface-format */
         {
           copy = g_malloc (width * height * 4);
@@ -288,10 +294,17 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
         }
     }
 
+  if (gl_format == GL_RGBA16)
+    {
+      glPixelStorei (GL_UNPACK_ALIGNMENT, 2);
+
+      glTexImage2D (texture_target, 0, GL_RGBA16, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT, data);
+      glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
+    }
   /* GL_UNPACK_ROW_LENGTH is available on desktop GL, OpenGL ES >= 3.0, or if
    * the GL_EXT_unpack_subimage extension for OpenGL ES 2.0 is available
    */
-  if (stride == width * bpp)
+  else if (stride == width * bpp)
     {
       glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
 


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