From 7e62c4dc9cebd17f3eca7673b71944a0c467346b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Fri, 19 Jun 2015 20:06:47 -0700 Subject: [PATCH] Don't mangle safe bit patterns in copy_image sRGB RB cases. Clearing a sRGB framebuffer takes in the clear color in linear space and then transforms it to sRGB space. This process destroys the carefully selected clear color bit pattern. Avoid bit mangling by doing first an inverse tranformation to the supplied clear color which restores the bit pattern when the color is coverted to sRGB internal format. Bug: 20698928 Bug: 21951463 Change-Id: I2155e8a977cc524401b5f98c7dde4502f62e35a7 --- modules/gles31/functional/es31fCopyImageTests.cpp | 35 +++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/gles31/functional/es31fCopyImageTests.cpp b/modules/gles31/functional/es31fCopyImageTests.cpp index 53f7416..2377c8f 100644 --- a/modules/gles31/functional/es31fCopyImageTests.cpp +++ b/modules/gles31/functional/es31fCopyImageTests.cpp @@ -657,16 +657,7 @@ void genRenderbufferImage (const glw::Functions& gl, { const tcu::ConstPixelBufferAccess texelAccess (format, 1, 1, 1, &(texelBlock[0])); - if (isFloatFormat(info.getFormat())) - { - const tcu::Vec4 color = texelAccess.getPixel(0, 0, 0); - - gl.clearBufferfv(GL_COLOR, 0, (const float*)&color); - GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer."); - - tcu::clear(refAccess, (tcu::isSRGB(format) ? tcu::linearToSRGB(color) : color)); - } - else if (isIntFormat(info.getFormat())) + if (isIntFormat(info.getFormat())) { const tcu::IVec4 color = texelAccess.getPixelInt(0, 0, 0); @@ -688,13 +679,27 @@ void genRenderbufferImage (const glw::Functions& gl, } else { - const tcu::Vec4 color = texelAccess.getPixel(0, 0, 0); - - gl.clearColor(color.x(), color.y(), color.z(), color.w()); - gl.clear(GL_COLOR_BUFFER_BIT); + const tcu::Vec4 rawColor = texelAccess.getPixel(0, 0, 0); + const tcu::Vec4 linearColor = (tcu::isSRGB(format) ? tcu::sRGBToLinear(rawColor) : rawColor); + + // rawColor bit pattern has been chosen to be "safe" in the destination format. For sRGB + // formats, the clear color is in linear space. Since we want the resulting bit pattern + // to be safe after implementation linear->sRGB transform, we must apply the inverting + // transform to the clear color. + + if (isFloatFormat(info.getFormat())) + { + gl.clearBufferfv(GL_COLOR, 0, (const float*)&linearColor); + } + else + { + // fixed-point + gl.clearColor(linearColor.x(), linearColor.y(), linearColor.z(), linearColor.w()); + gl.clear(GL_COLOR_BUFFER_BIT); + } GLU_EXPECT_NO_ERROR(gl.getError(), "Failed to clear renderbuffer."); - tcu::clear(refAccess, (tcu::isSRGB(format) ? tcu::linearToSRGB(color) : color)); + tcu::clear(refAccess, rawColor); } } } -- 2.7.4