CCLabelTTF - Batch render when using same font

Since we have auto-batching, it’s quite easy to reduce draw calls by using TriangleCommands and the same texture. For example I was able to hack CCProgressTimers into batch rendering recently.

Now I’m wondering if the same could be done for CCLabelTTF and using the same Font file. I’ve gone through the whole source code of CCLabel, FontAtlas, FontFreeType, etc. a couple of times, but I wasn’t able to find the place where the texture is being created and the triangles to draw are being calculated.

Has anyone achieved this yet or does anyone have some clues for me how I could achieve this?

Any help is highly appreciated :wink:

2 Likes

Anyone? :wink:

Another bump :wink:

I think this is the one you’re looking for, if you can make sure the label is using the same texture, the render will auto batch them.

1 Like

@nite Ah! Thank you, this is interesting.

So this might be way more difficult than I thought since it seems to create one texture per TTFLabel and it’s also taking the specific string into account. As the function says, it’s creating a sprite for the specific text and that’s it…

Isn’t that going to be quite inefficient if you use quite a few of these in terms of texture memory?

Since it’s quite impossible to have Bitmap fonts in your app for every language, I wanted to use TTF fonts…but I’m really concerned about the performance and memory usage.

Do you have an idea how batch rendering could be achieved for this kind of fonts?

Maybe by having a shared texture for all the labels with same font-size, any new characters will be added to that texture.

I’m dealing with 220 draw calls, where 130 of them are drawing text, so to add to this because I’m dealing with a similar problem, these is the call that leads them to finding a FontAtlas

then here they go and find the cached texture in the atlas (im on 3.13 still, so this looks a little different for me, but it seems like its still similar)

I assumed because once I had all the fontatlas caches set up to be identical (by hardcoding in a ttfconfig on that line) I’d see a reduction in draw calls through showDisplayStats but no dice. Only if I hide the labels with setVisible(false) do I see a performance hit.

Still doing research into whether bitmap fonts solves this.

The problem is that TTF fonts do not have any caching mechanism for the glyph they once rendered. Every time you request a certain string from a TTF label, this exact string will be rendered to a texture and then displayed as a sprite.

Bitmap fonts definitely solve that, they can be batch rendered. But bitmap fonts have other issues - you can’t provide a bitmap font for every language and all symbols needed in all languages - or at least it’s hard.

It’s funny that you did this up now. I’ve suggested/asked yesterday to create bitmap fonts from TTF fonts at runtime. Maybe that would also solve your issues (once we have a a solution):

1 Like