[Mesa-dev] [PATCH v2] mesa: Fix swizzling for luminance/intensity in _mesa_readpixels
Chris Wilson
chris at chris-wilson.co.uk
Mon Jul 31 21:51:25 UTC 2017
Luminance/Intensity when converted to RGB should be replicated to fill
the RGB channels, but they differ on how the alpha channel is filled, as
luminance is set to 1 (unless alpha is supplied) and intensity is
replicated into alpha as well.
https://www.khronos.org/opengl/wiki/Image_Format:
Legacy Image Formats
Warning: This section describes legacy OpenGL APIs that have been
removed from core OpenGL 3.1 and above (they are only deprecated in
OpenGL 3.0). It is recommended that you not use this functionality in
your programs.
As with other deprecated functionality, it is advised that you not rely
on these features.
Luminance and intensity formats are color formats. They are one or two
channel formats like RED or RG, but they specify particular behavior.
When a GL_RED format is sampled in a shader, the resulting vec4 is (Red,
0, 0, 1). When a GL_INTENSITY format is sampled, the resulting vec4 is
(I, I, I, I). The single intensity value is read into all four
components. For GL_LUMINANCE, the result is (L, L, L, 1). There is also
a two-channel GL_LUMINANCE_ALPHA format, which gives (L, L, L, A).
v2: luminance -> xxx1, intensity -> xxxx, luminance_alpha -> xxxw
Fixes:5038d839b8e4 ("mesa: use _mesa_format_convert to implement glReadPixels.")
Cc: Iago Toral Quiroga <itoral at igalia.com>
Cc: Jason Ekstrand <jason.ekstrand at intel.com>
---
src/mesa/main/readpix.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index 6ce340ddf9..894b87d826 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -471,17 +471,23 @@ read_rgba_pixels( struct gl_context *ctx,
* Depending on the base formats involved in the conversion we might need to
* rebase some values, so for these formats we compute a rebase swizzle.
*/
- if (rb->_BaseFormat == GL_LUMINANCE || rb->_BaseFormat == GL_INTENSITY) {
+ if (rb->_BaseFormat == GL_LUMINANCE) {
needs_rebase = true;
rebase_swizzle[0] = MESA_FORMAT_SWIZZLE_X;
- rebase_swizzle[1] = MESA_FORMAT_SWIZZLE_ZERO;
- rebase_swizzle[2] = MESA_FORMAT_SWIZZLE_ZERO;
+ rebase_swizzle[1] = MESA_FORMAT_SWIZZLE_X;
+ rebase_swizzle[2] = MESA_FORMAT_SWIZZLE_X;
rebase_swizzle[3] = MESA_FORMAT_SWIZZLE_ONE;
+ } else if (rb->_BaseFormat == GL_INTENSITY) {
+ needs_rebase = true;
+ rebase_swizzle[0] = MESA_FORMAT_SWIZZLE_X;
+ rebase_swizzle[1] = MESA_FORMAT_SWIZZLE_X;
+ rebase_swizzle[2] = MESA_FORMAT_SWIZZLE_X;
+ rebase_swizzle[3] = MESA_FORMAT_SWIZZLE_X;
} else if (rb->_BaseFormat == GL_LUMINANCE_ALPHA) {
needs_rebase = true;
rebase_swizzle[0] = MESA_FORMAT_SWIZZLE_X;
- rebase_swizzle[1] = MESA_FORMAT_SWIZZLE_ZERO;
- rebase_swizzle[2] = MESA_FORMAT_SWIZZLE_ZERO;
+ rebase_swizzle[1] = MESA_FORMAT_SWIZZLE_X;
+ rebase_swizzle[2] = MESA_FORMAT_SWIZZLE_X;
rebase_swizzle[3] = MESA_FORMAT_SWIZZLE_W;
} else if (_mesa_get_format_base_format(rb_format) != rb->_BaseFormat) {
needs_rebase =
--
2.13.3
More information about the mesa-dev
mailing list