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().
This commit is contained in:
Clément Foucault 2018-03-30 22:50:17 +02:00
parent 96d6a928ab
commit 4241d6a9cc
9 changed files with 91 additions and 27 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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)

View File

@ -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,

View File

@ -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,

View File

@ -1,4 +1,6 @@
uniform mat4 ModelViewProjectionMatrix;
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
@ -12,23 +14,22 @@ 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;
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].zw;
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
texCoord_interp = tex_rect[0].zy;
EmitVertex();
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
texCoord_interp = tex_rect[0].xw;
EmitVertex();
gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
texCoord_interp = tex_rect[0].zw;
EmitVertex();
EndPrimitive();
}

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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;
}