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:
authorMike Erwin <significant.bit@gmail.com>2016-10-14 21:40:53 +0300
committerMike Erwin <significant.bit@gmail.com>2016-10-14 21:41:36 +0300
commit34dc660a7669812a2f1ed829cecd273d4e859d24 (patch)
tree39c45f8c657f8245dc5a389d741f0a72c05595e6 /source/blender/blenfont
parentdd350c0b37052c0dfb2436fc671cdaf57e065c13 (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')
-rw-r--r--source/blender/blenfont/intern/blf_font.c23
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c12
2 files changed, 23 insertions, 12 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;
}
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 2354769fee0..3d96260f61b 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -469,16 +469,6 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
}
-#if 0 /* determine exact count of quads */
- unsigned quad_ct = 1 + (unsigned)font->blur;
- if (font->flags & BLF_SHADOW)
- quad_ct += (unsigned)font->shadow;
-
- immBegin(GL_QUADS, quad_ct * 4);
-#else
- immBeginAtMost(GL_QUADS, 40); /* (5 shadow + 5 blur) * 4 verts per quad */
-#endif
-
/* TODO: blur & shadow in shader, single quad per glyph */
if (font->flags & BLF_SHADOW) {
@@ -511,6 +501,4 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
immAttrib4fv(BLF_COLOR_ID, font->orig_col);
blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
-
- immEnd();
}