From 4398896905a41ed065facabf1012c8cb0ad0df84 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 22 Apr 2024 10:30:27 -0700 Subject: [PATCH] renderer/opengl: strikethrough as sprite --- src/renderer/Metal.zig | 4 +--- src/renderer/OpenGL.zig | 35 ++++++++++++++++---------------- src/renderer/shaders/cell.f.glsl | 5 ----- src/renderer/shaders/cell.v.glsl | 19 ----------------- 4 files changed, 18 insertions(+), 45 deletions(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 030df4834..0afc363a8 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -1918,13 +1918,11 @@ fn updateCell( }, ); - const color = style.underlineColor(palette) orelse colors.fg; - self.cells.appendAssumeCapacity(.{ .mode = .fg, .grid_pos = .{ @as(f32, @floatFromInt(x)), @as(f32, @floatFromInt(y)) }, .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, .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, .glyph_size = .{ render.glyph.width, render.glyph.height }, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 2056a236d..7e7ab7dbe 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -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) { + 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(.{ - .mode = .strikethrough, + .mode = .fg, .grid_col = @intCast(x), .grid_row = @intCast(y), .grid_width = cell.gridWidth(), - .glyph_x = 0, - .glyph_y = 0, - .glyph_width = 0, - .glyph_height = 0, - .glyph_offset_x = 0, - .glyph_offset_y = 0, + .glyph_x = render.glyph.atlas_x, + .glyph_y = render.glyph.atlas_y, + .glyph_width = render.glyph.width, + .glyph_height = render.glyph.height, + .glyph_offset_x = render.glyph.offset_x, + .glyph_offset_y = render.glyph.offset_y, .r = colors.fg.r, .g = colors.fg.g, .b = colors.fg.b, diff --git a/src/renderer/shaders/cell.f.glsl b/src/renderer/shaders/cell.f.glsl index e408fffc8..7c2a55370 100644 --- a/src/renderer/shaders/cell.f.glsl +++ b/src/renderer/shaders/cell.f.glsl @@ -28,7 +28,6 @@ const uint MODE_BG = 1u; const uint MODE_FG = 2u; const uint MODE_FG_CONSTRAINED = 3u; const uint MODE_FG_COLOR = 7u; -const uint MODE_STRIKETHROUGH = 8u; void main() { float a; @@ -48,9 +47,5 @@ void main() { case MODE_FG_COLOR: out_FragColor = texture(text_color, glyph_tex_coords); break; - - case MODE_STRIKETHROUGH: - out_FragColor = color; - break; } } diff --git a/src/renderer/shaders/cell.v.glsl b/src/renderer/shaders/cell.v.glsl index 89ec51f1e..16e61773c 100644 --- a/src/renderer/shaders/cell.v.glsl +++ b/src/renderer/shaders/cell.v.glsl @@ -8,7 +8,6 @@ const uint MODE_BG = 1u; const uint MODE_FG = 2u; const uint MODE_FG_CONSTRAINED = 3u; const uint MODE_FG_COLOR = 7u; -const uint MODE_STRIKETHROUGH = 8u; // The grid coordinates (x, y) where x < columns and y < rows layout (location = 0) in vec2 grid_coord; @@ -57,8 +56,6 @@ uniform sampler2D text; uniform sampler2D text_color; uniform vec2 cell_size; uniform mat4 projection; -uniform float strikethrough_position; -uniform float strikethrough_thickness; uniform float min_contrast; /******************************************************************** @@ -233,21 +230,5 @@ void main() { } color = color_final; 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; } }