Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-10-31 02:02:38 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-10-31 02:02:38 +0300
commitb349f7c99d770673cfd27b3ce7de311db33d6b3f (patch)
treebd3115583fc0edd04b3dba8fdbeeab789b159130 /source/blender/blenfont/intern/blf_font.c
parent97d2ca8a3309e3b74990430672e74b1239f76636 (diff)
Minor speedups for 3D view text drawing ~10-15% improved frame-rate with particle display.
- ascii text drawing functions, slightly faster since they dont have to do hash lookups & utf8 conversions for each char. - used ascii drawing functions for the view3d's number display. - each text item was using fixed 128 chars, now only allocate the string length needed.
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r--source/blender/blenfont/intern/blf_font.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 04f40ac825b..9fb40f0206d 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -92,7 +92,7 @@ void blf_font_size(FontBLF *font, int size, int dpi)
}
}
-void blf_font_draw(FontBLF *font, char *str)
+void blf_font_draw(FontBLF *font, const char *str)
{
unsigned int c;
GlyphBLF *g, *g_prev;
@@ -146,6 +146,65 @@ void blf_font_draw(FontBLF *font, char *str)
}
}
+/* faster version of blf_font_draw, ascii only for view dimensions */
+void blf_font_draw_ascii(FontBLF *font, const char *str)
+{
+ char c;
+ GlyphBLF *g, *g_prev;
+ FT_Vector delta;
+ FT_UInt glyph_index;
+ int pen_x, pen_y;
+ int i, has_kerning, st;
+
+ if (!font->glyph_cache)
+ return;
+
+ i= 0;
+ pen_x= 0;
+ pen_y= 0;
+ has_kerning= FT_HAS_KERNING(font->face);
+ g_prev= NULL;
+
+ /* build ascii on demand */
+ if(font->glyph_ascii_table['0']==NULL) {
+ for(i=0; i<256; i++) {
+ g= blf_glyph_search(font->glyph_cache, i);
+ if (!g) {
+ glyph_index= FT_Get_Char_Index(font->face, i);
+ g= blf_glyph_add(font, glyph_index, i);
+ }
+ font->glyph_ascii_table[i]= g;
+ }
+ }
+
+ while ((c= *(str++))) {
+ g= font->glyph_ascii_table[c];
+
+ /* if we don't found a glyph, skip it. */
+ if (!g)
+ continue;
+
+ if (has_kerning && g_prev) {
+ delta.x= 0;
+ delta.y= 0;
+
+ if (font->flags & BLF_KERNING_DEFAULT)
+ st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, ft_kerning_default, &delta);
+ else
+ st= FT_Get_Kerning(font->face, g_prev->idx, g->idx, FT_KERNING_UNFITTED, &delta);
+
+ if (st == 0)
+ pen_x += delta.x >> 6;
+ }
+
+ /* do not return this loop if clipped, we want every character tested */
+ blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
+
+ pen_x += g->advance;
+ g_prev= g;
+ }
+}
+
void blf_font_buffer(FontBLF *font, char *str)
{
unsigned char *cbuf;
@@ -460,6 +519,8 @@ static void blf_font_fill(FontBLF *font)
font->b_col[1]= 0;
font->b_col[2]= 0;
font->b_col[3]= 0;
+
+ memset(font->glyph_ascii_table, 0, sizeof(font->glyph_ascii_table));
}
FontBLF *blf_font_new(char *name, char *filename)