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/gpu/shaders/gpu_shader_text_vert.glsl
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/gpu/shaders/gpu_shader_text_vert.glsl')
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl21
1 files changed, 17 insertions, 4 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
index 28437208e91..768638e5229 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -2,20 +2,33 @@
uniform mat4 ModelViewProjectionMatrix;
in vec4 pos; /* rect */
-in vec4 tex; /* rect */
in vec4 col;
+in int offset;
+in ivec2 glyph_size;
flat out vec4 color_flat;
noperspective out vec2 texCoord_interp;
+flat out int glyph_offset;
+flat out ivec2 glyph_dim;
+flat out int interp_size;
void main()
{
+ color_flat = col;
+ glyph_offset = offset;
+ glyph_dim = abs(glyph_size);
+ interp_size = int(glyph_size.x < 0) + int(glyph_size.y < 0);
+
/* Quad expension using instanced rendering. */
float x = float(gl_VertexID % 2);
float y = float(gl_VertexID / 2);
vec2 quad = vec2(x, y);
- gl_Position = ModelViewProjectionMatrix * vec4(mix(pos.xy, pos.zw, quad), 0.0, 1.0);
- texCoord_interp = mix(abs(tex.xy), abs(tex.zw), quad) * sign(tex.xw);
- color_flat = col;
+ vec2 interp_offset = float(interp_size) / abs(pos.zw - pos.xy);
+ texCoord_interp = mix(-interp_offset, 1.0 + interp_offset, quad);
+
+ vec2 final_pos = mix(
+ pos.xy + ivec2(-interp_size, interp_size), pos.zw + ivec2(interp_size, -interp_size), quad);
+
+ gl_Position = ModelViewProjectionMatrix * vec4(final_pos, 0.0, 1.0);
}