meta: Always do GenerateMipmaps in linear colorspace.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 12 Aug 2016 21:48:54 +0000 (14:48 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 25 Aug 2016 18:07:01 +0000 (11:07 -0700)
When generating mipmaps for sRGB textures, force both decode and encode,
so the filtering is done in linear colorspace, regardless of settings.

Fixes a WebGL conformance test in Chrome:
https://www.khronos.org/registry/webgl/sdk/tests/conformance2/textures/misc/tex-srgb-mipmap.html?webglVersion=2

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97322
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
src/mesa/drivers/common/meta_generate_mipmap.c

index 9cebbf79fd5b26fbe2506fe005130e0249e7fcc3..bbe9d6d8863116712c4741431f0c3aa758fbe6f8 100644 (file)
@@ -221,9 +221,17 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
                                 GL_LINEAR);
       _mesa_set_sampler_wrap(ctx, mipmap->samp_obj, GL_CLAMP_TO_EDGE,
                              GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+   }
+
+   if (ctx->Extensions.EXT_texture_sRGB_decode) {
+      const struct gl_texture_image *baseImage =
+         _mesa_select_tex_image(texObj, target, texObj->BaseLevel);
+      const bool srgb =
+         _mesa_get_format_color_encoding(baseImage->TexFormat) == GL_SRGB;
 
-      /* We don't want to encode or decode sRGB values; treat them as linear. */
-      _mesa_set_sampler_srgb_decode(ctx, mipmap->samp_obj, GL_SKIP_DECODE_EXT);
+      _mesa_set_sampler_srgb_decode(ctx, mipmap->samp_obj,
+                                    srgb ? GL_DECODE_EXT : GL_SKIP_DECODE_EXT);
+      _mesa_set_framebuffer_srgb(ctx, srgb);
    }
 
    _mesa_bind_sampler(ctx, ctx->Texture.CurrentUnit, mipmap->samp_obj);