From 28dd01c8153e8dfd2ea687d47bbb8a71649f374b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 1 Oct 2024 14:01:39 +0200 Subject: [PATCH] MagnumFont: fix cache image upload on ES2. Now, instead of accessing the texture directly, it uses the public setProcessedImage() API. For which it needs to subclass the cache in order to advertise ImageProcessing, which means the class can no longer have the implementations private. I don't really like this, ideally none of this would be needed and MagnumFont would implement fillGlyphCache() instead. Not sure how to do that yet tho as there's still the issue with DistanceFieldGlyphCacheGL being RGBA, so this is a half-assed solution until a better one is found... or the plugin gets ditched completely. --- src/Magnum/Text/GlyphCacheGL.h | 8 ++++--- src/MagnumPlugins/MagnumFont/MagnumFont.cpp | 26 ++++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Magnum/Text/GlyphCacheGL.h b/src/Magnum/Text/GlyphCacheGL.h index 170216248..5cb64a2cd 100644 --- a/src/Magnum/Text/GlyphCacheGL.h +++ b/src/Magnum/Text/GlyphCacheGL.h @@ -187,12 +187,14 @@ class MAGNUM_TEXT_EXPORT GlyphCacheGL: public AbstractGlyphCache { private: MAGNUM_TEXT_LOCAL GlyphCacheFeatures doFeatures() const override; - MAGNUM_TEXT_LOCAL void doSetImage(const Vector2i& offset, const ImageView2D& image) override; + /** @todo make those MAGNUM_TEXT_LOCAL again once MagnumFont doesn't + need to subclass anything anymore */ + void doSetImage(const Vector2i& offset, const ImageView2D& image) override; /* Used if a subclass advertises GlyphCacheFeature::ImageProcessing / ProcessedImageDownload in its doFeatures() */ - MAGNUM_TEXT_LOCAL void doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) override; + void doSetProcessedImage(const Vector2i& offset, const ImageView2D& image) override; #ifndef MAGNUM_TARGET_GLES - MAGNUM_TEXT_LOCAL Image3D doProcessedImage() override; + Image3D doProcessedImage() override; #endif }; diff --git a/src/MagnumPlugins/MagnumFont/MagnumFont.cpp b/src/MagnumPlugins/MagnumFont/MagnumFont.cpp index 61a93624b..0bd79629f 100644 --- a/src/MagnumPlugins/MagnumFont/MagnumFont.cpp +++ b/src/MagnumPlugins/MagnumFont/MagnumFont.cpp @@ -159,22 +159,26 @@ Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) { } Containers::Pointer MagnumFont::doCreateGlyphCache() { - /* Set cache image */ - Containers::Pointer cache{InPlaceInit, + /* Set cache image. Have to create a custom subclass in order to have + control over both the source and processed format (where + DistanceFieldGlyphCache may set the processed format to RGBA if there's + no renderable single-channel format). */ + /** @todo figure out a nicer way, and ideally how to do this with + fillGlyphCache() instead */ + struct Cache: GlyphCacheGL { + using GlyphCacheGL::GlyphCacheGL; + + GlyphCacheFeatures doFeatures() const override { + return GlyphCacheFeature::ImageProcessing; + } + }; + Containers::Pointer cache{InPlaceInit, PixelFormat::R8Unorm, _opened->conf.value("originalImageSize"), PixelFormat::R8Unorm, _opened->image->size(), _opened->conf.value("padding")}; - /* Copy the opened image data directly to the GL texture because (unlike - image()) it matches the actual image size if it differs from - originalImageSize. A potential other way would be to create a - DistanceFieldGlyphCache instead, and call setDistanceFieldImage() on it, - but the font file itself doesn't contain any info about whether it - actually is a distance field, so that would be not really any better. */ - /** @todo clean this up once there's a way to upload the processed image - directly from the base class */ - cache->texture().setSubImage(0, {}, *_opened->image); + cache->setProcessedImage({}, *_opened->image); const std::vector glyphs = _opened->conf.groups("glyph");