summaryrefslogtreecommitdiff
path: root/gdk/gdkmemoryformat.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2021-09-25 04:47:45 +0200
committerBenjamin Otte <otte@redhat.com>2021-10-06 22:50:07 +0200
commit149395c306bb13589c60d01024ad65d1bc07e99c (patch)
treeaf9ae3a8fe21d116d34b2b08058f9d0f3261ff5b /gdk/gdkmemoryformat.c
parent48781cf7f7b67fe2f769423150b8fecce67a3549 (diff)
downloadgtk+-149395c306bb13589c60d01024ad65d1bc07e99c.tar.gz
gl: Move memory <=> GL format mapping
Put it into gdkmemoryformat.c, where all the mapping goes.
Diffstat (limited to 'gdk/gdkmemoryformat.c')
-rw-r--r--gdk/gdkmemoryformat.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/gdk/gdkmemoryformat.c b/gdk/gdkmemoryformat.c
index 2a4cfa1e92..8b2ba6ae6d 100644
--- a/gdk/gdkmemoryformat.c
+++ b/gdk/gdkmemoryformat.c
@@ -23,6 +23,8 @@
#include "gsk/ngl/fp16private.h"
+#include <epoxy/gl.h>
+
typedef struct _GdkMemoryFormatDescription GdkMemoryFormatDescription;
typedef enum {
@@ -175,17 +177,32 @@ struct _GdkMemoryFormatDescription
GdkMemoryAlpha alpha;
gsize bytes_per_pixel;
gsize alignment;
-
+ gboolean supports_gles;
+ struct {
+ guint internal_format;
+ guint format;
+ guint type;
+ } gl;
/* no premultiplication going on here */
void (* to_float) (float *, const guchar*, gsize);
void (* from_float) (guchar *, const float *, gsize);
};
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+# define GDK_GL_UNSIGNED_BYTE_FLIPPED GL_UNSIGNED_INT_8_8_8_8
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+# define GDK_GL_UNSIGNED_BYTE_FLIPPED GL_UNSIGNED_INT_8_8_8_8_REV
+#else
+# error "Define the right GL flags here"
+#endif
+
static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
[GDK_MEMORY_B8G8R8A8_PREMULTIPLIED] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
4,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE },
b8g8r8a8_premultiplied_to_float,
b8g8r8a8_premultiplied_from_float,
},
@@ -193,6 +210,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
4,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGBA8, GL_BGRA, GDK_GL_UNSIGNED_BYTE_FLIPPED },
a8r8g8b8_premultiplied_to_float,
a8r8g8b8_premultiplied_from_float,
},
@@ -200,6 +219,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
4,
G_ALIGNOF (guchar),
+ TRUE,
+ { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE },
r8g8b8a8_premultiplied_to_float,
r8g8b8a8_premultiplied_from_float,
},
@@ -207,6 +228,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_STRAIGHT,
4,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE },
b8g8r8a8_to_float,
b8g8r8a8_from_float,
},
@@ -214,6 +237,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_STRAIGHT,
4,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGBA8, GL_RGBA, GDK_GL_UNSIGNED_BYTE_FLIPPED },
a8r8g8b8_to_float,
a8r8g8b8_from_float,
},
@@ -221,6 +246,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_STRAIGHT,
4,
G_ALIGNOF (guchar),
+ TRUE,
+ { GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE },
r8g8b8a8_to_float,
r8g8b8a8_from_float,
},
@@ -228,6 +255,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_STRAIGHT,
4,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGBA8, GL_BGRA, GDK_GL_UNSIGNED_BYTE_FLIPPED },
a8b8g8r8_to_float,
a8b8g8r8_from_float,
},
@@ -235,6 +264,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_OPAQUE,
3,
G_ALIGNOF (guchar),
+ TRUE,
+ { GL_RGBA8, GL_RGB, GL_UNSIGNED_BYTE },
r8g8b8_to_float,
r8g8b8_from_float,
},
@@ -242,6 +273,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_OPAQUE,
3,
G_ALIGNOF (guchar),
+ FALSE,
+ { GL_RGB8, GL_BGR, GL_UNSIGNED_BYTE },
b8g8r8_to_float,
b8g8r8_from_float,
},
@@ -249,6 +282,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_OPAQUE,
6,
G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGB16, GL_RGB, GL_UNSIGNED_SHORT },
r16g16b16_to_float,
r16g16b16_from_float,
},
@@ -256,6 +291,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
8,
G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT },
r16g16b16a16_to_float,
r16g16b16a16_from_float,
},
@@ -263,6 +300,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_OPAQUE,
6,
G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGB16F, GL_RGB, GL_HALF_FLOAT },
r16g16b16_float_to_float,
r16g16b16_float_from_float,
},
@@ -270,6 +309,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
8,
G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT },
r16g16b16a16_float_to_float,
r16g16b16a16_float_from_float,
},
@@ -277,6 +318,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_OPAQUE,
12,
G_ALIGNOF (float),
+ TRUE,
+ { GL_RGB32F, GL_RGB, GL_FLOAT },
r32g32b32_float_to_float,
r32g32b32_float_from_float,
},
@@ -284,6 +327,8 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
GDK_MEMORY_ALPHA_PREMULTIPLIED,
16,
G_ALIGNOF (float),
+ TRUE,
+ { GL_RGBA32F, GL_RGBA, GL_FLOAT },
r32g32b32a32_float_to_float,
r32g32b32a32_float_from_float,
}
@@ -301,6 +346,26 @@ gdk_memory_format_alignment (GdkMemoryFormat format)
return memory_formats[format].alignment;
}
+gboolean
+gdk_memory_format_gl_format (GdkMemoryFormat format,
+ gboolean gles,
+ guint *out_internal_format,
+ guint *out_format,
+ guint *out_type)
+{
+ *out_internal_format = memory_formats[format].gl.internal_format;
+ *out_format = memory_formats[format].gl.format;
+ *out_type = memory_formats[format].gl.type;
+
+ if (memory_formats[format].alpha == GDK_MEMORY_ALPHA_STRAIGHT)
+ return FALSE;
+
+ if (gles && !memory_formats[format].supports_gles)
+ return FALSE;
+
+ return TRUE;
+}
+
static void
premultiply (float *rgba,
gsize n)