- if (_mesa_get_format_color_encoding(rb->Format) == GL_SRGB &&
- drawFb->Visual.sRGBCapable) {
- _mesa_SamplerParameteri(fb_tex_blit.sampler,
- GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT);
- _mesa_set_framebuffer_srgb(ctx, GL_TRUE);
- } else {
- _mesa_SamplerParameteri(fb_tex_blit.sampler,
- GL_TEXTURE_SRGB_DECODE_EXT,
- GL_SKIP_DECODE_EXT);
- /* set_framebuffer_srgb was set by _mesa_meta_begin(). */
- }
+ /* The GL 4.4 spec, section 18.3.1 ("Blitting Pixel Rectangles") says:
+ *
+ * "When values are taken from the read buffer, if FRAMEBUFFER_SRGB
+ * is enabled and the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING
+ * for the framebuffer attachment corresponding to the read buffer
+ * is SRGB (see section 9.2.3), the red, green, and blue components
+ * are converted from the non-linear sRGB color space according to
+ * equation 3.24.
+ *
+ * When values are written to the draw buffers, blit operations
+ * bypass most of the fragment pipeline. The only fragment
+ * operations which affect a blit are the pixel ownership test,
+ * the scissor test, and sRGB conversion (see section 17.3.9)."
+ *
+ * ES 3.0 contains nearly the exact same text, but omits the part
+ * about GL_FRAMEBUFFER_SRGB as that doesn't exist in ES. Mesa
+ * defaults it to on for ES contexts, so we can safely check it.
+ */
+ const bool decode =
+ ctx->Color.sRGBEnabled &&
+ _mesa_get_format_color_encoding(rb->Format) == GL_SRGB;
+
+ _mesa_set_sampler_srgb_decode(ctx, fb_tex_blit.samp_obj,
+ decode ? GL_DECODE_EXT
+ : GL_SKIP_DECODE_EXT);