diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-16 18:04:21 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-16 18:04:21 -0300 |
| commit | e77b01d4b5504cea08a3f88cf8502897d868a1d3 (patch) | |
| tree | c8e643d234dd26d920cbc563bfa7f740febf1fc7 /src/host/gfx.zig | |
| parent | d3074636fff0fbcd5fd9b71c0c3b1c1f5c0c1285 (diff) | |
| download | sketchbook-e77b01d4b5504cea08a3f88cf8502897d868a1d3.tar.gz sketchbook-e77b01d4b5504cea08a3f88cf8502897d868a1d3.zip | |
Add glTF scene rendering, resource setup and 9P controls
Diffstat (limited to 'src/host/gfx.zig')
| -rw-r--r-- | src/host/gfx.zig | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/host/gfx.zig b/src/host/gfx.zig index a7ebd05..fef58c3 100644 --- a/src/host/gfx.zig +++ b/src/host/gfx.zig @@ -12,6 +12,7 @@ pub const Images = struct { const Entry = struct { texture: ?*c.SDL_Texture = null, + gpu_texture: ?*anyopaque = null, w: u32 = 0, h: u32 = 0, /// Holds premultiplied colour: a target drawn into, a GPU pass's @@ -79,6 +80,7 @@ pub const Images = struct { /// Makes `image` show a GPU render target (GPU renderer only). pub fn wrap(self: *Images, image: abi.Image, gpu_texture: *anyopaque, w: u32, h: u32) !void { const entry = self.get(image) orelse return error.UnknownImage; + if (entry.gpu_texture == gpu_texture) return; const props = c.SDL_CreateProperties(); defer c.SDL_DestroyProperties(props); _ = c.SDL_SetPointerProperty(props, c.SDL_PROP_TEXTURE_CREATE_GPU_TEXTURE_POINTER, gpu_texture); @@ -89,7 +91,7 @@ pub const Images = struct { // Rendered output: smooth scaling, and already premultiplied. _ = c.SDL_SetTextureScaleMode(texture, c.SDL_SCALEMODE_LINEAR); entry.release(); - entry.* = .{ .texture = texture, .w = w, .h = h, .premultiplied = true, .smooth = true }; + entry.* = .{ .texture = texture, .w = w, .h = h, .premultiplied = true, .smooth = true, .gpu_texture = gpu_texture }; } /// Stops showing a wrapped render target, before the target goes away. @@ -97,6 +99,7 @@ pub const Images = struct { const entry = self.get(image) orelse return; if (entry.texture) |t| c.SDL_DestroyTexture(t); entry.texture = null; + entry.gpu_texture = null; } pub fn free(self: *Images, image: abi.Image) void { @@ -591,7 +594,7 @@ fn fcolor(color: abi.Color) c.SDL_FColor { /// Native shaped text on Linux, using a 13px monospace face at scale 1. /// Other targets retain SDL's built-in 8x8 fallback. Coordinates are line-box tops. pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: []const u8, color: abi.Color, face: abi.Face, raster: f32) void { - if (@import("builtin").os.tag == .linux and c.sk_text_draw_scaled(renderer, @intFromEnum(face), x, y, scale, raster, bytes.ptr, bytes.len, color.r, color.g, color.b, color.a)) return; + if (@import("builtin").os.tag == .linux and c.sk_text_draw_scaled(renderer, @backingInt(face), x, y, scale, raster, bytes.ptr, bytes.len, color.r, color.g, color.b, color.a)) return; var buf: [1024]u8 = undefined; const len = @min(std.mem.indexOfScalar(u8, bytes, 0) orelse bytes.len, buf.len - 1); @memcpy(buf[0..len], bytes[0..len]); @@ -623,7 +626,7 @@ pub fn drawText(renderer: *c.SDL_Renderer, x: f32, y: f32, scale: f32, bytes: [] /// its line, in canvas units (`Host.textSize`). pub fn textSize(renderer: *c.SDL_Renderer, scale: f32, bytes: []const u8, face: abi.Face) [2]f32 { var size: [2]f32 = .{ 0, 0 }; - if (@import("builtin").os.tag == .linux and c.sk_text_measure_face(renderer, @intFromEnum(face), scale, bytes.ptr, bytes.len, &size[0], &size[1])) return size; + if (@import("builtin").os.tag == .linux and c.sk_text_measure_face(renderer, @backingInt(face), scale, bytes.ptr, bytes.len, &size[0], &size[1])) return size; // The debug font's 8 px cells. const s = @max(scale, 1); return .{ @as(f32, @floatFromInt(bytes.len)) * 8 * s, 8 * s }; |
