Merge branch 'wip/otte/for-main' into 'main'

gl: BGRA formats need a different internal format

Closes #6333

See merge request GNOME/gtk!6772
This commit is contained in:
Benjamin Otte 2024-01-16 21:21:17 +00:00
commit 9f8e84cb60
5 changed files with 97 additions and 37 deletions

View File

@ -161,7 +161,12 @@ gdk_gl_texture_find_format (GdkGLContext *context,
if (!(gdk_gl_context_get_format_flags (context, format) & GDK_GL_FORMAT_RENDERABLE))
continue;
gdk_memory_format_gl_format (format, &q_internal_format, &q_format, &q_type, q_swizzle);
gdk_memory_format_gl_format (format,
gdk_gl_context_get_use_es (context),
&q_internal_format,
&q_format,
&q_type,
q_swizzle);
if (q_format != gl_format || q_type != gl_type)
continue;
@ -193,6 +198,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
((gdk_gl_context_get_format_flags (context, format) & GDK_GL_FORMAT_USABLE) == GDK_GL_FORMAT_USABLE))
{
gdk_memory_format_gl_format (format,
gdk_gl_context_get_use_es (context),
&gl_internal_format,
&gl_format, &gl_type, gl_swizzle);
if (download->stride == expected_stride &&
@ -255,6 +261,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
actual_format = gdk_memory_format_get_straight (actual_format);
gdk_memory_format_gl_format (actual_format,
gdk_gl_context_get_use_es (context),
&gl_internal_format,
&gl_read_format, &gl_read_type, gl_swizzle);
}
@ -266,6 +273,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
actual_format = gdk_memory_format_get_straight (actual_format);
gdk_memory_format_gl_format (actual_format,
gdk_gl_context_get_use_es (context),
&gl_internal_format,
&gl_read_format, &gl_read_type, gl_swizzle);
}

View File

