From abf8a759f26c305dbf0babf754dd2467b58add67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 16 Oct 2023 19:55:26 +0200 Subject: [PATCH] TextureTools: verify DistanceField doesn't overwrite the whole output. It does that, yeah. Another reason why incremental filling couldn't have ever worked. --- .../TextureTools/Test/DistanceFieldGLTest.cpp | 64 ++++++++++++++++--- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp index 5adfd7268..1d3719904 100644 --- a/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp +++ b/src/Magnum/TextureTools/Test/DistanceFieldGLTest.cpp @@ -80,6 +80,8 @@ struct DistanceFieldGLTest: GL::OpenGLTester { Containers::String _testDir; }; +using namespace Math::Literals; + const struct { const char* name; Vector2i size; @@ -205,21 +207,34 @@ void DistanceFieldGLTest::runTexture() { #endif #ifndef MAGNUM_TARGET_GLES2 - const GL::TextureFormat outputFormat = GL::TextureFormat::R8; + const GL::TextureFormat outputTextureFormat = GL::TextureFormat::R8; + const GL::PixelFormat outputPixelFormat = GL::PixelFormat::Red; #elif !defined(MAGNUM_TARGET_WEBGL) - GL::TextureFormat outputFormat; - if(GL::Context::current().isExtensionSupported()) - outputFormat = GL::TextureFormat::R8; - else - outputFormat = GL::TextureFormat::RGBA; + GL::TextureFormat outputTextureFormat; + GL::PixelFormat outputPixelFormat; + if(GL::Context::current().isExtensionSupported()) { + outputTextureFormat = GL::TextureFormat::R8; + outputPixelFormat = GL::PixelFormat::Red; + } else { + outputTextureFormat = GL::TextureFormat::RGBA; + outputPixelFormat = GL::PixelFormat::RGBA; + } #else - const GL::TextureFormat outputFormat = GL::TextureFormat::RGBA; + const GL::TextureFormat outputTextureFormat = GL::TextureFormat::RGBA; + const GL::PixelFormat outputPixelFormat = GL::PixelFormat::RGBA; #endif + const GL::PixelType outputPixelType = GL::PixelType::UnsignedByte; GL::Texture2D output; output.setMinificationFilter(GL::SamplerFilter::Nearest, GL::SamplerMipmap::Base) .setMagnificationFilter(GL::SamplerFilter::Nearest) - .setStorage(1, outputFormat, data.size); + .setStorage(1, outputTextureFormat, data.size); + + /* Fill the texture with some data to verify they don't affect the output + and aren't accidentally overwritten when running on just a + subrectangle */ + output.setSubImage(0, {}, ImageView2D{outputPixelFormat, outputPixelType, data.size, + Containers::Array{DirectInit, std::size_t(data.size.product()*GL::pixelFormatSize(outputPixelFormat, outputPixelType)), '\x66'}}); DistanceField distanceField{32}; CORRADE_COMPARE(distanceField.radius(), 32); @@ -244,6 +259,16 @@ void DistanceFieldGLTest::runTexture() { actualOutputImage = Image2D{PixelFormat::RGBA8Unorm}; #endif + /* Verify that the other data weren't overwritten if processing just a + subrange -- it should still have the original data kept */ + if(data.offset.product()) { + DebugTools::textureSubImage(output, 0, Range2Di::fromSize({}, Vector2i{1}), *actualOutputImage); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + CORRADE_COMPARE(actualOutputImage->data()[0], '\x66'); + } + DebugTools::textureSubImage(output, 0, Range2Di::fromSize(data.offset, Vector2i{64}), *actualOutputImage); MAGNUM_VERIFY_NO_GL_ERROR(); @@ -351,6 +376,19 @@ void DistanceFieldGLTest::runFramebuffer() { GL::Framebuffer output{{{}, data.size}}; output.attachTexture(GL::Framebuffer::ColorAttachment(0), outputTexture, 0); + /* Clear the framebuffer to some data to verify it's not getting cleared + again inside, stomping on existing data. Use the statless clear command + if possible to avoid the clear color getting accidentally reused for a + clear inside, making the test wrongly pass */ + #ifndef MAGNUM_TARGET_GLES2 + output.clearColor(0, 0x667788_rgbf); + #else + GL::Renderer::setClearColor(0x667788_rgbf); + output.clear(GL::FramebufferClear::Color); + /* Same as in GL::Renderer::initializeContextBasedFunctionality() */ + GL::Renderer::setClearColor(0x1f1f1f_rgbf); + #endif + DistanceField distanceField{32}; CORRADE_COMPARE(distanceField.radius(), 32); @@ -377,6 +415,16 @@ void DistanceFieldGLTest::runFramebuffer() { actualOutputImage = Image2D{PixelFormat::RGBA8Unorm}; #endif + /* Verify that the other data weren't overwritten if processing just a + subrange -- it should still have the original data kept */ + if(data.offset.product()) { + DebugTools::textureSubImage(outputTexture, 0, Range2Di::fromSize({}, Vector2i{1}), *actualOutputImage); + + MAGNUM_VERIFY_NO_GL_ERROR(); + + CORRADE_COMPARE(actualOutputImage->data()[0], '\x66'); + } + DebugTools::textureSubImage(outputTexture, 0, Range2Di::fromSize(data.offset, Vector2i{64}), *actualOutputImage); MAGNUM_VERIFY_NO_GL_ERROR();