From a9efe0ca4c26b675c587224e4a23eea2f9372f6d Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Mon, 30 Mar 2026 20:13:10 +0200 Subject: [PATCH] fix(gui): eliminate row clipping at top of window --- src/gui/gpu/builtin.glsl.zig | 7 ++++--- src/gui/gpu/gpu.zig | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gui/gpu/builtin.glsl.zig b/src/gui/gpu/builtin.glsl.zig index 61a58294..88fb7501 100644 --- a/src/gui/gpu/builtin.glsl.zig +++ b/src/gui/gpu/builtin.glsl.zig @@ -14,6 +14,7 @@ pub const FsParams = extern struct { cell_size_y: i32, col_count: i32, row_count: i32, + viewport_height: i32, }; const vs_src = @@ -32,6 +33,7 @@ const fs_src = \\uniform int cell_size_y; \\uniform int col_count; \\uniform int row_count; + \\uniform int viewport_height; \\uniform sampler2D glyph_tex_glyph_smp; \\uniform usampler2D cell_tex_cell_smp; \\out vec4 frag_color; @@ -47,10 +49,8 @@ const fs_src = \\ \\void main() { \\ // Convert gl_FragCoord (bottom-left origin) to top-left origin. - \\ // row_count * cell_size_y >= viewport height (we ceil the division), - \\ // so this formula maps the top screen pixel to row 0. \\ int px = int(gl_FragCoord.x); - \\ int py = row_count * cell_size_y - 1 - int(gl_FragCoord.y); + \\ int py = viewport_height - 1 - int(gl_FragCoord.y); \\ int col = px / cell_size_x; \\ int row = py / cell_size_y; \\ @@ -99,6 +99,7 @@ pub fn shaderDesc(backend: sg.Backend) sg.ShaderDesc { desc.uniform_blocks[0].glsl_uniforms[1] = .{ .type = .INT, .glsl_name = "cell_size_y" }; desc.uniform_blocks[0].glsl_uniforms[2] = .{ .type = .INT, .glsl_name = "col_count" }; desc.uniform_blocks[0].glsl_uniforms[3] = .{ .type = .INT, .glsl_name = "row_count" }; + desc.uniform_blocks[0].glsl_uniforms[4] = .{ .type = .INT, .glsl_name = "viewport_height" }; // Glyph atlas texture: R8 → sample_type = FLOAT desc.views[0].texture = .{ diff --git a/src/gui/gpu/gpu.zig b/src/gui/gpu/gpu.zig index 40816fea..b1965e0a 100644 --- a/src/gui/gpu/gpu.zig +++ b/src/gui/gpu/gpu.zig @@ -20,7 +20,7 @@ const Rgba8 = gui_cell.Rgba8; const log = std.log.scoped(.gpu); // Maximum glyph atlas dimension. 4096 is universally supported and gives -// 65536+ glyph slots at typical cell sizes — far more than needed in practice. +// 65536+ glyph slots at typical cell sizes - far more than needed in practice. const max_atlas_dim: u16 = 4096; fn getAtlasCellCount(cell_size: XY(u16)) XY(u16) { @@ -339,8 +339,8 @@ pub fn paint( top: u16, cells: []const Cell, ) void { - const shader_col_count: u16 = @intCast(@divTrunc(client_size.x + font.cell_size.x - 1, font.cell_size.x)); - const shader_row_count: u16 = @intCast(@divTrunc(client_size.y + font.cell_size.y - 1, font.cell_size.y)); + const shader_col_count: u16 = @intCast(@divTrunc(client_size.x, font.cell_size.x)); + const shader_row_count: u16 = @intCast(@divTrunc(client_size.y, font.cell_size.y)); const copy_col_count: u16 = @min(col_count, shader_col_count); const blank_glyph_index = state.generateGlyph(font, ' ', .single); @@ -422,6 +422,7 @@ pub fn paint( .cell_size_y = font.cell_size.y, .col_count = shader_col_count, .row_count = shader_row_count, + .viewport_height = @intCast(client_size.y), }; sg.applyUniforms(0, .{ .ptr = &fs_params,