mesa: Avoid temp images in _mesa_texstore_rgb_dxt1 for GL_RGBA source
authorKenneth Graunke <kenneth@whitecape.org>
Mon, 2 May 2022 19:59:12 +0000 (12:59 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 27 May 2022 01:47:33 +0000 (01:47 +0000)
The compressor can handle 3 or 4-component sources, so allow a GL_RGBA
source and just pass that along with the correct number of components.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16631>

src/mesa/main/texcompress_s3tc.c

index c16e6e9..3470a7d 100644 (file)
@@ -51,11 +51,12 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
    const GLubyte *pixels;
    GLubyte *dst;
    const GLubyte *tempImage = NULL;
+   int srccomps = srcFormat == GL_RGB ? 3 : 4;
 
    assert(dstFormat == MESA_FORMAT_RGB_DXT1 ||
           dstFormat == MESA_FORMAT_SRGB_DXT1);
 
-   if (srcFormat != GL_RGB ||
+   if (!(srcFormat == GL_RGB || srcFormat == GL_RGBA) ||
        srcType != GL_UNSIGNED_BYTE ||
        ctx->_ImageTransferState ||
        ALIGN(srcPacking->RowLength, srcPacking->Alignment) != srcWidth ||
@@ -76,6 +77,7 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
                      srcPacking);
       pixels = tempImage;
       srcFormat = GL_RGB;
+      srccomps = 3;
    }
    else {
       pixels = _mesa_image_address2d(srcPacking, srcAddr, srcWidth, srcHeight,
@@ -84,7 +86,8 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
 
    dst = dstSlices[0];
 
-   tx_compress_dxt1(3, srcWidth, srcHeight, pixels, dst, dstRowStride, 3);
+   tx_compress_dxt1(srccomps, srcWidth, srcHeight, pixels,
+                    dst, dstRowStride, 3);
 
    free((void *) tempImage);