renderer/opengl: strikethrough as sprite

This commit is contained in:
Mitchell Hashimoto
2024-04-22 10:30:27 -07:00
parent ad08842e86
commit 4398896905
4 changed files with 18 additions and 45 deletions

View File

@ -1918,13 +1918,11 @@ fn updateCell(
}, },
); );
const color = style.underlineColor(palette) orelse colors.fg;
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = .fg, .mode = .fg,
.grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) },
.cell_width = cell.gridWidth(), .cell_width = cell.gridWidth(),
.color = .{ color.r, color.g, color.b, alpha }, .color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
.bg_color = bg, .bg_color = bg,
.glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y },
.glyph_size = .{ render.glyph.width, render.glyph.height }, .glyph_size = .{ render.glyph.width, render.glyph.height },

View File

@ -207,17 +207,6 @@ const SetFontSize = struct {
}, },
); );
} }
const bind = try gl_state.cell_program.program.use();
defer bind.unbind();
try gl_state.cell_program.program.setUniform(
"strikethrough_position",
@as(f32, @floatFromInt(self.metrics.strikethrough_position)),
);
try gl_state.cell_program.program.setUniform(
"strikethrough_thickness",
@as(f32, @floatFromInt(self.metrics.strikethrough_thickness)),
);
} }
}; };
@ -1491,17 +1480,27 @@ fn updateCell(
} }
if (style.flags.strikethrough) { if (style.flags.strikethrough) {
const render = try self.font_grid.renderGlyph(
self.alloc,
font.sprite_index,
@intFromEnum(font.Sprite.strikethrough),
.{
.cell_width = if (cell.wide == .wide) 2 else 1,
.grid_metrics = self.grid_metrics,
},
);
self.cells.appendAssumeCapacity(.{ self.cells.appendAssumeCapacity(.{
.mode = .strikethrough, .mode = .fg,
.grid_col = @intCast(x), .grid_col = @intCast(x),
.grid_row = @intCast(y), .grid_row = @intCast(y),
.grid_width = cell.gridWidth(), .grid_width = cell.gridWidth(),
.glyph_x = 0, .glyph_x = render.glyph.atlas_x,
.glyph_y = 0, .glyph_y = render.glyph.atlas_y,
.glyph_width = 0, .glyph_width = render.glyph.width,
.glyph_height = 0, .glyph_height = render.glyph.height,
.glyph_offset_x = 0, .glyph_offset_x = render.glyph.offset_x,
.glyph_offset_y = 0, .glyph_offset_y = render.glyph.offset_y,
.r = colors.fg.r, .r = colors.fg.r,
.g = colors.fg.g, .g = colors.fg.g,
.b = colors.fg.b, .b = colors.fg.b,

View File

@ -28,7 +28,6 @@ const uint MODE_BG = 1u;
const uint MODE_FG = 2u; const uint MODE_FG = 2u;
const uint MODE_FG_CONSTRAINED = 3u; const uint MODE_FG_CONSTRAINED = 3u;
const uint MODE_FG_COLOR = 7u; const uint MODE_FG_COLOR = 7u;
const uint MODE_STRIKETHROUGH = 8u;
void main() { void main() {
float a; float a;
@ -48,9 +47,5 @@ void main() {
case MODE_FG_COLOR: case MODE_FG_COLOR:
out_FragColor = texture(text_color, glyph_tex_coords); out_FragColor = texture(text_color, glyph_tex_coords);
break; break;
case MODE_STRIKETHROUGH:
out_FragColor = color;
break;
} }
} }

View File

@ -8,7 +8,6 @@ const uint MODE_BG = 1u;
const uint MODE_FG = 2u; const uint MODE_FG = 2u;
const uint MODE_FG_CONSTRAINED = 3u; const uint MODE_FG_CONSTRAINED = 3u;
const uint MODE_FG_COLOR = 7u; const uint MODE_FG_COLOR = 7u;
const uint MODE_STRIKETHROUGH = 8u;
// The grid coordinates (x, y) where x < columns and y < rows // The grid coordinates (x, y) where x < columns and y < rows
layout (location = 0) in vec2 grid_coord; layout (location = 0) in vec2 grid_coord;
@ -57,8 +56,6 @@ uniform sampler2D text;
uniform sampler2D text_color; uniform sampler2D text_color;
uniform vec2 cell_size; uniform vec2 cell_size;
uniform mat4 projection; uniform mat4 projection;
uniform float strikethrough_position;
uniform float strikethrough_thickness;
uniform float min_contrast; uniform float min_contrast;
/******************************************************************** /********************************************************************
@ -233,21 +230,5 @@ void main() {
} }
color = color_final; color = color_final;
break; break;
case MODE_STRIKETHROUGH:
// Strikethrough Y value is just our thickness
vec2 strikethrough_size = vec2(cell_size_scaled.x, strikethrough_thickness);
// Position the strikethrough where we are told to
vec2 strikethrough_offset = vec2(cell_size_scaled.x, strikethrough_position) ;
// Go to the bottom of the cell, take away the size of the
// strikethrough, and that is our position. We also float it slightly
// above the bottom.
cell_pos = cell_pos + strikethrough_offset - (strikethrough_size * position);
gl_Position = projection * vec4(cell_pos, cell_z, 1.0);
color = color_in / 255.0;
break;
} }
} }