for (format = 0; format < GDK_MEMORY_N_FORMATS; format++)
{
GLenum q_internal_format, q_format, q_type;
+ GLint q_swizzle[4];
- if (!gdk_memory_format_gl_format (format, use_es, gl_major, gl_minor, &q_internal_format, &q_format, &q_type))
+ if (!gdk_memory_format_gl_format (format, use_es, gl_major, gl_minor, &q_internal_format, &q_format, &q_type, &q_swizzle))
continue;
if (q_format != gl_format || q_type != gl_type)
gsize expected_stride;
Download *download = download_;
GLenum gl_internal_format, gl_format, gl_type;
+ GLint gl_swizzle[4];
int major, minor;
expected_stride = texture->width * gdk_memory_format_bytes_per_pixel (download->format);
if (download->stride == expected_stride &&
!gdk_gl_context_get_use_es (context) &&
- gdk_memory_format_gl_format (download->format, TRUE, major, minor, &gl_internal_format, &gl_format, &gl_type))
+ gdk_memory_format_gl_format (download->format, TRUE, major, minor, &gl_internal_format, &gl_format, &gl_type, &gl_swizzle))
{
glGetTexImage (GL_TEXTURE_2D,
0,
guint gl_minor,
guint *out_internal_format,
guint *out_format,
- guint *out_type)
+ guint *out_type,
+ GLint (*out_swizzle)[4])
{
*out_internal_format = memory_formats[format].gl.internal_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);
if (memory_formats[format].alpha == GDK_MEMORY_ALPHA_STRAIGHT)
return FALSE;
#include "gdkenums.h"
+#include <epoxy/gl.h>
+
G_BEGIN_DECLS
typedef enum {
guint gl_minor,
guint *out_internal_format,
guint *out_format,
- guint *out_type);
+ guint *out_type,
+ GLint (*out_gizzle)[4]);
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,
guint minor,
guint *gl_internalformat,
guint *gl_format,
- guint *gl_type)
+ guint *gl_type,
+ GLint (*gl_swizzle)[4])
{
if (gdk_memory_format_gl_format (data_format,
use_es,
minor,
gl_internalformat,
gl_format,
- gl_type))
+ gl_type,
+ gl_swizzle))
return data_format;
if (gdk_memory_format_prefers_high_depth (data_format))
minor,
gl_internalformat,
gl_format,
- gl_type))
+ gl_type,
+ gl_swizzle))
return data_format;
}
minor,
gl_internalformat,
gl_format,
- gl_type))
+ gl_type,
+ gl_swizzle))
{
g_assert_not_reached ();
}
GLenum gl_internalformat;
GLenum gl_format;
GLenum gl_type;
+ GLint gl_swizzle[4];
gsize bpp;
gboolean use_es;
int major, minor;
minor,
&gl_internalformat,
&gl_format,
- &gl_type);
+ &gl_type,
+ &gl_swizzle);
gdk_texture_downloader_init (&downloader, texture);
gdk_texture_downloader_set_format (&downloader, data_format);
glPixelStorei (GL_UNPACK_ALIGNMENT, 4);
+ /* Only apply swizzle if really needed, might not even be
+ * supported if default values are set
+ */
+ if (gl_swizzle[0] != GL_RED || gl_swizzle[1] != GL_GREEN || gl_swizzle[2] != GL_BLUE)
+ {
+ /* Set each channel independently since GLES 3.0 doesn't support the iv method */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, gl_swizzle[0]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, gl_swizzle[1]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, gl_swizzle[2]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, gl_swizzle[3]);
+ }
+
g_bytes_unref (bytes);
}
GLenum gl_internalformat;
GLenum gl_format;
GLenum gl_type;
+ GLint gl_swizzle[4];
gboolean use_es;
int texture_id;
int major, minor;
minor,
&gl_internalformat,
&gl_format,
- &gl_type);
+ &gl_type,
+ &gl_swizzle);
glTexImage2D (GL_TEXTURE_2D, 0, gl_internalformat, width, height, 0, gl_format, gl_type, NULL);
case GDK_MEMORY_R16G16B16:
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
case GDK_MEMORY_R16G16B16A16:
+ case GDK_MEMORY_G8A8_PREMULTIPLIED:
+ case GDK_MEMORY_G8A8:
+ case GDK_MEMORY_G8:
+ case GDK_MEMORY_G16A16_PREMULTIPLIED:
+ case GDK_MEMORY_G16A16:
+ case GDK_MEMORY_G16:
+ case GDK_MEMORY_A8:
+ case GDK_MEMORY_A16:
bytes = gdk_texture_save_to_png_bytes (texture);
g_string_append (p->str, "url(\"data:image/png;base64,");
break;