diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-30 20:16:14 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-30 21:09:26 +0300 |
commit | ab9adf9cdc3b2fd91dcade32ea4b4359f4897392 (patch) | |
tree | 1f9e12d6a24fa1f74cfc4ab595ac1680d0202433 /source/blender/blenfont/intern/blf.c | |
parent | 8568d38f1b0858a3138b72698babd6ba7b65d6b3 (diff) |
BLF: Use Batch API instead of IMM.
This is not a perfect win just yet. It's now calling glBufferSubData for
every call (instead of using glMapBufferRange which is almost faster), but
with this system we will be able to batch drawcalls together.
See next commit.
Diffstat (limited to 'source/blender/blenfont/intern/blf.c')
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 30919f1acda..5b51ecbc047 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -132,6 +132,11 @@ void BLF_exit(void) blf_font_exit(); } +void BLF_batch_reset(void) +{ + blf_batching_vao_clear(); +} + void BLF_cache_clear(void) { FontBLF *font; @@ -561,8 +566,11 @@ static void blf_draw_gl__start(FontBLF *font) * in BLF_position (old ui_rasterpos_safe). */ - glEnable(GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + /* always bind the texture for the first glyph */ + font->tex_bind_state = 0; + + if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0) + return; /* glyphs will be translated individually and batched. */ gpuPushMatrix(); @@ -576,35 +584,12 @@ static void blf_draw_gl__start(FontBLF *font) if (font->flags & BLF_ROTATION) gpuRotate2D(RAD2DEG(font->angle)); - -#ifndef BLF_STANDALONE - Gwn_VertFormat *format = immVertexFormat(); - unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT); - unsigned int texCoord = GWN_vertformat_attr_add(format, "tex", GWN_COMP_F32, 4, GWN_FETCH_FLOAT); - unsigned int color = GWN_vertformat_attr_add(format, "col", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT); - - BLI_assert(pos == BLF_POS_ID); - BLI_assert(texCoord == BLF_COORD_ID); - BLI_assert(color == BLF_COLOR_ID); - - UNUSED_VARS_NDEBUG(pos, texCoord, color); - - immBindBuiltinProgram(GPU_SHADER_TEXT); -#endif - - /* always bind the texture for the first glyph */ - font->tex_bind_state = -1; } -static void blf_draw_gl__end(void) +static void blf_draw_gl__end(FontBLF *font) { - gpuPopMatrix(); - -#ifndef BLF_STANDALONE - immUnbindProgram(); -#endif - - glDisable(GL_BLEND); + if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0) + gpuPopMatrix(); } void BLF_draw_ex( @@ -623,7 +608,7 @@ void BLF_draw_ex( else { blf_font_draw(font, str, len, r_info); } - blf_draw_gl__end(); + blf_draw_gl__end(font); } } void BLF_draw(int fontid, const char *str, size_t len) @@ -652,7 +637,7 @@ void BLF_draw_ascii_ex( else { blf_font_draw_ascii(font, str, len, r_info); } - blf_draw_gl__end(); + blf_draw_gl__end(font); } } void BLF_draw_ascii(int fontid, const char *str, size_t len) @@ -676,7 +661,7 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) if (font && font->glyph_cache) { blf_draw_gl__start(font); columns = blf_font_draw_mono(font, str, len, cwidth); - blf_draw_gl__end(); + blf_draw_gl__end(font); } return columns; |