Font rendering speed

Font rendering speed

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Font rendering speed

Post by trepan » 01 Apr 2007, 01:31

So I decided to spend an hour to look into my assertion that a
texture atlas based font system implemented in lua would be
faster then the current Spring font system. Here are the results:

Using 8 x "the quick brown fox jumps over the lazy dog"

No font rendering
360 fps (2.778 ms / frame)

Spring outlined text (size = 12)
185 fps (5.405 ms / frame)

LuaUI texture atlas (size = 12)
311 fps (3.215 ms / frame)

Subtract the no-font case from the two other cases:
spring font = 2.627 ms
luaui font = 0.437 ms

That's about 600% faster.

The texture atlas fonts can also be pre-rendered with outlining
(as was the case with the font I tested with, ProFont). I have not
yet included a dynamic string display list manager, which would
render strings with a single display list call, avoiding all the lua
processing and 'gl' call-outs. I could easily see that halving the
amount of time it takes to render a string.

P.S. The texture atlas font was copied from the BZFlag data pack.
To set it up, all I had to do was pick out the character parameters
from their custom font spec files.

P.P.S. This also means that you'd be able to switch between
multiple fonts with very little effort.
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 01 Apr 2007, 01:44

For what it's worth, I also tested the Spring's font rendering
without outlining. It was a slightly different camera setup, but
here are the numbers anyways:

No rendering
358 fps

Spring font (no outline)
297 fps

LuaUI texture atlas rendering
315 fps

Note that the LuaUI rendering is still faster, even though it
has to make a number of lua call-outs for every character
that it renders.

P.S. Oops, forgot to include some vitat stats:
CPU = AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
GPU = Nvidia GeForce 7900 GS
0 x

User avatar
AF
AI Developer
Posts: 20669
Joined: 14 Sep 2004, 11:32

Post by AF » 01 Apr 2007, 03:01

^_^ This should help greatly.

Any chance of outlined fonts on the loading screens? To prevent the whtie text on white explosion syndrome...
0 x

User avatar
LordMatt
Posts: 3393
Joined: 15 May 2005, 04:26

Post by LordMatt » 01 Apr 2007, 04:01

Sweet!
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 01 Apr 2007, 08:06

I've committed a "LuaUI/fonts.lua" font handler that works reasonalbly well.
It is not yet a full replacement for gl.Text(), as it does not yet handle embedded
color codes, text alignment, or font size queries.

This addition also brought a couple of handy texture features along for the
ride. I've added the 'g' and 'i' options to gl.Texture(). The 'g' flag will convert
an image to greyscale (disabled buildpics? does not work with dds images).
The 'i' flag will invert the color components of an image.

This fonts.lua implementation also supports caching complete strings in
display lists to speed up the rendering, and avoid lua processing. Early
testing shows a noticeable improvement.
0 x

MelTraX
Posts: 470
Joined: 02 Jan 2007, 16:18

Post by MelTraX » 01 Apr 2007, 15:25

Wow, this really sounds great.. I will continue my serious GUI work starting tomorrow.. Would you recommend to update my Text to your fonts.lua (if that is possible; haven't looked at it yet) or will you replace the gl.Text call completely any time soon?
0 x

User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 » 01 Apr 2007, 20:53

I have to ask:

How the hell are fonts so inefficient?

EDITED (trepan): removed needless profanity
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 01 Apr 2007, 21:29

There are 2 big slowdowns in Spring's font code (from what I've seen).

1. Texture switches
Each glyph uses a separate texture.

2. glPushAttrib / glPopAttrib
These state calls are used to compartmentalize the font rendering, but
they're oftentimes wasted, especially when you consider how often
multiple lines of text are rendered together.
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 01 Apr 2007, 21:31

MelTrax
If you want to play with it, here's what's currently available:

Code: Select all

fontHandler.SetFont("ProFont_12") 
-- ":ongi:" prefix options can be used

fontHandler.Draw("text..."[, xoffset, yoffset])
-- color code handling will be added later
-- right and center justification may go into separate calls

