From 66a2ce87cde2928adebedfbee73fd0662dfcde41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 25 Jan 2025 17:30:29 +0100 Subject: [PATCH] Text: fix DistanceFieldGlyphCacheGLTest failing on recent Mesa. Neither a driver bug nor something wrong with the code. It's just that with a tight flush rectangle the target texture may have some random garbage left around the edges, causing the comparison to fail, so it's now explicitly cleared upfront. Doesn't happen when running the offending test alone (because I suppose the memory is coming fresh from the driver, being zeroed out for security purposes), only when running after the others (where I suspect it's now reusing previous partially-filled memory which it didn't before). Doesn't happen on NVidia either. --- .../Text/Test/DistanceFieldGlyphCacheGLTest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp b/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp index bad778562..e527c0534 100644 --- a/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp +++ b/src/Magnum/Text/Test/DistanceFieldGlyphCacheGLTest.cpp @@ -230,6 +230,20 @@ void DistanceFieldGlyphCacheGLTest::setImage() { CORRADE_COMPARE(inputImage->size(), (Vector2i{256, 256})); DistanceFieldGlyphCacheGL cache{data.sourceSize, data.size, 32}; + + /* Clear the target texture to avoid random garbage getting in when the + data.flushRange isn't covering the whole output */ + Containers::Array zeros{ValueInit, data.size.product()*pixelFormatSize(cache.processedFormat())}; + cache.texture().setSubImage(0, {}, + /* On ES2, R8Unorm maps to Luminance, but here it's actually Red if + EXT_texture_rg is supported */ + #if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) + cache.processedFormat() == PixelFormat::R8Unorm ? + ImageView2D{GL::PixelFormat::Red, GL::PixelType::UnsignedByte, data.size, zeros} : + #endif + ImageView2D{cache.processedFormat(), data.size, zeros} + ); + Containers::StridedArrayView3D src = inputImage->pixels(); /* Test also uploading under an offset. The cache might be three-component in some cases, slice the destination view to just the first component */