Search Unity

TextMesh Pro Feature Request: Automatic Dynamic Font Atlas Management like UI.Text

Discussion in 'UGUI & TextMesh Pro' started by psyhama, Jun 10, 2022.

  1. psyhama

    psyhama

    Joined:
    Sep 4, 2018
    Posts:
    28
    Hi,
    I want the feature to automatically manage dynamic font atlases. What is missing in TextMesh Pro is that it automatically clears rendered unused font glyphs in font atlases.

    About use cases, we're developing app that want to localize to languages include CJK, and because the app is UGC type, users can type any characters, the whole possible characters will be more than 10000 and it can not be handled with static font atlases. But the count of displayed characters(glyphs) at a time will not be more than 1000.

    Recently, TextMesh Pro can add more dynamic font atlases if one font atlas has no space left for new characters, which is great. But, if a user of our app browse through many UGC contents, it will eventually end up with too many font atlases or memory shortage. (Without periodical clearing of font atlases)

    So, if there's the feature to automatically clear font atlas when one font atlas become full, there will be not much possibility of memory shortage.

    As I understand, The Unity's standard UI.Text has this feature. When one font atlas becomes full, it will clear the font atlas and re-draw font atlas with actually used (displayed) characters only. Also it will enlarge font atlas if there's actually no remaining space. I think this implementation is good enough.

    If the feature exists, developers using CJK languages will be much more easier to use TextMesh Pro, as I believe.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Changes to font asset in the Editor are persistent. So if you had a font asset with Multi Atlas Texture enabled, in the Editor it could eventually grow to include all glyphs.

    However, changes to font asset at runtime are not persistent between play sessions. Whenever your app is loaded, the font assets will be in their initial ship state. So if your font assets were empty when you created your build, they will be empty at the start of each play session.

    As per the above, you then only have to worry about the characters a user can type in a single play session.

    Note:
    - The Multi Atlas Texture option results in additional atlas textures being created as needed at runtime.
    - The "Clear Dynamic Data on Build" clear all dynamic data which includes the Character and Glyph tables as well as Atlas Textures. It also resizes the main atlas texture back to size 0. This data is cleared when creating a build as well as when closing the Editor.
    - The newly added "Clear Dynamic Data" context menu option, does the same as above but can be manually triggered.
    - The "Reset" context menu option on font assets clears all dynamic data that is cleared by the Clear Dynamic Data on Build option but also clears the OpenType Layout feature tables such as Pair Adjustments, Mark-to-Base, Mark-to-Mark, etc.
     
  3. psyhama

    psyhama

    Joined:
    Sep 4, 2018
    Posts:
    28
    Thanks for the reply!

    > As per the above, you then only have to worry about the characters a user can type in a single play session.

    We also have to worry about the characters the user can 'view' in a single play session and that may be become massive number of characters.

    We're thinking about runtime only (almost). In our use case, our app has functionality to browse through many contents, like Steam, or iOS App Store. So the possible characters are not limited.
    Surely, at each one time, the displayed contents will be limited to just some sentences, but during a play session, users can browse through many many sentences which may include more than 10000 glyphs. So if multi atlas textures work at runtime (if I understand correctly), it will eventually make many textures than actually needed, which may impact texture memory size and performance.

    So what I think is that clearing font atlas texture at 'good timing' is nice. Then, old unused glyphs will be discarded at the time. One candidate of the 'good timing' may be the time that one atlas texture becoming full.
     
    Last edited: Jun 12, 2022