fontHandler.CalcTextWidth("text...")
-- use the font names height as the height
Notes:
1. "fontHandler" is passed to all widgets.
2. There is no "size" parameter
3. Color codes are not interpreted
4. You have to make sure that the state is setup correctly
(ex: gl.AlphaThresh will affect fontHandler rendering, so
you can make it look as ugly as you want ;))

Available Fonts: (only ProFont is outlined)
LuxiMono_6
LuxiMono_8
LuxiMono_12
LuxiMono_16
LuxiMono_32
ProFont_6
ProFont_8
ProFont_12
ProFont_16
TogaSansBold_6
TogaSansBold_8
TogaSansBold_12
TogaSansBold_16
TogaSansBold_32
TogaSerifBold_12
TogaSerifBold_16
TogaSerifBold_32
VeraMonoBold_6
VeraMonoBold_8
VeraMonoBold_12
VeraMonoBold_16
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 05 Apr 2007, 11:07

I ditched the BZFlag format, and wrote a custom font texture and
metrics file generator. The generator can be used as a stand alone
program, and can be called by LuaUI (it's built into the Spring engine).
It will optionally outline the font, with variable width and darkness. I plan
to setup up a split outline option as well (render twice, needed for bright
outlines). The generator can also write the font glyphs with padding,
to make it easier to edit the texture files without screwing up the metrics
(in case you wanted to do your own outlining, setup a colored font, etc...)

Click on the images to view the high resolution PNG versions (~1.4Mbytes).
Note the proper anti-aliasing, and how smaller fonts are more legible then
with the current rendering.

Image

Image

P.S. It'd probably be quite easy to tie it into the default font rendering
setup, but having it available to LuaUI is good enough for me (for now).

P.P.S. The sizes listed are pixel sizes, not point sizes. The console text in the
second picture is the default Spring font rendering (using the trebuchet font).
0 x

User avatar
Bobcatben
Posts: 120
Joined: 10 Mar 2006, 17:01

Post by Bobcatben » 05 Apr 2007, 15:20

*is trying to understand* this way uses 1 texture with all the letters on it in a grid for each font/color?
0 x

User avatar
Machiosabre
Posts: 1474
Joined: 25 Dec 2005, 22:56

Post by Machiosabre » 05 Apr 2007, 15:41

*the quick brown fox jumps over the unfortunate dog.

it's time somebody set the record straight.
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 06 Apr 2007, 07:21

0 x

User avatar
Machiosabre
Posts: 1474
Joined: 25 Dec 2005, 22:56

Post by Machiosabre » 06 Apr 2007, 12:38

It's from a peanuts comic :P
0 x

User avatar
BvDorp
Posts: 439
Joined: 14 Oct 2005, 12:09

Post by BvDorp » 06 Apr 2007, 12:43

Great work trepan!

However, a lot of ppl don't use LuA at this time, for it slows other processes and can crash. How's that problem atm?

E: Wow, the fonts and outline looks really great! This would be awesome, and really enhance the GUI experience!
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 06 Apr 2007, 15:43

0 x

Caradhras
Posts: 381
Joined: 31 Jul 2006, 21:49

Post by Caradhras » 06 Apr 2007, 20:52

btw is it possible to make he font mod-dependent?
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 06 Apr 2007, 20:53

yes
0 x

trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan » 06 Apr 2007, 21:00

On that note, I'll probably be adding the code for mod-widgets sometime
today or tomorrow. That'll make it easy for mods to provide mod-dependant
widgets, which can interface with mod-dependant LuaRules scripts. The
LuaRules scripts can set custom properties on units which are accessible
to LuaUI (ex: you could add a fuel parameter to all mobile units, and stop
them when they run out; i'd hope you'd also have refueller units...)

P.S. Coding fuel for all units in lua is a waste of resources, and would be
better coded in C++. The point is that the lua scripts are flexible enough to
allow you to fill in some of the missing pieces.
0 x

User avatar
Dragon45
Posts: 2883
Joined: 16 Aug 2004, 04:36

Post by Dragon45 » 12 Apr 2007, 05:04

My lovely profanity :|

It's never needless, you know :P
0 x

Post Reply

Return to “Lua Scripts”