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:
authorGermano Cavalcante <germano.costa@ig.com.br>2020-02-23 23:30:27 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2020-02-24 14:01:22 +0300
commit001f7c92d1452e01622f066d37bd42545b650a27 (patch)
treec31f0067b2b6399b7c2b2f55ded1af244e67e248 /source/blender/blenfont/intern/blf_internal_types.h
parenta31bd3f7b5cf27166ccdf3b33890533c5366eb4f (diff)
BLF: Optimize text rendering and caching
The current code allocates and transfers a lot of memory to the GPU, but only a small portion of this memory is actually used. In addition, the code calls many costly gl operations during the caching process. This commit significantly reduce the amount of memory by allocating and transferring a flat array without pads to the GPU. It also calls as little as possible the gl operations during the cache. This code also simulate a billinear filter `GL_LINEAR` using a 1D texture. **Average drawing time:** |before:|0.00003184 sec |now:|0.00001943 sec |fac:|1.6385156675048407 **5 worst times:** |before:|[0.001075, 0.001433, 0.002143, 0.002915, 0.003242] |now:|[0.00094, 0.000993, 0.001502, 0.002284, 0.002328] Differential Revision: https://developer.blender.org/D6886
Diffstat (limited to 'source/blender/blenfont/intern/blf_internal_types.h')
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h47
1 files changed, 10 insertions, 37 deletions
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 45086de0f61..bb1697d7860 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -33,13 +33,13 @@ typedef struct BatchBLF {
struct FontBLF *font; /* can only batch glyph from the same font */
struct GPUBatch *batch;
struct GPUVertBuf *verts;
- struct GPUVertBufRaw pos_step, tex_step, col_step;
- unsigned int pos_loc, tex_loc, col_loc;
+ struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step;
+ unsigned int pos_loc, col_loc, offset_loc, glyph_size_loc;
unsigned int glyph_len;
float ofs[2]; /* copy of font->pos */
float mat[4][4]; /* previous call modelmatrix. */
bool enabled, active, simple_shader;
- GPUTexture *tex_bind_state;
+ struct GlyphCacheBLF *glyph_cache;
} BatchBLF;
extern BatchBLF g_batch;
@@ -72,30 +72,16 @@ typedef struct GlyphCacheBLF {
struct GlyphBLF *glyph_ascii_table[256];
/* texture array, to draw the glyphs. */
- GPUTexture **textures;
-
- /* size of the array. */
- unsigned int textures_len;
-
- /* and the last texture, aka. the current texture. */
- unsigned int texture_current;
-
- /* We draw every glyph in a big texture, so this is the
- * current position inside the texture. */
- int offset_x;
- int offset_y;
-
- /* and the space from one to other. */
- int pad;
+ GPUTexture *texture;
+ char *bitmap_result;
+ int bitmap_len;
+ int bitmap_len_landed;
+ int bitmap_len_alloc;
/* and the bigger glyph in the font. */
int glyph_width_max;
int glyph_height_max;
- /* next two integer power of two, to build the texture. */
- int p2_width;
- int p2_height;
-
/* number of glyphs in the font. */
int glyphs_len_max;
@@ -125,12 +111,8 @@ typedef struct GlyphBLF {
/* avoid conversion to int while drawing */
int advance_i;
- /* texture id where this glyph is store. */
- GPUTexture *tex;
-
/* position inside the texture where this glyph is store. */
- int offset_x;
- int offset_y;
+ int offset;
/* Bitmap data, from freetype. Take care that this
* can be NULL.
@@ -142,9 +124,6 @@ typedef struct GlyphBLF {
int height;
int pitch;
- /* uv coords. */
- float uv[2][2];
-
/* X and Y bearing of the glyph.
* The X bearing is from the origin to the glyph left bbox edge.
* The Y bearing is from the baseline to the top of the glyph edge.
@@ -152,8 +131,7 @@ typedef struct GlyphBLF {
float pos_x;
float pos_y;
- /* with value of zero mean that we need build the texture. */
- char build_tex;
+ bool cached;
} GlyphBLF;
typedef struct FontBufInfoBLF {
@@ -239,9 +217,6 @@ typedef struct FontBLF {
/* max texture size. */
int tex_size_max;
- /* cache current OpenGL texture to save calls into the API */
- GPUTexture *tex_bind_state;
-
/* font options. */
int flags;
@@ -286,6 +261,4 @@ typedef struct DirBLF {
char *path;
} DirBLF;
-#define BLF_TEXTURE_UNSET ((unsigned int)-1)
-
#endif /* __BLF_INTERNAL_TYPES_H__ */