Browse Source

Text: suggest using the returned range for glyph cache image flush.

Now it's less code, and it also no longer results in random edge
artifacts because the padding area wasn't correctly uploaded. I'm going
to do the same change in the FreeTypeFont and StbTrueTypeFont next.
pull/651/merge
Vladimír Vondruš 1 year ago
parent
commit
4ef578f30f
  1. 13
      doc/snippets/Text.cpp
  2. 20
      src/Magnum/Text/AbstractGlyphCache.h

13
doc/snippets/Text.cpp

@ -199,15 +199,15 @@ Containers::Array<Vector2i> offsets{NoInit, images.size()};
cache.atlas().clearFlags( cache.atlas().clearFlags(
TextureTools::AtlasLandfillFlag::RotatePortrait| TextureTools::AtlasLandfillFlag::RotatePortrait|
TextureTools::AtlasLandfillFlag::RotateLandscape); TextureTools::AtlasLandfillFlag::RotateLandscape);
CORRADE_INTERNAL_ASSERT(cache.atlas().add( Containers::Optional<Range2Di> range = cache.atlas().add(
stridedArrayView(images).slice(&ImageView2D::size), stridedArrayView(images).slice(&ImageView2D::size),
offsets)); offsets);
CORRADE_INTERNAL_ASSERT(range);
/* [AbstractGlyphCache-filling-atlas] */ /* [AbstractGlyphCache-filling-atlas] */
/* [AbstractGlyphCache-filling-glyphs] */ /* [AbstractGlyphCache-filling-glyphs] */
/* The glyph cache is just 2D, so copying to the first slice */ /* The glyph cache is just 2D, so copying to the first slice */
Containers::StridedArrayView3D<char> dst = cache.image().pixels()[0]; Containers::StridedArrayView3D<char> dst = cache.image().pixels()[0];
Range2Di updated;
for(UnsignedInt i = 0; i != images.size(); ++i) { for(UnsignedInt i = 0; i != images.size(); ++i) {
Range2Di rectangle = Range2Di::fromSize(offsets[i], images[i].size()); Range2Di rectangle = Range2Di::fromSize(offsets[i], images[i].size());
cache.addGlyph(fontId, i, {}, rectangle); cache.addGlyph(fontId, i, {}, rectangle);
@ -218,13 +218,10 @@ for(UnsignedInt i = 0; i != images.size(); ++i) {
std::size_t(offsets[i].y()), std::size_t(offsets[i].y()),
std::size_t(offsets[i].x()), std::size_t(offsets[i].x()),
0}, src.size())); 0}, src.size()));
/* Maintain a range that was updated in the glyph cache */
updated = Math::join(updated, rectangle);
} }
/* Reflect the image data update to the actual GPU-side texture */ /* Reflect the updated image range to the actual GPU-side texture */
cache.flushImage(updated); cache.flushImage(*range);
/* [AbstractGlyphCache-filling-glyphs] */ /* [AbstractGlyphCache-filling-glyphs] */
} }

20
src/Magnum/Text/AbstractGlyphCache.h

@ -166,15 +166,17 @@ efficiency.
@snippet Text.cpp AbstractGlyphCache-filling-atlas @snippet Text.cpp AbstractGlyphCache-filling-atlas
In case the layouting fails, triggering the assertion, the cache size was On success, @ref TextureTools::AtlasLandfill::add() returns a range spanning
picked too small or there was already enough glyphs added that the new ones all added images, which we'll use later for GPU texture upload. In case of a
didn't fit. The solution is then to either increase the cache size, turn the failure, triggering the assertion above, the cache size was picked too small or
cache into an array, or create a second cache for the new data. Depending on there was already enough glyphs added that the new ones didn't fit. The
the input sizes it's also possible to achieve a better packing efficiency by solution is then to either increase the cache size, turn the cache into an
toggling various @ref TextureTools::AtlasLandfillFlag values --- you can for array, or create a second cache for the new data. Depending on the input sizes
example create temporary instances aside, attempt packing with them, and then it's also possible to achieve a better packing efficiency by toggling various
for filling the glyph cache itself pick the set of flags that resulted in the @ref TextureTools::AtlasLandfillFlag values --- you can for example create
smallest @ref TextureTools::AtlasLandfill::filledSize(). temporary instances aside, attempt packing with them, and then for filling the
glyph cache itself pick the set of flags that resulted in the smallest
@ref TextureTools::AtlasLandfill::filledSize().
@subsection Text-AbstractGlyphCache-filling-glyphs Adding glyphs @subsection Text-AbstractGlyphCache-filling-glyphs Adding glyphs

Loading…
Cancel
Save