main: don't always clamp pixels read from snorm buffers
authorItalo Nicola <italonicola@collabora.com>
Tue, 7 Sep 2021 13:37:20 +0000 (10:37 -0300)
committerMarge Bot <eric+marge@anholt.net>
Tue, 7 Sep 2021 20:18:33 +0000 (20:18 +0000)
From the OpenGL 4.6 spec, section 18.2.8:

"For a signed normalized fixed-point color buffer, each component is
clamped to [0,1] if read color clamping is enabled, or if type
represents un- signed integer components; otherwise type represents
signed integer components, and each component is clamped to [−1,1]."

Signed-off-by: Italo Nicola <italonicola@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12749>

src/mesa/main/readpix.c

index 6f4d49905a196d3affa66c61853f7bd49404c85a..f52474ca1af4e8cf993aee7f4d17fb36c94cbc81 100644 (file)
@@ -120,6 +120,13 @@ _mesa_get_readpixels_transfer_ops(const struct gl_context *ctx,
            type != GL_UNSIGNED_INT_10F_11F_11F_REV)) {
          transferOps |= IMAGE_CLAMP_BIT;
       }
+
+      /* For SNORM formats we only clamp if `type` is signed and clamp is `true` */
+      if (!_mesa_get_clamp_read_color(ctx, ctx->ReadBuffer) &&
+          _mesa_get_format_datatype(texFormat) == GL_SIGNED_NORMALIZED &&
+          (type == GL_BYTE || type == GL_SHORT || type == GL_INT)) {
+         transferOps &= ~IMAGE_CLAMP_BIT;
+      }
    }
 
    /* If the format is unsigned normalized, we can ignore clamping