st/mesa: Fix GL_MAP_COLOR with glDrawPixels GL_COLOR_INDEX
authorDanylo Piliaiev <danylo.piliaiev@globallogic.com>
Wed, 3 Apr 2019 15:09:24 +0000 (18:09 +0300)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 4 Apr 2019 14:38:32 +0000 (10:38 -0400)
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 <danylo.piliaiev@globallogic.com>
Signed-off-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_cb_drawpixels.c

index 5f2d50ceb1b87e022ca3dc96a65630741b3dc472..6f6b42596e6f3fe51855f914a3395bc70bb95365 100644 (file)
@@ -1144,6 +1144,35 @@ get_color_fp_variant(struct st_context *st)
    return fpv;
 }
 
    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.
 
 /**
  * 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 {
                                                 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;
 
 
       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++;
          pipe_sampler_view_reference(&sv[1],
                                      st->pixel_xfer.pixelmap_sampler_view);
          num_sampler_view++;