Browse Source

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.
pull/650/head
Vladimír Vondruš 2 years ago
parent
commit
28dd01c815
  1. 8
      src/Magnum/Text/GlyphCacheGL.h
  2. 26
      src/MagnumPlugins/MagnumFont/MagnumFont.cpp

8
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
};

26
src/MagnumPlugins/MagnumFont/MagnumFont.cpp

@ -159,22 +159,26 @@ Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) {
}
Containers::Pointer<AbstractGlyphCache> MagnumFont::doCreateGlyphCache() {
/* Set cache image */
Containers::Pointer<GlyphCacheGL> 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> cache{InPlaceInit,
PixelFormat::R8Unorm,
_opened->conf.value<Vector2i>("originalImageSize"),
PixelFormat::R8Unorm,
_opened->image->size(),
_opened->conf.value<Vector2i>("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<Utility::ConfigurationGroup*> glyphs = _opened->conf.groups("glyph");

Loading…
Cancel
Save