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
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-03-30 23:50:17 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-03-30 23:50:17 +0300
commit4241d6a9ccd0790f90ab1cc63446474dcbc08719 (patch)
tree71e19a53f22f7ebfb16aa4a5b6e211ee9804647a /source
parent96d6a928ab4e74fe07ac337d3292057bedd9dc21 (diff)
BFL: Fix broken vertical texts.
I've made a separate version of the geom shader that works with full 3D modelviewmat. This commit also includes some fixup inside blf_batching_start().
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenfont/intern/blf_font.c21
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h2
-rw-r--r--source/blender/gpu/CMakeLists.txt2
-rw-r--r--source/blender/gpu/GPU_shader.h1
-rw-r--r--source/blender/gpu/intern/gpu_shader.c5
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_geom.glsl19
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl34
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl22
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl8
9 files changed, 89 insertions, 25 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 1df1dc5706c..745cd142467 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -124,12 +124,12 @@ void blf_batching_start(FontBLF *font)
}
const bool font_changed = (g_batch.font != font);
- g_batch.font = font;
+ const bool simple_shader = ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0);
+ const bool shader_changed = (simple_shader != g_batch.simple_shader);
- const bool manual_ofs_active = ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0);
- g_batch.active = g_batch.enabled && manual_ofs_active;
+ g_batch.active = g_batch.enabled && simple_shader;
- if (manual_ofs_active) {
+ if (g_batch.simple_shader) {
/* Offset is applied to each glyph. */
copy_v2_v2(g_batch.ofs, font->pos);
}
@@ -143,8 +143,6 @@ void blf_batching_start(FontBLF *font)
gpuGetModelViewMatrix(gpumat);
bool mat_changed = (memcmp(gpumat, g_batch.mat, sizeof(g_batch.mat)) != 0);
- /* Save for next memcmp. */
- memcpy(g_batch.mat, gpumat, sizeof(g_batch.mat));
if (mat_changed) {
/* Modelviewmat is no longer the same.
@@ -154,8 +152,12 @@ void blf_batching_start(FontBLF *font)
}
/* flush cache if config is not the same. */
- if (mat_changed || font_changed) {
+ if (mat_changed || font_changed || shader_changed) {
blf_batching_draw();
+ g_batch.simple_shader = simple_shader;
+ g_batch.font = font;
+ /* Save for next memcmp. */
+ memcpy(g_batch.mat, gpumat, sizeof(g_batch.mat));
}
else {
/* Nothing changed continue batching. */
@@ -169,6 +171,8 @@ void blf_batching_start(FontBLF *font)
else {
/* flush cache */
blf_batching_draw();
+ g_batch.font = font;
+ g_batch.simple_shader = simple_shader;
}
}
@@ -187,7 +191,8 @@ void blf_batching_draw(void)
GWN_vertbuf_vertex_count_set(g_batch.verts, g_batch.glyph_ct);
GWN_vertbuf_use(g_batch.verts); /* send data */
- GWN_batch_program_set_builtin(g_batch.batch, GPU_SHADER_TEXT);
+ 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);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 91d7917b0b5..5808bd38990 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -44,7 +44,7 @@ typedef struct BatchBLF{
unsigned int glyph_ct;
float ofs[2]; /* copy of font->pos */
float mat[4][4]; /* previous call modelmatrix. */
- bool enabled, active;
+ bool enabled, active, simple_shader;
} BatchBLF;
extern BatchBLF g_batch;
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index c754a21b427..f0e5b0842fc 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -202,6 +202,8 @@ data_to_c_simple(shaders/gpu_shader_edges_overlay_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_edges_overlay_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_edges_overlay_simple_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_edges_overlay_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
data_to_c_simple(shaders/gpu_shader_text_geom.glsl SRC)
data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC)
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 6a156b32c35..1a1ec120d28 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -97,6 +97,7 @@ typedef enum GPUBuiltinShader {
/* specialized drawing */
GPU_SHADER_TEXT,
+ GPU_SHADER_TEXT_SIMPLE,
GPU_SHADER_EDGES_FRONT_BACK_PERSP,
GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
GPU_SHADER_EDGES_OVERLAY_SIMPLE,
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index 586a7b70cd9..ad6331befce 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -137,6 +137,8 @@ extern char datatoc_gpu_shader_edges_overlay_frag_glsl[];
extern char datatoc_gpu_shader_text_vert_glsl[];
extern char datatoc_gpu_shader_text_geom_glsl[];
extern char datatoc_gpu_shader_text_frag_glsl[];
+extern char datatoc_gpu_shader_text_simple_vert_glsl[];
+extern char datatoc_gpu_shader_text_simple_geom_glsl[];
extern char datatoc_gpu_shader_keyframe_diamond_vert_glsl[];
extern char datatoc_gpu_shader_keyframe_diamond_frag_glsl[];
@@ -653,6 +655,9 @@ GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
[GPU_SHADER_TEXT] = { datatoc_gpu_shader_text_vert_glsl,
datatoc_gpu_shader_text_frag_glsl,
datatoc_gpu_shader_text_geom_glsl },
+ [GPU_SHADER_TEXT_SIMPLE] = { datatoc_gpu_shader_text_simple_vert_glsl,
+ datatoc_gpu_shader_text_frag_glsl,
+ datatoc_gpu_shader_text_simple_geom_glsl },
[GPU_SHADER_KEYFRAME_DIAMOND] = { datatoc_gpu_shader_keyframe_diamond_vert_glsl,
datatoc_gpu_shader_keyframe_diamond_frag_glsl },
[GPU_SHADER_EDGES_FRONT_BACK_PERSP] = { datatoc_gpu_shader_edges_front_back_persp_vert_glsl,
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
index d12b60be9e9..d4d86db6bc3 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
@@ -1,4 +1,6 @@
+uniform mat4 ModelViewProjectionMatrix;
+
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
@@ -12,22 +14,21 @@ 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;
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
+ texCoord_interp = tex_rect[0].xy;
EmitVertex();
- gl_Position.xy = pos_rect[0].zy;
- texCoord_interp = tex_rect[0].zw;
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
+ texCoord_interp = tex_rect[0].zy;
EmitVertex();
- gl_Position.xy = pos_rect[0].xw;
- texCoord_interp = tex_rect[0].xy;
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
+ texCoord_interp = tex_rect[0].xw;
EmitVertex();
- gl_Position.xy = pos_rect[0].zw;
- texCoord_interp = tex_rect[0].zy;
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
+ texCoord_interp = tex_rect[0].zw;
EmitVertex();
EndPrimitive();
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
new file mode 100644
index 00000000000..79dc996997b
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_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].xy;
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].zy;
+ texCoord_interp = tex_rect[0].zy;
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].xw;
+ texCoord_interp = tex_rect[0].xw;
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].zw;
+ texCoord_interp = tex_rect[0].zw;
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
new file mode 100644
index 00000000000..4a2cde71e07
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
@@ -0,0 +1,22 @@
+
+/* Simpler version of gpu_shader_text_vert that supports only 2D translation. */
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec4 pos; /* rect */
+in vec4 tex; /* rect */
+in vec4 col;
+
+out vec4 pos_rect;
+out vec4 tex_rect;
+out vec4 color;
+
+void main()
+{
+ /* Manual mat4*vec2 */
+ pos_rect = ModelViewProjectionMatrix[0].xyxy * pos.xxzz;
+ pos_rect += ModelViewProjectionMatrix[1].xyxy * pos.yyww;
+ pos_rect += ModelViewProjectionMatrix[3].xyxy;
+ tex_rect = tex;
+ color = col;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
index d8e46aca975..338156f5b68 100644
--- a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -11,13 +11,7 @@ out vec4 color;
void main()
{
- /* 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);
-
+ pos_rect = pos;
tex_rect = tex;
color = col;
}