diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-29 21:22:31 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-29 22:32:26 +0300 |
commit | 7144fdf28568e195dc639bea8828e614d7eb6f79 (patch) | |
tree | 837bb3094fea9bca5f6d3c0eacd8e51fa57e784d /source/blender/gpu/shaders | |
parent | c48b6fae9ae6d06bc99fc4eea6a4c54d978d3a16 (diff) |
BLF: Perf: Divide by 6 the amount of verts sent to the GPU.
This means smaller imm buffer usage.
This does not reduce the number of drawcalls.
This uses geometry shader which is slow for the GPU but given we are really
CPU bound on this case, it should not matter.
A perfect implementation would:
- Set the glyph coord in a bufferTexture and just send the glyph ID to the
GPU to read the bufferTexture.
- Use GWN_draw_primitive and draw 2*strllen triangle and just retrieve the
glyph ID and color based on gl_VertexID / 6.
- Stream fixed size buffer that the Driver can discard quickly but this is
the same as improving IMM directly.
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_text_geom.glsl | 34 | ||||
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_text_vert.glsl | 23 |
2 files changed, 49 insertions, 8 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl new file mode 100644 index 00000000000..d12b60be9e9 --- /dev/null +++ b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl @@ -0,0 +1,34 @@ + +layout(points) in; +layout(triangle_strip, max_vertices = 4) out; + +in vec4 pos_rect[]; +in vec4 tex_rect[]; +in vec4 color[]; + +flat out vec4 color_flat; +noperspective out vec2 texCoord_interp; + +void main() +{ + color_flat = color[0]; + gl_Position.zw = vec2(0.0, 1.0); + + gl_Position.xy = pos_rect[0].xy; + texCoord_interp = tex_rect[0].xw; + EmitVertex(); + + gl_Position.xy = pos_rect[0].zy; + texCoord_interp = tex_rect[0].zw; + EmitVertex(); + + gl_Position.xy = pos_rect[0].xw; + texCoord_interp = tex_rect[0].xy; + EmitVertex(); + + gl_Position.xy = pos_rect[0].zw; + texCoord_interp = tex_rect[0].zy; + EmitVertex(); + + EndPrimitive(); +} diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl index 6129f49ce22..d8e46aca975 100644 --- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl @@ -1,16 +1,23 @@ uniform mat4 ModelViewProjectionMatrix; -in vec2 pos; -in vec2 texCoord; -in vec4 color; -flat out vec4 color_flat; -noperspective out vec2 texCoord_interp; +in vec4 pos; /* rect */ +in vec4 tex; /* rect */ +in vec4 col; + +out vec4 pos_rect; +out vec4 tex_rect; +out vec4 color; void main() { - gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); + /* This won't work for real 3D ModelViewProjectionMatrix. */ + vec2 v1 = (ModelViewProjectionMatrix * vec4(pos.xy, 0.0, 1.0)).xy; + vec2 v2 = (ModelViewProjectionMatrix * vec4(pos.zw, 0.0, 1.0)).xy; + + pos_rect.xy = min(v1, v2); + pos_rect.zw = max(v1, v2); - color_flat = color; - texCoord_interp = texCoord; + tex_rect = tex; + color = col; } |