From bb5c1611231d9c0ed2769a6dfbc998b5651d3082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Apr 2025 15:16:13 +0200 Subject: [PATCH] Text: add comments in DistanceFieldGlyphCacheGL re temporary GL objects. At first I was like "ugh this is BAD" and made the texture and output framebuffer resident. Then I realized that for the upcoming array variant I need to reattach the output texture every time, so having a resident framebuffer was not that useful anymore, and then I realized that having a resident texture but calling setImage() on it is not any better than making a temporary one every time, and making the resident texture significantly larger just to accomodate any size that could possibly be processed was even worse. So, ultimately it's just these comments. --- src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp b/src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp index 0606a531b..476df2803 100644 --- a/src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp +++ b/src/Magnum/Text/DistanceFieldGlyphCacheGL.cpp @@ -109,6 +109,11 @@ void DistanceFieldGlyphCacheGL::doSetImage(const Vector2i& , const ImageView2D& image) { auto& state = static_cast(*_state); + /* Creating a temporary input texture that's deleted right after because I + assume it's better than having a persistent one which would just occupy + memory that was only ever used once. This way it can also be scaled to + just exactly the input size being processed, not the whole unprocessed + cache size, which can be quite big. */ GL::Texture2D input; input /* In order to have correctly processed output, the input has to be @@ -171,6 +176,10 @@ void DistanceFieldGlyphCacheGL::doSetImage(const Vector2i& paddedMaxRounded - paddedMinRounded, image.data()}; + /** @todo investigate if using setStorage() + setSubImage() is any + faster or better, the assumption is that since the texture is + temporary it doesn't matter much anyway; similarly with the + temporary framebuffer created inside */ input.setImage(0, GL::textureFormat(paddedImage.format()), paddedImage); state.distanceField(input, texture(), {paddedMinRounded/ratio, paddedMaxRounded/ratio}, paddedImage.size()); }