Magnum::Text::DistanceFieldGlyphCacheArrayGL class new in Git master

OpenGL array glyph cache with distance field rendering.

Like DistanceFieldGlyphCacheGL, but backed by a GL::Texture2DArray instead of GL::Texture2D. See the AbstractGlyphCache class documentation for information about setting up a glyph cache instance and filling it with glyphs, and DistanceFieldGlyphCacheGL for details specific to distance field processing and used internal texture format. The setup differs from DistanceFieldGlyphCacheGL only in specifying one extra dimension for size:

Containers::Pointer<Text::AbstractFont> font = ;
font->openFile("font.ttf", 48.0f);

Text::DistanceFieldGlyphCacheArrayGL cache{{512, 512, 4}, {128, 128}, 12};
if(!font->fillGlyphCache(cache, "abcdefghijklmnopqrstuvwxyz"
                                "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                "0123456789?!:;,. "))
    Fatal{} << "Glyph cache too small to fit all characters";

Assuming a RendererGL is used with this cache for rendering the text, its mesh() can be then drawn using Shaders::DistanceFieldVectorGL that has Shaders::DistanceFieldVectorGL::Flag::TextureArrays enabled, together with binding texture() for drawing:

Text::RendererGL renderer{cache};


Shaders::DistanceFieldVectorGL2D shader{
    Shaders::DistanceFieldVectorGL2D::Configuration{}
        .setFlags(Shaders::DistanceFieldVectorGL2D::Flag::TextureArrays)};
shader
    
    .bindVectorTexture(cache.texture())
    .draw(renderer.mesh());

Base classes

class GlyphCacheArrayGL new in Git master
OpenGL array glyph cache.

Constructors, destructors, conversion operators

DistanceFieldGlyphCacheArrayGL(const Vector3i& size, const Vector2i& processedSize, UnsignedInt radius) explicit
Constructor.
DistanceFieldGlyphCacheArrayGL(NoCreateT) explicit noexcept
Construct without creating the internal state and the OpenGL texture object.

Public functions

auto radius() const -> UnsignedInt
Distance field calculation radius.

Function documentation

Magnum::Text::DistanceFieldGlyphCacheArrayGL::DistanceFieldGlyphCacheArrayGL(const Vector3i& size, const Vector2i& processedSize, UnsignedInt radius) explicit

Constructor.

Parameters
size Size of the source image
processedSize Resulting distance field texture size. Depth of the resulting texture is size.z().
radius Distance field calculation radius

See TextureTools::DistanceFieldGL for more information about the parameters. Size restrictions from it apply here as well, in particular the ratio of size.xy() and processedSize is expected to be a multiple of 2.

Sets the processedFormat() to PixelFormat::R8Unorm, if available. On OpenGL ES 3.0+ and WebGL 2 uses PixelFormat::R8Unorm always. On desktop OpenGL requires ARB_texture_rg (part of OpenGL 3.0), on ES2 uses EXT_texture_rg if available and uses PixelFormat::RGB8Unorm as fallback if not, on WebGL 1 uses PixelFormat::RGB8Unorm always.

Magnum::Text::DistanceFieldGlyphCacheArrayGL::DistanceFieldGlyphCacheArrayGL(NoCreateT) explicit noexcept

Construct without creating the internal state and the OpenGL texture object.

The constructed instance is equivalent to moved-from state, i.e. no APIs can be safely called on the object. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.