From 409c1accefeb7a775c0914c888b469a1e78fc69a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 13 Nov 2026 12:12:22 -0300 Subject: Add reusable GPU backdrop filtering to the shared canvas Draw native GPU frames through the same bounded canvas used by headless capture. Backdrop commands reuse one snapshot and shader state, with an unchanged fallback on unsupported renderers. Verified through native debugger lenses, restart, and repeated font zoom checks. --- src/host/Host.zig | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/host/Host.zig') diff --git a/src/host/Host.zig b/src/host/Host.zig index 86e1873..43f030a 100644 --- a/src/host/Host.zig +++ b/src/host/Host.zig @@ -49,8 +49,7 @@ renderer: *c.SDL_Renderer, /// Null when the machine has no usable GPU driver. gpu: ?*c.SDL_GPUDevice, passes: ?Gpu = null, -/// Headless with a GPU: the renderer has no window and draws into this -/// canvas-sized texture, which screenshots read. +/// GPU canvas, shared by native/headless drawing, backdrop filters and screenshots. offscreen: ?*c.SDL_Texture = null, pointer_cursor: ?*c.SDL_Cursor = null, images: gfx.Images, @@ -350,6 +349,7 @@ fn draw(self: *Host, now: u64) !void { const ctx = self.context(); self.sketch.draw(&ctx, self.live().ptr); + _ = c.SDL_SetRenderTarget(self.renderer, self.offscreen); _ = c.SDL_SetRenderClipRect(self.renderer, null); _ = c.SDL_SetRenderDrawColor(self.renderer, 0, 0, 0, 255); _ = c.SDL_RenderClear(self.renderer); @@ -399,6 +399,11 @@ fn draw(self: *Host, now: u64) !void { } if (self.options.export_to) |to| try self.exportFrame(surface, to); } + if (!self.options.headless) if (self.offscreen) |canvas| { + _ = c.SDL_SetRenderTarget(self.renderer, null); + _ = c.SDL_SetTextureBlendMode(canvas, c.SDL_BLENDMODE_NONE); + _ = c.SDL_RenderTexture(self.renderer, canvas, null, null); + }; _ = c.SDL_RenderPresent(self.renderer); if (self.passes) |*g| g.endFrame(); } @@ -640,12 +645,12 @@ fn forget(list: anytype, handle: anytype) void { fn setCanvas(self: *Host, w: u32, h: u32) void { if (w == 0 or h == 0 or (self.canvas[0] == w and self.canvas[1] == h)) return; self.canvas = .{ w, h }; - if (self.options.headless and self.gpu != null) { + _ = c.SDL_SetRenderTarget(self.renderer, null); + _ = c.SDL_SetRenderLogicalPresentation(self.renderer, @intCast(w), @intCast(h), c.SDL_LOGICAL_PRESENTATION_LETTERBOX); + if (self.gpu != null) { if (self.offscreen) |texture| c.SDL_DestroyTexture(texture); self.offscreen = c.SDL_CreateTexture(self.renderer, c.SDL_PIXELFORMAT_RGBA32, c.SDL_TEXTUREACCESS_TARGET, @intCast(w), @intCast(h)); _ = c.SDL_SetRenderTarget(self.renderer, self.offscreen); - } else { - _ = c.SDL_SetRenderLogicalPresentation(self.renderer, @intCast(w), @intCast(h), c.SDL_LOGICAL_PRESENTATION_LETTERBOX); } _ = c.SDL_SetWindowSize(self.window, @intCast(w), @intCast(h)); } -- cgit v1.3