From 96142a3e87abb9e61ee87e895df64f5f64606e83 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Mon, 4 May 2015 09:58:36 +0200 Subject: [PATCH] swrast: Fix rgba_draw_pixels with GL_COLOR_INDEX When we implemented the format conversion rewrite we forgot to handle GL_COLOR_INDEX here, which needs special handling. Fixes the following piglit test: bin/gl-1.0-drawpixels-color-index -auto -fbo Buzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90213 Tested-by: Juha-Pekka Heikkila Reviewed-by: Juha-Pekka Heikkila Reviewed-by: Jason Ekstrand --- src/mesa/swrast/s_drawpix.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index bf427266cef..fb677ee1b16 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -448,14 +448,34 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, { const GLbitfield interpMask = span.interpMask; const GLbitfield arrayMask = span.arrayMask; - const GLint srcStride - = _mesa_image_row_stride(unpack, width, format, type); GLint skipPixels = 0; /* use span array for temp color storage */ GLfloat *rgba = (GLfloat *) span.array->attribs[VARYING_SLOT_COL0]; void *tempImage = NULL; - if (unpack->SwapBytes) { + /* We have to deal with GL_COLOR_INDEX manually because + * _mesa_format_convert does not handle this format. So what we do here is + * convert it to RGBA ubyte first and then convert from that to dst as + * usual. + */ + if (format == GL_COLOR_INDEX) { + /* This will handle byte swapping and transferops if needed */ + tempImage = + _mesa_unpack_color_index_to_rgba_ubyte(ctx, 2, + pixels, format, type, + width, height, 1, + unpack, + transferOps); + if (!tempImage) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels"); + return; + } + + transferOps = 0; + pixels = tempImage; + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + } else if (unpack->SwapBytes) { /* We have to handle byte-swapping scenarios before calling * _mesa_format_convert */ @@ -476,6 +496,9 @@ draw_rgba_pixels( struct gl_context *ctx, GLint x, GLint y, } } + const GLint srcStride + = _mesa_image_row_stride(unpack, width, format, type); + /* if the span is wider than SWRAST_MAX_WIDTH we have to do it in chunks */ while (skipPixels < width) { const GLint spanWidth = MIN2(width - skipPixels, SWRAST_MAX_WIDTH); -- 2.30.2