@ -335,7 +335,8 @@ struct _GdkMemoryFormatDescription
GdkMemoryDepth depth;
const GdkMemoryFormat *fallbacks;
struct {
GLint internal_format;
GLint internal_gl_format;
GLint internal_gles_format;
GLenum format;
GLenum type;
GLint swizzle[4];
@ -375,7 +376,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_BGRA,
.format = GL_BGRA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -402,7 +404,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_BGRA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -429,7 +432,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -455,7 +459,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -482,7 +487,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_BGRA,
.format = GL_BGRA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -509,7 +515,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_BGRA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -536,7 +543,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -562,7 +570,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -590,7 +599,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_BGRA,
.format = GL_BGRA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE },
@ -618,7 +628,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_BGRA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE },
@ -646,7 +657,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE },
@ -673,7 +685,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA8,
.internal_gl_format = GL_RGBA8,
.internal_gles_format = GL_RGBA8,
.format = GL_RGBA,
.type = GDK_GL_UNSIGNED_BYTE_FLIPPED,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE },
@ -701,7 +714,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGB8,
.internal_gl_format = GL_RGB8,
.internal_gles_format = GL_RGB8,
.format = GL_RGB,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -728,7 +742,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGB8,
.internal_gl_format = GL_RGB8,
.internal_gles_format = GL_RGB8,
.format = GL_BGR,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -759,7 +774,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGB16,
.internal_gl_format = GL_RGB16,
.internal_gles_format = GL_RGB16,
.format = GL_RGB,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -788,7 +804,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA16,
.internal_gl_format = GL_RGBA16,
.internal_gles_format = GL_RGBA16,
.format = GL_RGBA,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -817,7 +834,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA16,
.internal_gl_format = GL_RGBA16,
.internal_gles_format = GL_RGBA16,
.format = GL_RGBA,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -846,7 +864,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGB16F,
.internal_gl_format = GL_RGB16F,
.internal_gles_format = GL_RGB16F,
.format = GL_RGB,
.type = GL_HALF_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -874,7 +893,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA16F,
.internal_gl_format = GL_RGBA16F,
.internal_gles_format = GL_RGBA16F,
.format = GL_RGBA,
.type = GL_HALF_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -902,7 +922,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA16F,
.internal_gl_format = GL_RGBA16F,
.internal_gles_format = GL_RGBA16F,
.format = GL_RGBA,
.type = GL_HALF_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -931,7 +952,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGB32F,
.internal_gl_format = GL_RGB32F,
.internal_gles_format = GL_RGB32F,
.format = GL_RGB,
.type = GL_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -959,7 +981,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA32F,
.internal_gl_format = GL_RGBA32F,
.internal_gles_format = GL_RGBA32F,
.format = GL_RGBA,
.type = GL_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -987,7 +1010,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RGBA32F,
.internal_gl_format = GL_RGBA32F,
.internal_gles_format = GL_RGBA32F,
.format = GL_RGBA,
.type = GL_FLOAT,
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
@ -1014,7 +1038,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RG8,
.internal_gl_format = GL_RG8,
.internal_gles_format = GL_RG8,
.format = GL_RG,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
@ -1041,7 +1066,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RG8,
.internal_gl_format = GL_RG8,
.internal_gles_format = GL_RG8,
.format = GL_RG,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
@ -1068,7 +1094,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R8,
.internal_gl_format = GL_R8,
.internal_gles_format = GL_R8,
.format = GL_RED,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_ONE },
@ -1098,7 +1125,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RG16,
.internal_gl_format = GL_RG16,
.internal_gles_format = GL_RG16,
.format = GL_RG,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
@ -1128,7 +1156,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_RG16,
.internal_gl_format = GL_RG16,
.internal_gles_format = GL_RG16,
.format = GL_RG,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
@ -1158,7 +1187,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R16,
.internal_gl_format = GL_R16,
.internal_gles_format = GL_R16,
.format = GL_RED,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_ONE },
@ -1185,7 +1215,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R8,
.internal_gl_format = GL_R8,
.internal_gles_format = GL_R8,
.format = GL_RED,
.type = GL_UNSIGNED_BYTE,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
@ -1215,7 +1246,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R16,
.internal_gl_format = GL_R16,
.internal_gles_format = GL_R16,
.format = GL_RED,
.type = GL_UNSIGNED_SHORT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
@ -1244,7 +1276,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R16F,
.internal_gl_format = GL_R16F,
.internal_gles_format = GL_R16F,
.format = GL_RED,
.type = GL_HALF_FLOAT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
@ -1273,7 +1306,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
-1,
},
.gl = {
.internal_format = GL_R32F,
.internal_gl_format = GL_R32F,
.internal_gles_format = GL_R32F,
.format = GL_RED,
.type = GL_FLOAT,
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
@ -1473,12 +1507,16 @@ gdk_memory_depth_get_alpha_format (GdkMemoryDepth depth)
void
gdk_memory_format_gl_format (GdkMemoryFormat format,
gboolean gles,
GLint *out_internal_format,
GLenum *out_format,
GLenum *out_type,
GLint out_swizzle[4])
{
*out_internal_format = memory_formats[format].gl.internal_format;
if (gles)
*out_internal_format = memory_formats[format].gl.internal_gles_format;
else
*out_internal_format = memory_formats[format].gl.internal_gl_format;
*out_format = memory_formats[format].gl.format;
*out_type = memory_formats[format].gl.type;
memcpy (out_swizzle, memory_formats[format].gl.swizzle, sizeof(GLint) * 4);
@ -1487,6 +1525,7 @@ gdk_memory_format_gl_format (GdkMemoryFormat format,
/*
* gdk_memory_format_gl_rgba_format:
* @format: The format to query
* @gles: TRUE for GLES, FALSE for GL
* @out_actual_format: The actual RGBA format
* @out_internal_format: the GL internal format
* @out_format: the GL format
@ -1504,6 +1543,7 @@ gdk_memory_format_gl_format (GdkMemoryFormat format,
**/
gboolean
gdk_memory_format_gl_rgba_format (GdkMemoryFormat format,
gboolean gles,
GdkMemoryFormat *out_actual_format,
GLint *out_internal_format,
GLenum *out_format,
@ -1516,7 +1556,10 @@ gdk_memory_format_gl_rgba_format (GdkMemoryFormat format,
return FALSE;
*out_actual_format = actual;
*out_internal_format = memory_formats[actual].gl.internal_format;
if (gles)
*out_internal_format = memory_formats[actual].gl.internal_gles_format;
else
*out_internal_format = memory_formats[actual].gl.internal_gl_format;
*out_format = memory_formats[actual].gl.format;
*out_type = memory_formats[actual].gl.type;
memcpy (out_swizzle, memory_formats[format].gl.rgba_swizzle, sizeof(GLint) * 4);

View File

@ -55,11 +55,13 @@ GdkMemoryDepth gdk_memory_depth_merge (GdkMemoryDepth
GdkMemoryFormat gdk_memory_depth_get_format (GdkMemoryDepth depth) G_GNUC_CONST;
GdkMemoryFormat gdk_memory_depth_get_alpha_format (GdkMemoryDepth depth) G_GNUC_CONST;
void gdk_memory_format_gl_format (GdkMemoryFormat format,
gboolean gles,
GLint *out_internal_format,
GLenum *out_format,
GLenum *out_type,
GLint out_swizzle[4]);
gboolean gdk_memory_format_gl_rgba_format (GdkMemoryFormat format,
gboolean gles,
GdkMemoryFormat *out_actual_format,
GLint *out_internal_format,
GLenum *out_format,

View File

@ -1504,6 +1504,7 @@ memory_format_gl_format (GskGLCommandQueue *self,
if ((flags & required_flags) == required_flags)
{
gdk_memory_format_gl_format (data_format,
gdk_gl_context_get_use_es (self->context),
gl_internalformat,
gl_format,
gl_type,
@ -1514,6 +1515,7 @@ memory_format_gl_format (GskGLCommandQueue *self,
/* Second, try the potential RGBA format */
if (gdk_memory_format_gl_rgba_format (data_format,
gdk_gl_context_get_use_es (self->context),
&alt_format,
gl_internalformat,
gl_format,
@ -1529,6 +1531,7 @@ memory_format_gl_format (GskGLCommandQueue *self,
return data_format;
gdk_memory_format_gl_format (alt_format,
gdk_gl_context_get_use_es (self->context),
gl_internalformat,
gl_format,
gl_type,
@ -1546,6 +1549,7 @@ memory_format_gl_format (GskGLCommandQueue *self,
if (((flags & required_flags) == required_flags))
{
gdk_memory_format_gl_format (fallbacks[i],
gdk_gl_context_get_use_es (self->context),
gl_internalformat,
gl_format,
gl_type,

View File

@ -638,6 +638,7 @@ gsk_gl_device_find_gl_format (GskGLDevice *self,
*out_format = format;
*out_flags = flags;
gdk_memory_format_gl_format (format,
gdk_gl_context_get_use_es (context),
out_gl_internal_format,
out_gl_format,
out_gl_type,
@ -647,6 +648,7 @@ gsk_gl_device_find_gl_format (GskGLDevice *self,
/* Second, try the potential RGBA format */
if (gdk_memory_format_gl_rgba_format (format,
gdk_gl_context_get_use_es (context),
&alt_format,
out_gl_internal_format,
out_gl_format,
@ -670,6 +672,7 @@ gsk_gl_device_find_gl_format (GskGLDevice *self,
*out_format = fallbacks[i];
*out_flags = flags;
gdk_memory_format_gl_format (fallbacks[i],
gdk_gl_context_get_use_es (context),
out_gl_internal_format,
out_gl_format,
out_gl_type,