[Bf-blender-cvs] [34dc660] blender2.8: OpenGL: draw text with fewer draw calls

Mike Erwin noreply at git.blender.org
Fri Oct 14 20:44:51 CEST 2016


Commit: 34dc660a7669812a2f1ed829cecd273d4e859d24
Author: Mike Erwin
Date:   Fri Oct 14 14:40:53 2016 -0400
Branches: blender2.8
https://developer.blender.org/rB34dc660a7669812a2f1ed829cecd273d4e859d24

OpenGL: draw text with fewer draw calls

Was one draw call per glyph,  now one per line.

Still room for improvement here.

===================================================================

M	source/blender/blenfont/intern/blf_font.c
M	source/blender/blenfont/intern/blf_glyph.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 44a1d08..7d73465 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 2354769..3d96260 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();
 }




More information about the Bf-blender-cvs mailing list