mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
renderer/opengl: shaders only need one color input
This commit is contained in:
@ -833,15 +833,15 @@ pub fn rebuildCells(
|
||||
if (cursor_cell) |*cell| {
|
||||
if (cell.mode == .fg) {
|
||||
if (self.config.cursor_text) |txt| {
|
||||
cell.fg_r = txt.r;
|
||||
cell.fg_g = txt.g;
|
||||
cell.fg_b = txt.b;
|
||||
cell.fg_a = 255;
|
||||
cell.r = txt.r;
|
||||
cell.g = txt.g;
|
||||
cell.b = txt.b;
|
||||
cell.a = 255;
|
||||
} else {
|
||||
cell.fg_r = 0;
|
||||
cell.fg_g = 0;
|
||||
cell.fg_b = 0;
|
||||
cell.fg_a = 255;
|
||||
cell.r = 0;
|
||||
cell.g = 0;
|
||||
cell.b = 0;
|
||||
cell.a = 255;
|
||||
}
|
||||
}
|
||||
self.cells.appendAssumeCapacity(cell.*);
|
||||
@ -992,14 +992,10 @@ fn addCursor(
|
||||
.grid_col = @intCast(x),
|
||||
.grid_row = @intCast(screen.cursor.y),
|
||||
.grid_width = if (wide) 2 else 1,
|
||||
.fg_r = color.r,
|
||||
.fg_g = color.g,
|
||||
.fg_b = color.b,
|
||||
.fg_a = alpha,
|
||||
.bg_r = 0,
|
||||
.bg_g = 0,
|
||||
.bg_b = 0,
|
||||
.bg_a = 0,
|
||||
.r = color.r,
|
||||
.g = color.g,
|
||||
.b = color.b,
|
||||
.a = alpha,
|
||||
.glyph_x = glyph.atlas_x,
|
||||
.glyph_y = glyph.atlas_y,
|
||||
.glyph_width = glyph.width,
|
||||
@ -1147,14 +1143,10 @@ pub fn updateCell(
|
||||
.glyph_height = 0,
|
||||
.glyph_offset_x = 0,
|
||||
.glyph_offset_y = 0,
|
||||
.fg_r = 0,
|
||||
.fg_g = 0,
|
||||
.fg_b = 0,
|
||||
.fg_a = 0,
|
||||
.bg_r = rgb.r,
|
||||
.bg_g = rgb.g,
|
||||
.bg_b = rgb.b,
|
||||
.bg_a = bg_alpha,
|
||||
.r = rgb.r,
|
||||
.g = rgb.g,
|
||||
.b = rgb.b,
|
||||
.a = bg_alpha,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1189,14 +1181,10 @@ pub fn updateCell(
|
||||
.glyph_height = glyph.height,
|
||||
.glyph_offset_x = glyph.offset_x,
|
||||
.glyph_offset_y = glyph.offset_y,
|
||||
.fg_r = colors.fg.r,
|
||||
.fg_g = colors.fg.g,
|
||||
.fg_b = colors.fg.b,
|
||||
.fg_a = alpha,
|
||||
.bg_r = 0,
|
||||
.bg_g = 0,
|
||||
.bg_b = 0,
|
||||
.bg_a = 0,
|
||||
.r = colors.fg.r,
|
||||
.g = colors.fg.g,
|
||||
.b = colors.fg.b,
|
||||
.a = alpha,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1230,14 +1218,10 @@ pub fn updateCell(
|
||||
.glyph_height = underline_glyph.height,
|
||||
.glyph_offset_x = underline_glyph.offset_x,
|
||||
.glyph_offset_y = underline_glyph.offset_y,
|
||||
.fg_r = color.r,
|
||||
.fg_g = color.g,
|
||||
.fg_b = color.b,
|
||||
.fg_a = alpha,
|
||||
.bg_r = 0,
|
||||
.bg_g = 0,
|
||||
.bg_b = 0,
|
||||
.bg_a = 0,
|
||||
.r = color.r,
|
||||
.g = color.g,
|
||||
.b = color.b,
|
||||
.a = alpha,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1253,14 +1237,10 @@ pub fn updateCell(
|
||||
.glyph_height = 0,
|
||||
.glyph_offset_x = 0,
|
||||
.glyph_offset_y = 0,
|
||||
.fg_r = colors.fg.r,
|
||||
.fg_g = colors.fg.g,
|
||||
.fg_b = colors.fg.b,
|
||||
.fg_a = alpha,
|
||||
.bg_r = 0,
|
||||
.bg_g = 0,
|
||||
.bg_b = 0,
|
||||
.bg_a = 0,
|
||||
.r = colors.fg.r,
|
||||
.g = colors.fg.g,
|
||||
.b = colors.fg.b,
|
||||
.a = alpha,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -25,21 +25,15 @@ pub const Cell = extern struct {
|
||||
glyph_width: u32 = 0,
|
||||
glyph_height: u32 = 0,
|
||||
|
||||
/// vec2 glyph_size
|
||||
/// vec2 glyph_offset
|
||||
glyph_offset_x: i32 = 0,
|
||||
glyph_offset_y: i32 = 0,
|
||||
|
||||
/// vec4 fg_color_in
|
||||
fg_r: u8,
|
||||
fg_g: u8,
|
||||
fg_b: u8,
|
||||
fg_a: u8,
|
||||
|
||||
/// vec4 bg_color_in
|
||||
bg_r: u8,
|
||||
bg_g: u8,
|
||||
bg_b: u8,
|
||||
bg_a: u8,
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
a: u8,
|
||||
|
||||
/// uint mode
|
||||
mode: CellMode,
|
||||
@ -111,11 +105,9 @@ pub fn init() !CellProgram {
|
||||
offset += 2 * @sizeOf(i32);
|
||||
try vbobind.attributeAdvanced(4, 4, gl.c.GL_UNSIGNED_BYTE, false, @sizeOf(Cell), offset);
|
||||
offset += 4 * @sizeOf(u8);
|
||||
try vbobind.attributeAdvanced(5, 4, gl.c.GL_UNSIGNED_BYTE, false, @sizeOf(Cell), offset);
|
||||
offset += 4 * @sizeOf(u8);
|
||||
try vbobind.attributeIAdvanced(6, 1, gl.c.GL_UNSIGNED_BYTE, @sizeOf(Cell), offset);
|
||||
try vbobind.attributeIAdvanced(5, 1, gl.c.GL_UNSIGNED_BYTE, @sizeOf(Cell), offset);
|
||||
offset += 1 * @sizeOf(u8);
|
||||
try vbobind.attributeIAdvanced(7, 1, gl.c.GL_UNSIGNED_BYTE, @sizeOf(Cell), offset);
|
||||
try vbobind.attributeIAdvanced(6, 1, gl.c.GL_UNSIGNED_BYTE, @sizeOf(Cell), offset);
|
||||
try vbobind.enableAttribArray(0);
|
||||
try vbobind.enableAttribArray(1);
|
||||
try vbobind.enableAttribArray(2);
|
||||
@ -123,7 +115,6 @@ pub fn init() !CellProgram {
|
||||
try vbobind.enableAttribArray(4);
|
||||
try vbobind.enableAttribArray(5);
|
||||
try vbobind.enableAttribArray(6);
|
||||
try vbobind.enableAttribArray(7);
|
||||
try vbobind.attributeDivisor(0, 1);
|
||||
try vbobind.attributeDivisor(1, 1);
|
||||
try vbobind.attributeDivisor(2, 1);
|
||||
@ -131,7 +122,6 @@ pub fn init() !CellProgram {
|
||||
try vbobind.attributeDivisor(4, 1);
|
||||
try vbobind.attributeDivisor(5, 1);
|
||||
try vbobind.attributeDivisor(6, 1);
|
||||
try vbobind.attributeDivisor(7, 1);
|
||||
|
||||
return .{
|
||||
.program = program,
|
||||
|
@ -21,20 +21,18 @@ layout (location = 2) in vec2 glyph_size;
|
||||
// Offset of the top-left corner of the glyph when rendered in a rect.
|
||||
layout (location = 3) in vec2 glyph_offset;
|
||||
|
||||
// The background color for this cell in RGBA (0 to 1.0)
|
||||
layout (location = 4) in vec4 fg_color_in;
|
||||
|
||||
// The background color for this cell in RGBA (0 to 1.0)
|
||||
layout (location = 5) in vec4 bg_color_in;
|
||||
// The color for this cell in RGBA (0 to 1.0). Background or foreground
|
||||
// depends on mode.
|
||||
layout (location = 4) in vec4 color_in;
|
||||
|
||||
// The mode of this shader. The mode determines what fields are used,
|
||||
// what the output will be, etc. This shader is capable of executing in
|
||||
// multiple "modes" so that we can share some logic and so that we can draw
|
||||
// the entire terminal grid in a single GPU pass.
|
||||
layout (location = 6) in uint mode_in;
|
||||
layout (location = 5) in uint mode_in;
|
||||
|
||||
// The width in cells of this item.
|
||||
layout (location = 7) in uint grid_width;
|
||||
layout (location = 6) in uint grid_width;
|
||||
|
||||
// The background or foreground color for the fragment, depending on
|
||||
// whether this is a background or foreground pass.
|
||||
@ -117,7 +115,7 @@ void main() {
|
||||
cell_pos = cell_pos + cell_size_scaled * position;
|
||||
|
||||
gl_Position = projection * vec4(cell_pos, cell_z, 1.0);
|
||||
color = bg_color_in / 255.0;
|
||||
color = color_in / 255.0;
|
||||
break;
|
||||
|
||||
case MODE_FG:
|
||||
@ -150,7 +148,7 @@ void main() {
|
||||
glyph_tex_coords = glyph_tex_pos + glyph_tex_size * position;
|
||||
|
||||
// Set our foreground color output
|
||||
color = fg_color_in / 255.;
|
||||
color = color_in / 255.;
|
||||
break;
|
||||
|
||||
case MODE_STRIKETHROUGH:
|
||||
@ -166,7 +164,7 @@ void main() {
|
||||
cell_pos = cell_pos + strikethrough_offset - (strikethrough_size * position);
|
||||
|
||||
gl_Position = projection * vec4(cell_pos, cell_z, 1.0);
|
||||
color = fg_color_in / 255.0;
|
||||
color = color_in / 255.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user