From 4d298673da9b05d826b960eece2e715a6b187330 Mon Sep 17 00:00:00 2001 From: "Eric R. Smith" Date: Fri, 10 May 2024 11:07:54 -0300 Subject: [PATCH] get_color_read_type: make sure format/type combo is legal for gles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GLES spec limits the valid combinations of format and type that may be returned by queries and/or used by ReadPixel. The list of valid combinations appears in table 8.2 of the GLES 3.2 spec. Our code for reporting the type and format of the current framebuffer, however, does not verify that the combination is legal for GLES. For example, RGBA and UNSIGNED_SHORT_1_5_5_5_REV is not a valid GLES combination, but it's what we were returning for a panthor 16 bit frame buffer. We can fix this either by changing the format or type that we return (internally we can handle any format/type combination). We advertise the read_format_bgra extension, so we could return GL_BGRA for the format. However, very few applications (including notably the Khronos CTS for GLES) cope well with BGRA. So instead we change the type to a non-_REV one so that the combination appears in the GLES spec table of legal values. Cc: mesa-stable Reviewed-by: Marek Olšák Reviewed-by: Erik Faye-Lund Part-of: --- src/mesa/main/framebuffer.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c index baa66fc4ee5..14a359c5ea4 100644 --- a/src/mesa/main/framebuffer.c +++ b/src/mesa/main/framebuffer.c @@ -973,13 +973,36 @@ _mesa_get_color_read_type(struct gl_context *ctx, GLenum data_type; GLuint comps; - _mesa_uncompressed_format_to_type_and_comps(format, &data_type, &comps); - + _mesa_uncompressed_format_to_type_and_comps(format, &data_type, + &comps); + if (_mesa_is_gles(ctx)) { + /* GLES allows only a limited set of format/type combinations for + reading, namely the ones specified in table 8.2 of the GLES 3.2 + spec. In particular *_REV types are not allowed. The + EXT_read_format_bgra extension does add some *_REV types, but + only in conjunction with BGRA formats, and we return BGRA + from _mesa_get_color_read_format for very few cases. Work + around that here. + Note that EXT_texture_type_2_10_10_10_REV does add support + for that texture type and RGBA, so exclude that from our test. + */ + GLenum data_format = _mesa_get_color_read_format(ctx, fb, caller); + if (data_format == GL_RGBA) { + switch (data_type) { + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + data_type = GL_UNSIGNED_SHORT_4_4_4_4; + break; + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + data_type = GL_UNSIGNED_SHORT_5_5_5_1; + break; + default: + break; + } + } + } return data_type; } } - - /** * Returns the read renderbuffer for the specified format. */