Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/renderer/generic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/metal/shaders.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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));
}
};

Expand Down
15 changes: 8 additions & 7 deletions src/renderer/opengl/shaders.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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.
Expand Down
14 changes: 5 additions & 9 deletions src/renderer/shaders/glsl/cell_text.v.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
16 changes: 9 additions & 7 deletions src/renderer/shaders/shaders.metal
Original file line number Diff line number Diff line change
Expand Up @@ -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)]];
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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
);
Expand Down