From 8d179c078de6de97681224aea82d7de6a1563f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 10 Oct 2022 09:20:36 +0200 Subject: cogl/driver/gles: Fix RGB10 GL formats COGL_PIXEL_FORMAT_ABGR_2101010 is defined to mean the 2 A bits are placed in a 32 bit unsigned integer on the bits with highest significance, followed by B on the following 10 bits, and so on, until R on the 10 least significant bits. UNSIGNED_INT_2_10_10_10_REV_EXT is defined to represent color channels as ``` 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ------------------------------------------------------------------------------------- | a | b | g | r | ------------------------------------------------------------------------------------- ``` As can be seen, this matches COGL_PIXEL_FORMAT_ABGR_2101010, meaning that's the format we can directly read and write. In Cogl, when finding the GL formats, we get the tuple with the GL format given the format we pass, but we also get returned "required format" (CoglPixelFormat). This required format represents the format that is required when reading actual pixels from GLES. In GLES, the above mentioned format is the only one supported by the EXT_texture_type_2_10_10_10_REV extension, thus for other types, we need to do the CPU side conversion ourselves. To achieve this, correctly return COGL_PIXEL_FORMAT_ABGR_2101010 as the required format. The internal format should also be GL_RGB10_A2, not GL_RGBA. Part-of: --- cogl/cogl/driver/gl/gles/cogl-driver-gles.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c index 0904f5a04..59cf0c07e 100644 --- a/cogl/cogl/driver/gl/gles/cogl-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-driver-gles.c @@ -143,24 +143,24 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context, required_format = COGL_PIXEL_FORMAT_RGB_888; break; - case COGL_PIXEL_FORMAT_RGBA_1010102: - case COGL_PIXEL_FORMAT_RGBA_1010102_PRE: + case COGL_PIXEL_FORMAT_ABGR_2101010: + case COGL_PIXEL_FORMAT_ABGR_2101010_PRE: #if G_BYTE_ORDER == G_LITTLE_ENDIAN if (_cogl_has_private_feature (context, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_RGBA1010102)) { - glintformat = GL_RGBA; + glintformat = GL_RGB10_A2_EXT; glformat = GL_RGBA; gltype = GL_UNSIGNED_INT_2_10_10_10_REV_EXT; break; } G_GNUC_FALLTHROUGH; #endif + case COGL_PIXEL_FORMAT_RGBA_1010102: + case COGL_PIXEL_FORMAT_RGBA_1010102_PRE: case COGL_PIXEL_FORMAT_BGRA_1010102: case COGL_PIXEL_FORMAT_BGRA_1010102_PRE: case COGL_PIXEL_FORMAT_XBGR_2101010: - case COGL_PIXEL_FORMAT_ABGR_2101010: - case COGL_PIXEL_FORMAT_ABGR_2101010_PRE: case COGL_PIXEL_FORMAT_XRGB_2101010: case COGL_PIXEL_FORMAT_ARGB_2101010: case COGL_PIXEL_FORMAT_ARGB_2101010_PRE: @@ -168,10 +168,10 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context, if (_cogl_has_private_feature (context, COGL_PRIVATE_FEATURE_TEXTURE_FORMAT_RGBA1010102)) { - glintformat = GL_RGBA; + glintformat = GL_RGB10_A2_EXT; glformat = GL_RGBA; gltype = GL_UNSIGNED_INT_2_10_10_10_REV_EXT; - required_format = COGL_PIXEL_FORMAT_RGBA_1010102; + required_format = COGL_PIXEL_FORMAT_ABGR_2101010; required_format |= (format & COGL_PREMULT_BIT); break; } -- cgit v1.2.1