diff options
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 4 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 23 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 51 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 21 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 8 |
5 files changed, 48 insertions, 59 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 90c0016d0ed..f9ad1de8015 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -49,9 +49,6 @@ void BLF_default_set(int fontid); int BLF_default(void); /* get default font ID so we can pass it to other functions */ void BLF_batch_reset(void); /* call when changing opengl context. */ -void BLF_antialias_set(bool enabled); -bool BLF_antialias_get(void); - void BLF_cache_clear(void); int BLF_load(const char *name) ATTR_NONNULL(); @@ -232,6 +229,7 @@ void BLF_state_print(int fontid); #define BLF_ASPECT (1 << 5) #define BLF_HINTING (1 << 6) #define BLF_WORD_WRAP (1 << 7) +#define BLF_MONOCHROME (1 << 8) /* no-AA */ #define BLF_DRAW_STR_DUMMY_MAX 1024 diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 5dd692d3855..8e3f42e4d27 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -85,7 +85,6 @@ static FontBLF *global_font[BLF_MAX_FONT] = {NULL}; static int global_font_default = -1; static int global_font_points = 11; static int global_font_dpi = 72; -static bool global_use_antialias = true; /* XXX, should these be made into global_font_'s too? */ int blf_mono_font = -1; @@ -190,16 +189,6 @@ int BLF_default(void) return global_font_default; } -void BLF_antialias_set(bool enabled) -{ - global_use_antialias = enabled; -} - -bool BLF_antialias_get(void) -{ - return global_use_antialias; -} - int BLF_load(const char *name) { FontBLF *font; @@ -594,24 +583,24 @@ static void blf_draw_gl__start(FontBLF *font) if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0) return; /* glyphs will be translated individually and batched. */ - gpuPushMatrix(); + GPU_matrix_push(); if (font->flags & BLF_MATRIX) - gpuMultMatrix(font->m); + GPU_matrix_mul(font->m); - gpuTranslate3fv(font->pos); + GPU_matrix_translate_3fv(font->pos); if (font->flags & BLF_ASPECT) - gpuScale3fv(font->aspect); + GPU_matrix_scale_3fv(font->aspect); if (font->flags & BLF_ROTATION) - gpuRotate2D(RAD2DEG(font->angle)); + GPU_matrix_rotate_2d(RAD2DEG(font->angle)); } static void blf_draw_gl__end(FontBLF *font) { if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0) - gpuPopMatrix(); + GPU_matrix_pop(); } void BLF_draw_ex( diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index b3ab36f7bcc..f7a926275a9 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -91,31 +91,31 @@ static SpinLock ft_lib_mutex; **/ static void blf_batch_draw_init(void) { - Gwn_VertFormat format = {0}; - g_batch.pos_loc = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT); - g_batch.tex_loc = GWN_vertformat_attr_add(&format, "tex", GWN_COMP_F32, 4, GWN_FETCH_FLOAT); - g_batch.col_loc = GWN_vertformat_attr_add(&format, "col", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT); + GPUVertFormat format = {0}; + g_batch.pos_loc = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + g_batch.tex_loc = GPU_vertformat_attr_add(&format, "tex", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + g_batch.col_loc = GPU_vertformat_attr_add(&format, "col", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); - g_batch.verts = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_STREAM); - GWN_vertbuf_data_alloc(g_batch.verts, BLF_BATCH_DRAW_LEN_MAX); + g_batch.verts = GPU_vertbuf_create_with_format_ex(&format, GPU_USAGE_STREAM); + GPU_vertbuf_data_alloc(g_batch.verts, BLF_BATCH_DRAW_LEN_MAX); - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step); - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step); - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step); g_batch.glyph_len = 0; - g_batch.batch = GWN_batch_create_ex(GWN_PRIM_POINTS, g_batch.verts, NULL, GWN_BATCH_OWNS_VBO); + g_batch.batch = GPU_batch_create_ex(GPU_PRIM_POINTS, g_batch.verts, NULL, GPU_BATCH_OWNS_VBO); } static void blf_batch_draw_exit(void) { - GWN_BATCH_DISCARD_SAFE(g_batch.batch); + GPU_BATCH_DISCARD_SAFE(g_batch.batch); } void blf_batch_draw_vao_clear(void) { if (g_batch.batch) { - gwn_batch_vao_cache_clear(g_batch.batch); + GPU_batch_vao_cache_clear(g_batch.batch); } } @@ -133,7 +133,8 @@ void blf_batch_draw_begin(FontBLF *font) if (simple_shader) { /* Offset is applied to each glyph. */ - copy_v2_v2(g_batch.ofs, font->pos); + g_batch.ofs[0] = floorf(font->pos[0]); + g_batch.ofs[1] = floorf(font->pos[1]); } else { /* Offset is baked in modelview mat. */ @@ -142,15 +143,15 @@ void blf_batch_draw_begin(FontBLF *font) if (g_batch.active) { float gpumat[4][4]; - gpuGetModelViewMatrix(gpumat); + GPU_matrix_model_view_get(gpumat); bool mat_changed = (memcmp(gpumat, g_batch.mat, sizeof(g_batch.mat)) != 0); if (mat_changed) { /* Modelviewmat is no longer the same. * Flush cache but with the previous mat. */ - gpuPushMatrix(); - gpuLoadMatrix(g_batch.mat); + GPU_matrix_push(); + GPU_matrix_set(g_batch.mat); } /* flush cache if config is not the same. */ @@ -165,7 +166,7 @@ void blf_batch_draw_begin(FontBLF *font) } if (mat_changed) { - gpuPopMatrix(); + GPU_matrix_pop(); /* Save for next memcmp. */ memcpy(g_batch.mat, gpumat, sizeof(g_batch.mat)); } @@ -190,20 +191,20 @@ void blf_batch_draw(void) UI_widgetbase_draw_cache_flush(); GPU_texture_bind(g_batch.tex_bind_state, 0); - GWN_vertbuf_vertex_count_set(g_batch.verts, g_batch.glyph_len); - GWN_vertbuf_use(g_batch.verts); /* send data */ + GPU_vertbuf_vertex_count_set(g_batch.verts, g_batch.glyph_len); + GPU_vertbuf_use(g_batch.verts); /* send data */ GPUBuiltinShader shader = (g_batch.simple_shader) ? GPU_SHADER_TEXT_SIMPLE : GPU_SHADER_TEXT; - GWN_batch_program_set_builtin(g_batch.batch, shader); - GWN_batch_uniform_1i(g_batch.batch, "glyph", 0); - GWN_batch_draw(g_batch.batch); + GPU_batch_program_set_builtin(g_batch.batch, shader); + GPU_batch_uniform_1i(g_batch.batch, "glyph", 0); + GPU_batch_draw(g_batch.batch); GPU_blend(false); /* restart to 1st vertex data pointers */ - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step); - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step); - GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step); + GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step); g_batch.glyph_len = 0; } diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 8dc11443124..5b1a382e368 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -269,7 +269,6 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) GlyphBLF *g; FT_Error err; FT_Bitmap bitmap, tempbitmap; - const bool is_sharp = !BLF_antialias_get(); int flags = FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP; FT_BBox bbox; unsigned int key; @@ -294,10 +293,12 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) if (font->flags & BLF_HINTING) flags &= ~FT_LOAD_NO_HINTING; - if (is_sharp) + if (font->flags & BLF_MONOCHROME) { err = FT_Load_Glyph(font->face, (FT_UInt)index, FT_LOAD_TARGET_MONO); - else + } + else { err = FT_Load_Glyph(font->face, (FT_UInt)index, flags); + } if (err) { BLI_spin_unlock(font->ft_lib_mutex); @@ -307,7 +308,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) /* get the glyph. */ slot = font->face->glyph; - if (is_sharp) { + if (font->flags & BLF_MONOCHROME) { err = FT_Render_Glyph(slot, FT_RENDER_MODE_MONO); /* Convert result from 1 bit per pixel to 8 bit per pixel */ @@ -336,7 +337,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c) g->height = (int)bitmap.rows; if (g->width && g->height) { - if (is_sharp) { + if (font->flags & BLF_MONOCHROME) { /* Font buffer uses only 0 or 1 values, Blender expects full 0..255 range */ int i; for (i = 0; i < (g->width * g->height); i++) { @@ -382,10 +383,10 @@ static void blf_texture_draw(const unsigned char color[4], const float uv[2][2], { /* Only one vertex per glyph, geometry shader expand it into a quad. */ /* TODO Get rid of Geom Shader because it's not optimal AT ALL for the GPU */ - copy_v4_fl4(GWN_vertbuf_raw_step(&g_batch.pos_step), x1 + g_batch.ofs[0], y1 + g_batch.ofs[1], + copy_v4_fl4(GPU_vertbuf_raw_step(&g_batch.pos_step), x1 + g_batch.ofs[0], y1 + g_batch.ofs[1], x2 + g_batch.ofs[0], y2 + g_batch.ofs[1]); - copy_v4_v4(GWN_vertbuf_raw_step(&g_batch.tex_step), (float *)uv); - copy_v4_v4_uchar(GWN_vertbuf_raw_step(&g_batch.col_step), color); + copy_v4_v4(GPU_vertbuf_raw_step(&g_batch.tex_step), (float *)uv); + copy_v4_v4_uchar(GPU_vertbuf_raw_step(&g_batch.col_step), color); g_batch.glyph_len++; /* Flush cache if it's full. */ if (g_batch.glyph_len == BLF_BATCH_DRAW_LEN_MAX) { @@ -427,8 +428,8 @@ static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y) { rect->xmin = floorf(x + g->pos_x); rect->xmax = rect->xmin + (float)g->width; - rect->ymin = y + g->pos_y; - rect->ymax = y + g->pos_y - (float)g->height; + rect->ymin = floorf(y + g->pos_y); + rect->ymax = rect->ymin - (float)g->height; } void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y) diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 999773d0212..265835f4c75 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -31,16 +31,16 @@ #ifndef __BLF_INTERNAL_TYPES_H__ #define __BLF_INTERNAL_TYPES_H__ -#include "../../../intern/gawain/gawain/gwn_vertex_buffer.h" +#include "GPU_vertex_buffer.h" #include "GPU_texture.h" #define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */ typedef struct BatchBLF { struct FontBLF *font; /* can only batch glyph from the same font */ - struct Gwn_Batch *batch; - struct Gwn_VertBuf *verts; - struct Gwn_VertBufRaw pos_step, tex_step, col_step; + struct GPUBatch *batch; + struct GPUVertBuf *verts; + struct GPUVertBufRaw pos_step, tex_step, col_step; unsigned int pos_loc, tex_loc, col_loc; unsigned int glyph_len; float ofs[2]; /* copy of font->pos */ |