diff --git a/doc/snippets/Text.cpp b/doc/snippets/Text.cpp index 38c1545fe..ac7655e12 100644 --- a/doc/snippets/Text.cpp +++ b/doc/snippets/Text.cpp @@ -199,15 +199,15 @@ Containers::Array offsets{NoInit, images.size()}; cache.atlas().clearFlags( TextureTools::AtlasLandfillFlag::RotatePortrait| TextureTools::AtlasLandfillFlag::RotateLandscape); -CORRADE_INTERNAL_ASSERT(cache.atlas().add( +Containers::Optional range = cache.atlas().add( stridedArrayView(images).slice(&ImageView2D::size), - offsets)); + offsets); +CORRADE_INTERNAL_ASSERT(range); /* [AbstractGlyphCache-filling-atlas] */ /* [AbstractGlyphCache-filling-glyphs] */ /* The glyph cache is just 2D, so copying to the first slice */ Containers::StridedArrayView3D dst = cache.image().pixels()[0]; -Range2Di updated; for(UnsignedInt i = 0; i != images.size(); ++i) { Range2Di rectangle = Range2Di::fromSize(offsets[i], images[i].size()); 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].x()), 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 */ -cache.flushImage(updated); +/* Reflect the updated image range to the actual GPU-side texture */ +cache.flushImage(*range); /* [AbstractGlyphCache-filling-glyphs] */ } diff --git a/src/Magnum/Text/AbstractGlyphCache.h b/src/Magnum/Text/AbstractGlyphCache.h index 77ea40705..edd42c2d9 100644 --- a/src/Magnum/Text/AbstractGlyphCache.h +++ b/src/Magnum/Text/AbstractGlyphCache.h @@ -166,15 +166,17 @@ efficiency. @snippet Text.cpp AbstractGlyphCache-filling-atlas -In case the layouting fails, triggering the assertion, the cache size was -picked too small or there was already enough glyphs added that the new ones -didn't fit. The solution is then to either increase the cache size, turn the -cache into an array, or create a second cache for the new data. Depending on -the input sizes it's also possible to achieve a better packing efficiency by -toggling various @ref TextureTools::AtlasLandfillFlag values --- you can for -example create 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(). +On success, @ref TextureTools::AtlasLandfill::add() returns a range spanning +all added images, which we'll use later for GPU texture upload. In case of a +failure, triggering the assertion above, the cache size was picked too small or +there was already enough glyphs added that the new ones didn't fit. The +solution is then to either increase the cache size, turn the cache into an +array, or create a second cache for the new data. Depending on the input sizes +it's also possible to achieve a better packing efficiency by toggling various +@ref TextureTools::AtlasLandfillFlag values --- you can for example create +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