diff options
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)); } |
