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");