diff options
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 81 |
1 files changed, 12 insertions, 69 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 3dfafd68..98527842 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -673,16 +673,7 @@ fn fixedCellLayout(g: *const Gui) CellLayout { return .{ .w = @floatFromInt(g.cell_w), .h = @floatFromInt(g.cell_h), .x_off = 0, .y_off = 0 }; } -/// What one group draws, in this order: its cells, its images, then its -/// decor. -const Group = struct { - cell_start: u32 = 0, - cell_count: u32 = 0, - image_start: u32 = 0, - image_count: u32 = 0, - decor_start: u32 = 0, - decor_count: u32 = 0, -}; +const Group = Cells.Group; /// The frame's draw groups, bottom to top: the page and the panes, the /// notices floating over them, the guides and the debug box the core paints @@ -4065,14 +4056,14 @@ fn renderFrame( if (cursor) |value| _ = c.SDL_SetCursor(value); } g.words.memo = .{}; // positional, and this frame's cells are new - const cmd = c.SDL_AcquireGPUCommandBuffer(g.cells.device) orelse return false; + const cmd = g.cells.begin() orelse return false; var command_consumed = false; defer if (!command_consumed) { - _ = c.SDL_SubmitGPUCommandBuffer(cmd); + Cells.submit(cmd); }; const frame_target = try g.present.acquireTarget(cmd, g.window, @as(u32, surface.cols) * g.cell_w + g.capture_pad, @as(u32, surface.rows) * g.cell_h + g.capture_pad) orelse { command_consumed = true; - _ = c.SDL_SubmitGPUCommandBuffer(cmd); + Cells.submit(cmd); return false; }; const target = frame_target.texture; @@ -4132,16 +4123,12 @@ fn renderFrame( const page = chrome.page orelse bg_default; const background_opacity = backgroundOpacity(g.applied_window_opacity); - var color_target = std.mem.zeroes(c.SDL_GPUColorTargetInfo); - color_target.texture = target; - color_target.clear_color = .{ + const clear: c.SDL_FColor = .{ .r = @as(f32, @floatFromInt(page[0])) / 255.0 * background_opacity, .g = @as(f32, @floatFromInt(page[1])) / 255.0 * background_opacity, .b = @as(f32, @floatFromInt(page[2])) / 255.0 * background_opacity, .a = background_opacity, }; - color_target.load_op = c.SDL_GPU_LOADOP_CLEAR; - color_target.store_op = c.SDL_GPU_STOREOP_STORE; var shifted: u32 = 0; var row: u16 = 0; @@ -4180,14 +4167,11 @@ fn renderFrame( // The shifted rows of a scroll: its body, a glide's rows past it, and // a body layer's rows past the grid's. const capacity = std.math.add(u32, cell_total, 3 * cells + decor_len) catch return error.GpuCapacity; - try Cells.growInstances(g.cells.device, &g.cells.vbuf, &g.cells.vxfer, &g.cells.vbuf_cells, capacity, @sizeOf(CellInstance)); - - const vptr: [*]u8 = @ptrCast(c.SDL_MapGPUTransferBuffer(g.cells.device, g.cells.vxfer.?, false) orelse { + const instances = try g.cells.mapCells(capacity) orelse { command_consumed = true; - _ = c.SDL_SubmitGPUCommandBuffer(cmd); + Cells.submit(cmd); return false; - }); - const instances: [*]CellInstance = @ptrCast(@alignCast(vptr)); + }; const cursor_idx: u32 = if (surface.cursor) |cu| @as(u32, cu.y) * surface.cols + cu.x else cells; const cursor_bar = if (surface.cursor) |cu| cu.bar else false; row = 0; @@ -4238,56 +4222,15 @@ fn renderFrame( const held: u16 = if (scrolling) |id| if (core.panes[id]) |pane| pane.context_rows else 0 else 0; shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held); @memcpy(instances[cell_total + shifted ..][0..decor_len], g.decor.items); - c.SDL_UnmapGPUTransferBuffer(g.cells.device, g.cells.vxfer.?); - - if (g.atlas.atlas_dirty_top < g.atlas.atlas_dirty_bottom) g.cells.uploadAtlas(cmd, &g.atlas); - - const copy = c.SDL_BeginGPUCopyPass(cmd); - const src = c.SDL_GPUTransferBufferLocation{ .transfer_buffer = g.cells.vxfer.?, .offset = 0 }; - const dst = c.SDL_GPUBufferRegion{ .buffer = g.cells.vbuf.?, .offset = 0, .size = (cell_total + shifted + decor_len) * @sizeOf(CellInstance) }; - c.SDL_UploadToGPUBuffer(copy, &src, &dst, false); - c.SDL_EndGPUCopyPass(copy); + g.cells.uploadCells(cmd, cell_total + shifted + decor_len, &g.atlas); } build_zone.end(); building = false; if (frame_probe) |probe| probe.zone(.gui_build, probe_build); - const rp = c.SDL_BeginGPURenderPass(cmd, &color_target, 1, null); - Cells.pushLayerOpacity(cmd, rp, background_opacity); - const whole = c.SDL_Rect{ .x = 0, .y = 0, .w = @intCast(sw), .h = @intCast(sh) }; - const decor_base = cell_total + shifted; - for (groups.items[0..groups.len], 0..) |group, index| { - const has_shifted = index == 0 and shifted != 0; - if ((group.cell_count != 0 or has_shifted) and g.cells.vbuf != null) { - c.SDL_BindGPUGraphicsPipeline(rp, g.cells.pipeline); - const samp_binding = c.SDL_GPUTextureSamplerBinding{ .texture = g.cells.atlas_tex, .sampler = g.cells.atlas_sampler }; - c.SDL_BindGPUFragmentSamplers(rp, 0, &samp_binding, 1); - if (group.cell_count != 0) { - const binding = c.SDL_GPUBufferBinding{ .buffer = g.cells.vbuf.?, .offset = group.cell_start * @sizeOf(CellInstance) }; - c.SDL_BindGPUVertexBuffers(rp, 0, &binding, 1); - c.SDL_DrawGPUPrimitives(rp, 6, group.cell_count, 0, 0); - } - if (has_shifted) { - const clip = scrollScissor(g, layout, sw, sh); - c.SDL_SetGPUScissor(rp, &clip); - const binding = c.SDL_GPUBufferBinding{ .buffer = g.cells.vbuf.?, .offset = cell_total * @sizeOf(CellInstance) }; - c.SDL_BindGPUVertexBuffers(rp, 0, &binding, 1); - c.SDL_DrawGPUPrimitives(rp, 6, shifted, 0, 0); - c.SDL_SetGPUScissor(rp, &whole); - } - } - if (group.image_count != 0) g.cells.drawImages(rp, group.image_start, group.image_count, whole); - if (group.decor_count != 0 and g.cells.vbuf != null) { - c.SDL_BindGPUGraphicsPipeline(rp, g.cells.decor_pipeline); - // Ink keeps its colour at any WindowOpacity. - Cells.pushLayerOpacity(cmd, rp, if (index == groups.ink) 1 else background_opacity); - const binding = c.SDL_GPUBufferBinding{ .buffer = g.cells.vbuf.?, .offset = (decor_base + group.decor_start) * @sizeOf(CellInstance) }; - c.SDL_BindGPUVertexBuffers(rp, 0, &binding, 1); - c.SDL_DrawGPUPrimitives(rp, 6, group.decor_count, 0, 0); - } - } - g.cells.drawOverlay(cmd, rp, overlay_count, backgroundOpacity(g.applied_window_opacity)); - c.SDL_EndGPURenderPass(rp); + // Drawn only over a scroll's shifted rows (scrollScissor asks a scroll). + const scroll_clip = if (shifted != 0) scrollScissor(g, layout, sw, sh) else std.mem.zeroes(c.SDL_Rect); + g.cells.record(cmd, target, sw, sh, clear, background_opacity, groups.items[0..groups.len], groups.ink, cell_total, shifted, scroll_clip, overlay_count); command_consumed = true; return finishFrame(g, gpa, cmd, frame_target); |
