From 950e7b67248342c90511fc4b58b539bda1432f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sat, 7 Dec 2013 17:36:15 +0100 Subject: [PATCH] st/mesa: fix sRGB blitting The GL 4.4 specification is finally clear about how it should work. Older specs don't care (I'm pretty sure about GL 4.2 and older, not sure about GL 4.3). --- src/mesa/state_tracker/st_cb_blit.c | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_blit.c b/src/mesa/state_tracker/st_cb_blit.c index a236a08..88032b8 100644 --- a/src/mesa/state_tracker/st_cb_blit.c +++ b/src/mesa/state_tracker/st_cb_blit.c @@ -185,12 +185,39 @@ st_BlitFramebuffer(struct gl_context *ctx, blit.dst.resource = dstSurf->texture; blit.dst.level = dstSurf->u.tex.level; blit.dst.box.z = dstSurf->u.tex.first_layer; - blit.dst.format = util_format_linear(dstSurf->format); + + /* From the GL 4.4 compatibility specification: + * 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). + * + * Therefore the pipe_surface format is used. + */ + blit.dst.format = dstSurf->format; blit.src.resource = srcObj->pt; blit.src.level = srcAtt->TextureLevel; blit.src.box.z = srcAtt->Zoffset + srcAtt->CubeMapFace; - blit.src.format = util_format_linear(srcObj->pt->format); + + /* From the GL 4.4 compatibility specification: + * When values are taken from the read buffer, if + * 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 8.14. + * + * And from the section 9.2.3: + * For framebuffer objects, components are sRGB-encoded if + * the internal format of a color attachment is one of + * the color-renderable SRGB formats described in section + * 8.24. + * + * Therefore the original texture format is used. + */ + blit.src.format = srcObj->pt->format; st->pipe->blit(st->pipe, &blit); } @@ -220,12 +247,16 @@ st_BlitFramebuffer(struct gl_context *ctx, blit.dst.resource = dstSurf->texture; blit.dst.level = dstSurf->u.tex.level; blit.dst.box.z = dstSurf->u.tex.first_layer; - blit.dst.format = util_format_linear(dstSurf->format); + + /* Use the derived pipe_surface format. See above. */ + blit.dst.format = dstSurf->format; blit.src.resource = srcSurf->texture; blit.src.level = srcSurf->u.tex.level; blit.src.box.z = srcSurf->u.tex.first_layer; - blit.src.format = util_format_linear(srcSurf->format); + + /* Use the original texture format. See above. */ + blit.src.format = srcSurf->texture->format; st->pipe->blit(st->pipe, &blit); } -- 1.8.3.2