Skip to content

GtkGLArea red/blue channel swapping on OpenGL ES (GTK 3)

Benjamin Moody requested to merge benjaminmoody/gtk:gtk3-gles-red-blue into gtk-3-24

When using GtkGLArea on OpenGL ES, GDK wrongly swaps the red and blue channels (application draws a red teapot, blue teapot appears on screen.)

This is because the "software fallback" case in gdk_cairo_draw_from_gl uses the wrong channel order (except on Windows, for some reason.)

To be more precise: Cairo requires an image in one particular format (BGRA, on little-endian systems.) glReadPixels on OpenGL is required to support that format, but on OpenGL ES, it isn't required. Many OpenGL ES implementations do incidentally support BGRA, but by my reading of the specs, there's no way for them to advertise that support.

Consequently, GDK just uses the one format that is supported (RGBA) and forgets that this is the wrong format for cairo.

Note that this bug is also apparently present in GTK 4, although it doesn't affect GtkGLArea since GtkGLArea no longer uses gdk_cairo_draw_from_gl.

Merge request reports