@ -61,21 +61,33 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
public :
/**
* @ brief Constructor
* @ param size Glyph cache texture size
* @ param internalFormat Internal texture format
* @ param originalSize Unscaled glyph cache texture size
* @ param size Actual glyph cache texture size
* @ param padding Padding around every glyph
*
* All glyphs parameters are saved relative to @ p originalSize ,
* although the actual glyph cache texture has @ p size . Glyph
* @ p padding can be used to account for e . g . glyph shadows .
*/
explicit GlyphCache ( TextureFormat internalFormat , const Vector2i & originalSize , const Vector2i & size , const Vector2i & padding ) ;
/**
* @ brief Constructor
*
* Same as calling the above with @ p originalSize and @ p size the same .
*/
explicit GlyphCache ( const Vector2i & size , TextureFormat internalFormat ) ;
explicit GlyphCache ( TextureFormat internalFormat , const Vector2i & size , const Vector2i & padding = Vector2i ( ) ) ;
/**
* @ brief Constructor
* @ param size Glyph cache texture size
*
* Sets internal texture format to red channel only . On desktop OpenGL
* requires @ extension { ARB , texture_rg } ( also part of OpenGL ES 3.0 ) , in
* ES2 uses @ es_extension { EXT , texture_rg } , if available , or
* @ ref TextureFormat " TextureFormat::Luminance " as fallback .
*/
explicit GlyphCache ( const Vector2i & size ) ;
explicit GlyphCache ( const Vector2i & size , const Vector2i & padding = Vector2i ( ) ) ;
virtual ~ GlyphCache ( ) ;
@ -86,6 +98,9 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
*/
Vector2i textureSize ( ) const { return _size ; }
/** @brief Glyph padding */
Vector2i padding ( ) const { return _padding ; }
/** @brief Count of glyphs in the cache */
std : : size_t glyphCount ( ) const { return glyphs . size ( ) ; }
@ -99,9 +114,12 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
* First tuple element is glyph position relative to point on baseline ,
* second element is glyph region in texture atlas .
*
* Returned values include padding .
*
* If no glyph is found , glyph ` 0 ` is returned , which is by default on
* zero position and has zero region in texture atlas . You can reset it
* to some meaningful value in insert ( ) .
* @ see padding ( )
*/
std : : pair < Vector2i , Rectanglei > operator [ ] ( UnsignedInt glyph ) const {
auto it = glyphs . find ( glyph ) ;
@ -126,8 +144,11 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
* was stored there , use insert ( ) to store actual glyph on given
* position and setImage ( ) to upload glyph image .
*
* Glyph @ p sizes are expected to be without padding .
*
* @ attention Cache size must be large enough to contain all rendered
* glyphs .
* @ see padding ( )
*/
std : : vector < Rectanglei > reserve ( const std : : vector < Vector2i > & sizes ) ;
@ -141,7 +162,10 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
* can ' t overwrite already inserted glyph , however you can reset glyph
* ` 0 ` to some meaningful value .
*
* Glyph parameters are expected to be without padding .
*
* See also setImage ( ) to upload glyph image .
* @ see padding ( )
*/
void insert ( UnsignedInt glyph , Vector2i position , Rectanglei rectangle ) ;
@ -153,21 +177,12 @@ class MAGNUM_TEXT_EXPORT GlyphCache {
*/
virtual void setImage ( const Vector2i & offset , const ImageReference2D & image ) ;
# ifdef DOXYGEN_GENERATING_OUTPUT
private :
# else
protected :
# endif
/* Used from DistanceFieldGlyphCache */
explicit MAGNUM_LOCAL GlyphCache ( const Vector2i & size , const Vector2i & padding ) ;
void MAGNUM_LOCAL initialize ( TextureFormat internalFormat , const Vector2i & size ) ;
const Vector2i _size ;
Vector2i _size , _padding ;
Texture2D _texture ;
private :
const Vector2i _padding ;
std : : unordered_map < UnsignedInt , std : : pair < Vector2i , Rectanglei > > glyphs ;
} ;