[gtk/gamma-shenanigans: 5/7] Support 32-bit floating point textures




commit 120b6714267abcbd4fd91e1fdd7557c22a82ac40
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Sep 7 12:44:08 2021 -0400

    Support 32-bit floating point textures
    
    Add support for a R32G32B32_FLOAT format
    which is using floats.
    
    The intention is to use this for HDR content.
    
    Not done here: Update memory texture tests
    to include floating point textures.

 gdk/gdkglcontext.c            |  7 +++++++
 gdk/gdkgltexture.c            | 13 +++++++++++++
 gdk/gdkmemorytexture.c        |  3 +++
 gdk/gdkmemorytexture.h        |  2 ++
 testsuite/gdk/memorytexture.c |  3 ++-
 5 files changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 774d33780c..267b0303cc 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -292,6 +292,13 @@ gdk_gl_context_upload_texture (GdkGLContext    *context,
           gl_type = GL_HALF_FLOAT;
           bpp = 6;
         }
+      else if (data_format == GDK_MEMORY_R32G32B32_FLOAT)
+        {
+          gl_internalformat = GL_RGB32F;
+          gl_format = GL_RGB;
+          gl_type = GL_FLOAT;
+          bpp = 12;
+        }
       else /* Fall-back, convert to cairo-surface-format */
         {
           copy = g_malloc (width * height * 4);
diff --git a/gdk/gdkgltexture.c b/gdk/gdkgltexture.c
index 075c4cd583..704b39cb17 100644
--- a/gdk/gdkgltexture.c
+++ b/gdk/gdkgltexture.c
@@ -140,6 +140,19 @@ gdk_gl_texture_download_format (GdkTexture      *texture,
       glReadPixels (0, 0, texture->width, texture->height,
                     GL_RGBA16, GL_UNSIGNED_SHORT, data);
 
+      return g_bytes_new_take (data, size);
+    }
+  else if (format == GDK_MEMORY_R32G32B32_FLOAT)
+    {
+      if (format != GL_RGB32F)
+        return NULL;
+
+      size = texture->width * texture->height * 3 * sizeof (float);
+      data = malloc (size);
+
+      glReadPixels (0, 0, texture->width, texture->height,
+                    GL_RGBA32F, GL_FLOAT, data);
+
       return g_bytes_new_take (data, size);
     }
   else
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index bd00d71795..dd112dfb30 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -69,6 +69,9 @@ gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format)
     case GDK_MEMORY_R16G16B16_FLOAT:
       return 6;
 
+    case GDK_MEMORY_R32G32B32_FLOAT:
+      return 12;
+
     case GDK_MEMORY_N_FORMATS:
     default:
       g_assert_not_reached ();
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 07ff7ac0a8..c9eabb4a3f 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -45,6 +45,7 @@ G_BEGIN_DECLS
  * @GDK_MEMORY_R16G16B16A16_PREMULTIPLIED: 4 guint16 values; for red, green, blue, alpha.
  *   The color values are premultiplied with the alpha value.
  * @GDK_MEMORY_B16G16R16_FLOAT: 3 half-float values; for blue, green, red. The data is opaque.
+ * @GDK_MEMORY_B32G32R32_FLOAT: 3 float values; for blue, green, red. The data is opaque.
  * @GDK_MEMORY_N_FORMATS: The number of formats. This value will change as
  *   more formats get added, so do not rely on its concrete integer.
  *
@@ -74,6 +75,7 @@ typedef enum {
   GDK_MEMORY_B8G8R8,
   GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
   GDK_MEMORY_R16G16B16_FLOAT,
+  GDK_MEMORY_R32G32B32_FLOAT,
 
   GDK_MEMORY_N_FORMATS
 } GdkMemoryFormat;
diff --git a/testsuite/gdk/memorytexture.c b/testsuite/gdk/memorytexture.c
index 099cbacdf1..92f9d8f472 100644
--- a/testsuite/gdk/memorytexture.c
+++ b/testsuite/gdk/memorytexture.c
@@ -189,7 +189,8 @@ main (int argc, char *argv[])
 
   for (format = 0; format < GDK_MEMORY_N_FORMATS; format++)
     {
-      if (format == GDK_MEMORY_R16G16B16_FLOAT)
+      if (format == GDK_MEMORY_R16G16B16_FLOAT ||
+          format == GDK_MEMORY_R32G32B32_FLOAT)
         continue;
 
       for (color = 0; color < N_COLORS; color++)


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