From: Danylo Piliaiev Date: Wed, 3 Apr 2019 15:09:24 +0000 (+0300) Subject: st/mesa: Fix GL_MAP_COLOR with glDrawPixels GL_COLOR_INDEX X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3fdfface3ece93b55ba39dd987dd0962ac37bcdf;p=mesa.git st/mesa: Fix GL_MAP_COLOR with glDrawPixels GL_COLOR_INDEX Documentation for glDrawPixels with GL_COLOR_INDEX says: "If the GL is in color index mode, and if GL_MAP_COLOR is true, the index is replaced with the value that it references in lookup table GL_PIXEL_MAP_I_TO_I" We are always in RGBA mode and there is nothing in documentation about GL_MAP_COLOR in RGBA mode for GL_COLOR_INDEX. Scale and bias are also only applicable for RGBA format and not mentioned for GL_COLOR_INDEX. Thus the behaviour will be on par with i965. Fixes: gl-1.0-drawpixels-color-index Signed-off-by: Danylo Piliaiev Signed-off-by: Marek Olšák --- diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 5f2d50ceb1b..6f6b42596e6 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -1144,6 +1144,35 @@ get_color_fp_variant(struct st_context *st) return fpv; } +/** + * Get fragment program variant for a glDrawPixels command + * for COLOR_INDEX data + */ +static struct st_fp_variant * +get_color_index_fp_variant(struct st_context *st) +{ + struct gl_context *ctx = st->ctx; + struct st_fp_variant_key key; + struct st_fp_variant *fpv; + + memset(&key, 0, sizeof(key)); + + key.st = st->has_shareable_shaders ? NULL : st; + key.drawpixels = 1; + /* Since GL is always in RGBA mode MapColorFlag does not + * affect GL_COLOR_INDEX format. + * Scale and bias also never affect GL_COLOR_INDEX format. + */ + key.scaleAndBias = 0; + key.pixelMaps = 0; + key.clamp_color = st->clamp_frag_color_in_shader && + ctx->Color._ClampFragmentColor; + + fpv = st_get_fp_variant(st, st->fp, &key); + + return fpv; +} + /** * Clamp glDrawPixels width and height to the maximum texture size. @@ -1299,11 +1328,12 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y, write_stencil); } else { - fpv = get_color_fp_variant(st); + fpv = (format != GL_COLOR_INDEX) ? get_color_fp_variant(st) : + get_color_index_fp_variant(st); driver_fp = fpv->driver_shader; - if (ctx->Pixel.MapColorFlag) { + if (ctx->Pixel.MapColorFlag && format != GL_COLOR_INDEX) { pipe_sampler_view_reference(&sv[1], st->pixel_xfer.pixelmap_sampler_view); num_sampler_view++;