mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
renderer/opengl: implement fg_constrained
This commit is contained in:
@ -11,7 +11,6 @@ const objc = @import("objc");
|
|||||||
const macos = @import("macos");
|
const macos = @import("macos");
|
||||||
const imgui = @import("imgui");
|
const imgui = @import("imgui");
|
||||||
const glslang = @import("glslang");
|
const glslang = @import("glslang");
|
||||||
const ziglyph = @import("ziglyph");
|
|
||||||
const apprt = @import("../apprt.zig");
|
const apprt = @import("../apprt.zig");
|
||||||
const configpkg = @import("../config.zig");
|
const configpkg = @import("../config.zig");
|
||||||
const font = @import("../font/main.zig");
|
const font = @import("../font/main.zig");
|
||||||
|
@ -9,6 +9,7 @@ const testing = std.testing;
|
|||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const ArenaAllocator = std.heap.ArenaAllocator;
|
const ArenaAllocator = std.heap.ArenaAllocator;
|
||||||
const link = @import("link.zig");
|
const link = @import("link.zig");
|
||||||
|
const fgMode = @import("cell.zig").fgMode;
|
||||||
const shadertoy = @import("shadertoy.zig");
|
const shadertoy = @import("shadertoy.zig");
|
||||||
const apprt = @import("../apprt.zig");
|
const apprt = @import("../apprt.zig");
|
||||||
const configpkg = @import("../config.zig");
|
const configpkg = @import("../config.zig");
|
||||||
@ -1489,10 +1490,17 @@ pub fn updateCell(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// If we're rendering a color font, we use the color atlas
|
// If we're rendering a color font, we use the color atlas
|
||||||
const presentation = try self.font_group.group.presentationFromIndex(shaper_run.font_index);
|
const mode: CellProgram.CellMode = switch (try fgMode(
|
||||||
const mode: CellProgram.CellMode = switch (presentation) {
|
&self.font_group.group,
|
||||||
.text => .fg,
|
screen,
|
||||||
.emoji => .fg_color,
|
cell,
|
||||||
|
shaper_run,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
)) {
|
||||||
|
.normal => .fg,
|
||||||
|
.color => .fg_color,
|
||||||
|
.constrained => .fg_constrained,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.cells.appendAssumeCapacity(.{
|
self.cells.appendAssumeCapacity(.{
|
||||||
|
@ -51,6 +51,7 @@ pub const Cell = extern struct {
|
|||||||
pub const CellMode = enum(u8) {
|
pub const CellMode = enum(u8) {
|
||||||
bg = 1,
|
bg = 1,
|
||||||
fg = 2,
|
fg = 2,
|
||||||
|
fg_constrained = 3,
|
||||||
fg_color = 7,
|
fg_color = 7,
|
||||||
strikethrough = 8,
|
strikethrough = 8,
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ uniform vec2 cell_size;
|
|||||||
// See vertex shader
|
// See vertex shader
|
||||||
const uint MODE_BG = 1u;
|
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_COLOR = 7u;
|
const uint MODE_FG_COLOR = 7u;
|
||||||
const uint MODE_STRIKETHROUGH = 8u;
|
const uint MODE_STRIKETHROUGH = 8u;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ void main() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_FG:
|
case MODE_FG:
|
||||||
|
case MODE_FG_CONSTRAINED:
|
||||||
a = texture(text, glyph_tex_coords).r;
|
a = texture(text, glyph_tex_coords).r;
|
||||||
vec3 premult = color.rgb * color.a;
|
vec3 premult = color.rgb * color.a;
|
||||||
out_FragColor = vec4(premult.rgb*a, a);
|
out_FragColor = vec4(premult.rgb*a, a);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
// NOTE: this must be kept in sync with the fragment shader
|
// NOTE: this must be kept in sync with the fragment shader
|
||||||
const uint MODE_BG = 1u;
|
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_COLOR = 7u;
|
const uint MODE_FG_COLOR = 7u;
|
||||||
const uint MODE_STRIKETHROUGH = 8u;
|
const uint MODE_STRIKETHROUGH = 8u;
|
||||||
|
|
||||||
@ -179,6 +180,7 @@ void main() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MODE_FG:
|
case MODE_FG:
|
||||||
|
case MODE_FG_CONSTRAINED:
|
||||||
case MODE_FG_COLOR:
|
case MODE_FG_COLOR:
|
||||||
vec2 glyph_offset_calc = glyph_offset;
|
vec2 glyph_offset_calc = glyph_offset;
|
||||||
|
|
||||||
@ -187,8 +189,19 @@ void main() {
|
|||||||
// So we flip it with `cell_size.y - glyph_offset.y`.
|
// So we flip it with `cell_size.y - glyph_offset.y`.
|
||||||
glyph_offset_calc.y = cell_size_scaled.y - glyph_offset_calc.y;
|
glyph_offset_calc.y = cell_size_scaled.y - glyph_offset_calc.y;
|
||||||
|
|
||||||
|
// If this is a constrained mode, we need to constrain it!
|
||||||
|
vec2 glyph_size_calc = glyph_size;
|
||||||
|
if (mode == MODE_FG_CONSTRAINED) {
|
||||||
|
if (glyph_size.x > cell_size_scaled.x) {
|
||||||
|
float new_y = glyph_size.y * (cell_size_scaled.x / glyph_size.x);
|
||||||
|
glyph_offset_calc.y = glyph_offset_calc.y + (glyph_size.y - new_y);
|
||||||
|
glyph_size_calc.y = new_y;
|
||||||
|
glyph_size_calc.x = cell_size_scaled.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the final position of the cell.
|
// Calculate the final position of the cell.
|
||||||
cell_pos = cell_pos + (glyph_size * position) + glyph_offset_calc;
|
cell_pos = cell_pos + (glyph_size_calc * position) + glyph_offset_calc;
|
||||||
gl_Position = projection * vec4(cell_pos, cell_z, 1.0);
|
gl_Position = projection * vec4(cell_pos, cell_z, 1.0);
|
||||||
|
|
||||||
// We need to convert our texture position and size to normalized
|
// We need to convert our texture position and size to normalized
|
||||||
|
Reference in New Issue
Block a user