diff options
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 7d734653ffc..42717e65d9b 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -174,6 +174,21 @@ static void blf_font_ensure_ascii_table(FontBLF *font) } \ } (void)0 +static unsigned verts_needed(const FontBLF *font, const char *str, size_t len) +{ + unsigned length = (unsigned)((len == INT_MAX) ? strlen(str) : len); + return length * 40; + /* (5 shadow + 5 blur) * 4 verts per quad + * TODO: determine exact count of quads, somthing like this: */ +#if 0 + unsigned quad_ct = 1 + (unsigned)font->blur; + if (font->flags & BLF_SHADOW) + quad_ct += (unsigned)font->shadow; + + immBegin(GL_QUADS, length * quad_ct * 4); +#endif +} + static void blf_font_draw_ex( FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info, int pen_y) @@ -189,16 +204,7 @@ static void blf_font_draw_ex( blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); - /* (5 shadow + 5 blur) * 4 verts per quad - * TODO: determine exact count of quads, somthing like this: */ -#if 0 - unsigned quad_ct = 1 + (unsigned)font->blur; - if (font->flags & BLF_SHADOW) - quad_ct += (unsigned)font->shadow; - - immBegin(GL_QUADS, (unsigned)len * quad_ct * 4); -#endif + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); @@ -244,7 +250,7 @@ static void blf_font_draw_ascii_ex( blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((c = *(str++)) && len--) { BLI_assert(c < 128); @@ -284,7 +290,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth) blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); |