From 5696d61a678ac8c15be1e88d005c9d7198c78698 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Wed, 12 Jul 2023 20:06:26 +0200 Subject: [PATCH] cogl: Fix opaque formats on GLES2 getting premultiplied On GLES2 reading and writing some Cogl formats is not supported natively. In those cases we use another format to do the reading and writing. When the internal format and the temporary format differ in premultiplication, Cogl tries to adjust for it. Opaque Cogl formats don't have the premult bit set but our internal format is a premult format. Cogl tries to adjust for it but completely misses that the opaque format doesn't have an alpha channel and it should not do so at all. So skip the premult adjusting when the Cogl format has no alpha channel. Part-of: --- cogl/cogl/driver/gl/cogl-framebuffer-gl.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c index f809d9382..fc955262d 100644 --- a/cogl/cogl/driver/gl/cogl-framebuffer-gl.c +++ b/cogl/cogl/driver/gl/cogl-framebuffer-gl.c @@ -537,8 +537,16 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, _cogl_bitmap_gl_unbind (tmp_bmp); + if (!(internal_format & COGL_A_BIT)) + { + _cogl_bitmap_set_format (tmp_bmp, read_format & ~COGL_PREMULT_BIT); + _cogl_bitmap_set_format (bitmap, format & ~COGL_PREMULT_BIT); + } + succeeded = _cogl_bitmap_convert_into_bitmap (tmp_bmp, bitmap, error); + _cogl_bitmap_set_format (bitmap, format); + cogl_object_unref (tmp_bmp); if (!succeeded) @@ -603,7 +611,8 @@ cogl_gl_framebuffer_read_pixels_into_bitmap (CoglFramebufferDriver *driver, /* Convert to the premult format specified by the caller in-place. This will do nothing if the premult status is already correct. */ - if (_cogl_bitmap_convert_premult_status (shared_bmp, format, error)) + if (!(internal_format & COGL_A_BIT) || + _cogl_bitmap_convert_premult_status (shared_bmp, format, error)) succeeded = TRUE; cogl_object_unref (shared_bmp);