diff --git a/src/renderer/generic.zig b/src/renderer/generic.zig index f57339893f..668b65b732 100644 --- a/src/renderer/generic.zig +++ b/src/renderer/generic.zig @@ -1655,7 +1655,6 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .uniforms = frame.uniforms.buffer, .buffers = &.{ frame.cells.buffer, - frame.cells_bg.buffer, }, .textures = &.{ frame.grayscale, @@ -3076,8 +3075,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .atlas = .grayscale, .grid_pos = .{ @intCast(x), @intCast(y) }, .color = .{ color.r, color.g, color.b, alpha }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(y, x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x), @intCast(render.glyph.offset_y), @@ -3107,8 +3107,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .atlas = .grayscale, .grid_pos = .{ @intCast(x), @intCast(y) }, .color = .{ color.r, color.g, color.b, alpha }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(y, x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x), @intCast(render.glyph.offset_y), @@ -3138,8 +3139,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .atlas = .grayscale, .grid_pos = .{ @intCast(x), @intCast(y) }, .color = .{ color.r, color.g, color.b, alpha }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(y, x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x), @intCast(render.glyph.offset_y), @@ -3201,8 +3203,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .bools = .{ .no_min_contrast = noMinContrast(cp) }, .grid_pos = .{ @intCast(x), @intCast(y) }, .color = .{ color.r, color.g, color.b, alpha }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(y, x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x + shaper_cell.x_offset), @intCast(render.glyph.offset_y + shaper_cell.y_offset), @@ -3290,8 +3293,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .bools = .{ .is_cursor_glyph = true }, .grid_pos = .{ x, cursor_vp.y }, .color = .{ cursor_color.r, cursor_color.g, cursor_color.b, alpha }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(cursor_vp.y, x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x), @intCast(render.glyph.offset_y), @@ -3326,8 +3330,9 @@ pub fn Renderer(comptime GraphicsAPI: type) type { .atlas = .grayscale, .grid_pos = .{ @intCast(coord.x), @intCast(coord.y) }, .color = .{ screen_fg.r, screen_fg.g, screen_fg.b, 255 }, - .glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y }, - .glyph_size = .{ render.glyph.width, render.glyph.height }, + .bg_color = self.cells.bgCell(coord.y, coord.x).*, + .glyph_pos = .{ @intCast(render.glyph.atlas_x), @intCast(render.glyph.atlas_y) }, + .glyph_size = .{ @intCast(render.glyph.width), @intCast(render.glyph.height) }, .bearings = .{ @intCast(render.glyph.offset_x), @intCast(render.glyph.offset_y), diff --git a/src/renderer/metal/shaders.zig b/src/renderer/metal/shaders.zig index 0be0235724..638635bad7 100644 --- a/src/renderer/metal/shaders.zig +++ b/src/renderer/metal/shaders.zig @@ -263,8 +263,8 @@ pub const Uniforms = extern struct { /// This is a single parameter for the terminal cell shader. pub const CellText = extern struct { - glyph_pos: [2]u32 align(8) = .{ 0, 0 }, - glyph_size: [2]u32 align(8) = .{ 0, 0 }, + glyph_pos: [2]u16 align(4) = .{ 0, 0 }, + glyph_size: [2]u16 align(4) = .{ 0, 0 }, bearings: [2]i16 align(4) = .{ 0, 0 }, grid_pos: [2]u16 align(4), color: [4]u8 align(4), @@ -274,6 +274,7 @@ pub const CellText = extern struct { is_cursor_glyph: bool = false, _padding: u6 = 0, } align(1) = .{}, + bg_color: [4]u8 align(4) = .{ 0, 0, 0, 0 }, pub const Atlas = enum(u8) { grayscale = 0, @@ -283,7 +284,7 @@ pub const CellText = extern struct { test { // Minimizing the size of this struct is important, // so we test it in order to be aware of any changes. - try std.testing.expectEqual(32, @sizeOf(CellText)); + try std.testing.expectEqual(28, @sizeOf(CellText)); } }; diff --git a/src/renderer/opengl/shaders.zig b/src/renderer/opengl/shaders.zig index 68c1f36a34..6896dfcea0 100644 --- a/src/renderer/opengl/shaders.zig +++ b/src/renderer/opengl/shaders.zig @@ -232,8 +232,8 @@ pub const Uniforms = extern struct { /// This is a single parameter for the terminal cell shader. pub const CellText = extern struct { - glyph_pos: [2]u32 align(8) = .{ 0, 0 }, - glyph_size: [2]u32 align(8) = .{ 0, 0 }, + glyph_pos: [2]u16 align(4) = .{ 0, 0 }, + glyph_size: [2]u16 align(4) = .{ 0, 0 }, bearings: [2]i16 align(4) = .{ 0, 0 }, grid_pos: [2]u16 align(4), color: [4]u8 align(4), @@ -243,17 +243,18 @@ pub const CellText = extern struct { is_cursor_glyph: bool = false, _padding: u6 = 0, } align(1) = .{}, + bg_color: [4]u8 align(4) = .{ 0, 0, 0, 0 }, pub const Atlas = enum(u8) { grayscale = 0, color = 1, }; - // test { - // // Minimizing the size of this struct is important, - // // so we test it in order to be aware of any changes. - // try std.testing.expectEqual(32, @sizeOf(CellText)); - // } + test { + // Minimizing the size of this struct is important, + // so we test it in order to be aware of any changes. + try std.testing.expectEqual(28, @sizeOf(CellText)); + } }; /// This is a single parameter for the cell bg shader. diff --git a/src/renderer/shaders/glsl/cell_text.v.glsl b/src/renderer/shaders/glsl/cell_text.v.glsl index 7e38e2f0c0..bace101c56 100644 --- a/src/renderer/shaders/glsl/cell_text.v.glsl +++ b/src/renderer/shaders/glsl/cell_text.v.glsl @@ -21,6 +21,9 @@ layout(location = 5) in uint atlas; // Misc glyph properties. layout(location = 6) in uint glyph_bools; +// The per-cell background color (RGBA), used for min-contrast and blending. +layout(location = 7) in uvec4 bg_color_in; + // Values `atlas` can take. const uint ATLAS_GRAYSCALE = 0u; const uint ATLAS_COLOR = 1u; @@ -36,10 +39,6 @@ out CellTextVertexOut { vec2 tex_coord; } out_data; -layout(binding = 1, std430) readonly buffer bg_cells { - uint bg_colors[]; -}; - void main() { uvec2 grid_size = unpack2u16(grid_size_packed_2u16); uvec2 cursor_pos = unpack2u16(cursor_pos_packed_2u16); @@ -115,11 +114,8 @@ void main() { // Get our color. We always fetch a linearized version to // make it easier to handle minimum contrast calculations. out_data.color = load_color(color, true); - // Get the BG color - out_data.bg_color = load_color( - unpack4u8(bg_colors[grid_pos.y * grid_size.x + grid_pos.x]), - true - ); + // Get the BG color from the vertex attribute + out_data.bg_color = load_color(bg_color_in, true); // Blend it with the global bg color vec4 global_bg = load_color( unpack4u8(bg_color_packed_4u8), diff --git a/src/renderer/shaders/shaders.metal b/src/renderer/shaders/shaders.metal index 4e02b63368..6fdf0cf1fa 100644 --- a/src/renderer/shaders/shaders.metal +++ b/src/renderer/shaders/shaders.metal @@ -524,13 +524,13 @@ enum CellTextBools : uint8_t { struct CellTextVertexIn { // The position of the glyph in the texture (x, y) - uint2 glyph_pos [[attribute(0)]]; + ushort2 glyph_pos [[attribute(0)]]; // The size of the glyph in the texture (w, h) - uint2 glyph_size [[attribute(1)]]; + ushort2 glyph_size [[attribute(1)]]; // The left and top bearings for the glyph (x, y) - int2 bearings [[attribute(2)]]; + short2 bearings [[attribute(2)]]; // The grid coordinates (x, y) where x < columns and y < rows ushort2 grid_pos [[attribute(3)]]; @@ -543,6 +543,9 @@ struct CellTextVertexIn { // Misc properties of the glyph. uint8_t bools [[attribute(6)]]; + + // The per-cell background color (RGBA). + uchar4 bg_color [[attribute(7)]]; }; struct CellTextVertexOut { @@ -556,8 +559,7 @@ struct CellTextVertexOut { vertex CellTextVertexOut cell_text_vertex( uint vid [[vertex_id]], CellTextVertexIn in [[stage_in]], - constant Uniforms& uniforms [[buffer(1)]], - constant uchar4 *bg_colors [[buffer(2)]] + constant Uniforms& uniforms [[buffer(1)]] ) { // Convert the grid x, y into world space x, y by accounting for cell size float2 cell_pos = uniforms.cell_size * float2(in.grid_pos); @@ -633,9 +635,9 @@ vertex CellTextVertexOut cell_text_vertex( true ); - // Get the BG color + // Get the BG color from the vertex attribute out.bg_color = load_color( - bg_colors[in.grid_pos.y * uniforms.grid_size.x + in.grid_pos.x], + in.bg_color, uniforms.use_display_p3, true );