Strategies for background-thread text rendering

Since the jassert in Font::getGlyphPositions() it isn’t possible to draw text on a image without locking the MessageManagerLock.

I can’t use the MML for several reasons, what are possible alternatives to draw text on a background thread?

just skip the call to Font::getGlyphPositions:

Array<int> pos;
Array<int> xOffsets;
Font f;
String text = "hello";
f.getTypeface()->getGlyphPositions (text, pos, xOffsets);
Path p;
f.getTypeface()->getOutlineForGlyphs(pos[0], p); //store the outline for 'h' in Path p;

Hi makatmusic,

thanks! Unfortunately there is no getOutlineForGlyphs function, only getOutlineForGlyph.
I tried to reconstruct functionality from the juce classes, to allow simple text-rendering, but it seems much more complicated then i thought.

…also it seems the functionally already exists, for example in the CustomFont rendering classes (Is there anyway to use them with build-In fonts?)

Any help appreciated…

Did you ever find a solution for this? We’re bumping up against this issue again.

To summarize for anyone else who finds this:

As far as I know, it is currently not possible (at least not straightforwardly) to render 60 fps (or faster) text animations in JUCE.

This is because rendering text on a background thread in JUCE requires the message thread to be locked (specifically for getGlyphPositions() ). Locking the OpenGL thread, though, can cause deadlocks (see Another OpenGL deadlock thread) and other issues, and is generally fairly detrimental for performance/framerate, especially with multiple windows running.

1 Like

Also hitting this issue. Temporary and annoyingly complex solution is to do all graphics rendering inside a thread to offload, and then export the text computed inside the thread for rendering back on the main thread when I blit the image onto the screen. It works but - man this is kludgy.

I do not see a compelling design reason why the glyph code cannot be made thread-safe. I think a lot of people would be happy if this were to be implemented in a forthcoming release… Me too…