diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-10-14 21:40:53 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-10-14 21:41:36 +0300 |
commit | 34dc660a7669812a2f1ed829cecd273d4e859d24 (patch) | |
tree | 39c45f8c657f8245dc5a389d741f0a72c05595e6 /source/blender/blenfont/intern/blf_font.c | |
parent | dd350c0b37052c0dfb2436fc671cdaf57e065c13 (diff) |
OpenGL: draw text with fewer draw calls
Was one draw call per glyph, now one per line.
Still room for improvement here.
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 44a1d08f1fd..7d734653ffc 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -58,6 +58,8 @@ #include "BIF_gl.h" #include "BLF_api.h" +#include "GPU_immediate.h" + #include "blf_internal_types.h" #include "blf_internal.h" @@ -187,6 +189,17 @@ 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 + while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); @@ -204,6 +217,8 @@ static void blf_font_draw_ex( g_prev = g; } + immEnd(); + if (r_info) { r_info->lines = 1; r_info->width = pen_x; @@ -229,6 +244,8 @@ static void blf_font_draw_ascii_ex( blf_font_ensure_ascii_table(font); + immBeginAtMost(GL_QUADS, (unsigned)len * 40); + while ((c = *(str++)) && len--) { BLI_assert(c < 128); if ((g = glyph_ascii_table[c]) == NULL) @@ -243,6 +260,8 @@ static void blf_font_draw_ascii_ex( g_prev = g; } + immEnd(); + if (r_info) { r_info->lines = 1; r_info->width = pen_x; @@ -265,6 +284,8 @@ 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); + while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); @@ -284,6 +305,8 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth) pen_x += cwidth * col; } + immEnd(); + return columns; } |