setup our GPU cells based on terminal state

This commit is contained in:
Mitchell Hashimoto
2022-04-18 16:21:22 -07:00
parent 2e46612bc7
commit 34cb9b2c27
2 changed files with 26 additions and 5 deletions

View File

@ -168,8 +168,29 @@ pub fn demoCells(self: *Grid) !void {
/// updateCells updates our GPU cells from the current terminal view.
/// The updated cells will take effect on the next render.
pub fn updateCells(self: *Grid, term: Terminal) !void {
_ = self;
_ = term;
// For now, we just ensure that we have enough cells for all the lines
// we have plus a full width. This is very likely too much but its
// the probably close enough while guaranteeing no more allocations.
self.cells.clearRetainingCapacity();
try self.cells.ensureTotalCapacity(
self.alloc,
term.screen.items.len * term.cols,
);
for (term.screen.items) |line, y| {
for (line.items) |cell, x| {
_ = cell;
self.cells.appendAssumeCapacity(.{
.grid_col = @intCast(u16, x),
.grid_row = @intCast(u16, y),
.bg_r = @intCast(u8, @mod(x * y, 255)),
.bg_g = @intCast(u8, @mod(x, 255)),
.bg_b = @intCast(u8, 255 - @mod(x, 255)),
.bg_a = 255,
});
}
}
}
/// Set the screen size for rendering. This will update the projection

View File

@ -141,12 +141,12 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
.height = @intCast(u32, height),
}) catch |err| log.err("error updating grid screen size err={}", .{err});
// TODO: temp
win.grid.demoCells() catch unreachable;
// Update the size of our terminal state
win.terminal.resize(win.grid.size.columns, win.grid.size.rows);
// TODO: this is not the right place for this
win.grid.updateCells(win.terminal) catch unreachable;
// Update the size of our pty
win.pty.setSize(.{
.ws_row = @intCast(u16, win.grid.size.rows),