diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-13 12:12:22 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-13 12:12:22 -0300 |
| commit | 409c1accefeb7a775c0914c888b469a1e78fc69a (patch) | |
| tree | 21af5f4b0e82e5c36d129421a7257be6d8bebd8d /src/host/Host.zig | |
| parent | 91a34124880d932f97718b959b11bc5375c0dd79 (diff) | |
| download | sketchbook-409c1accefeb7a775c0914c888b469a1e78fc69a.tar.gz sketchbook-409c1accefeb7a775c0914c888b469a1e78fc69a.zip | |
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.
Diffstat (limited to 'src/host/Host.zig')
| -rw-r--r-- | src/host/Host.zig | 15 |
1 files changed, 10 insertions, 5 deletions
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)); } |
