fix(gui): eliminate row clipping at top of window
This commit is contained in:
parent
7fc2113b8a
commit
a9efe0ca4c
2 changed files with 8 additions and 6 deletions
|
|
@ -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 = .{
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue