From 5bcaaa3b67e439564effbe501f8260deb0c78fff Mon Sep 17 00:00:00 2001 From: Ryan Neph Date: Fri, 25 Feb 2022 10:49:47 -0800 Subject: [PATCH] vrend: swap red/blue color for clear_texture on BGRA resources in GLES On GLES hosts, pixel data for BGRA resources are byte-reordered and passed to the host driver for compatibility reasons. The clear color used in glClearTexSubImage[EXT] for such resources on GLES hosts must be reordered to match. Signed-off-by: Ryan Neph Reviewed-by: Gert Wollny Part-of: --- src/vrend_renderer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 07bee82..831ff74 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -4154,6 +4154,17 @@ void vrend_clear_texture(struct vrend_context* ctx, format = tex_conv_table[fmt].glformat; type = tex_conv_table[fmt].gltype; + /* 32-bit BGRA resources are always reordered to RGBA ordering before + * submission to the host driver. Reorder red/blue color bytes in + * the clear color to match. */ + if (vrend_state.use_gles && vrend_format_is_bgra(fmt)) { + assert(util_format_get_blocksizebits(fmt) >= 24); + VREND_DEBUG(dbg_bgra, ctx, "swizzling clear_texture color for bgra texture\n"); + uint8_t temp = ((uint8_t*)data)[0]; + ((uint8_t*)data)[0] = ((uint8_t*)data)[2]; + ((uint8_t*)data)[2] = temp; + } + if (vrend_state.use_gles) { glClearTexSubImageEXT(res->id, level, box->x, box->y, box->z,