I am still in the process of reducing memory usage of this new method,
already cut the memory usage in half. The CGUITTGlyphPage now holds
only video::ITexture; video::IImage is dropped. Each SGUITTGlyph holds
a video::IImage of its own glyph bitmap again; however, when the
page->updateTexture() is called, all of the individual bitmap will be
paged accordingly and dropped afterwards. CGUITTFont::draw() remains
unchanged. There's still many code sections and comments need to be
cleaned up, if anyone is interested right away please check out:
http://github.com/arch-jslin/Irrlicht/b ... UITTFont.h
http://github.com/arch-jslin/Irrlicht/b ... UITTFont.h
http://github.com/arch-jslin/Irrlicht/b ... TTFont.cpp
and possibly
http://github.com/arch-jslin/Irrlicht/b ... onment.cpp
about the addFont part.
And I am actually up to reduce the memory usage even further to
one-fourth from now. Because the bitmap we load from FT_Library are
either monochrome or grayscale only, assign them to a A1R5G5B5 or
A8R8G8B8 texture is pretty wasting. Consider a 2048x2048x32bit
texture, that's 16MB already!
I'm not sure if it is even doable or not, because that require a
texture structure that support grayscale(8bit) texture, by doing that
we also need a specific material renderer that will use grayscale
texture (in OpenGL there is GL_LUMINANCE flag which can set texture
flag to grayscale, I don't know about D3D though.), but I am not sure
if I use something like GL_LUMINANCE, can I still do the color
blending?
Beside the loading process, I did change some very subtle thing but it
will affect the performance quite much. I think the page size should
be reduced in general, in order to get a better balance between memory
usage and frames per second performance. I set the page size to
256x256 only if the font size is less than or equal to 21,
512x512 <-> 42 ... and the like. so every page holds like 144 glyphs
or so. The reason is that if you use TrueType font but only the ASCII
character part, it'll be less wasteful; and even if you use many
unicode characters, it still somewhat retains the performance boost.
Another suggestion is: don't use batch load, (i.e. set it to 1 only)
except for the initial batch load. (the first 127 ASCII characters.)
Two reasons for this:
First, there's little difference between cache 1 character a time or
cache a batch which contains tens or hundreds of characters. Because
the real threshold happens when you load glyph and allocate memory for
them. As long as we do it exactly only once for each glyph, and only
calls page->updateTexture() once at most for each call to
font->draw(), the differences between two methods are virtually
unnoticable.
Second, I tried batch loading 128 glyphs a time with chinese
characters, the test case is displaying a chinese news article around
100 ~ 200 words. It resulted in a noticable stutter and the memory
usage bloated, loading more than 4000 glyphs all of a sudden. I think
the cache miss rate of the batch loading method is too high.
All suggestion are welcomed, thanks in advance
Sincerely.