diff options
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/Post.zig | 22 | ||||
| -rw-r--r-- | src/gui/gui.zig | 48 |
2 files changed, 15 insertions, 55 deletions
diff --git a/src/gui/Post.zig b/src/gui/Post.zig index c0b71d97..64a431b9 100644 --- a/src/gui/Post.zig +++ b/src/gui/Post.zig @@ -383,16 +383,7 @@ pub fn draw(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffer, if (live > 1 and (post.ping[0] == null or post.ping_w != w or post.ping_h != h)) { for (&post.ping) |*texture| { if (texture.*) |old| c.SDL_ReleaseGPUTexture(device, old); - var info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); - info.type = c.SDL_GPU_TEXTURETYPE_2D; - info.format = format; - info.usage = c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER; - info.width = w; - info.height = h; - info.layer_count_or_depth = 1; - info.num_levels = 1; - info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - texture.* = c.SDL_CreateGPUTexture(device, &info) orelse return error.GpuCreate; + texture.* = gui.texture2d(device, format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, w, h) orelse return error.GpuCreate; } post.ping_w = w; post.ping_h = h; @@ -482,16 +473,7 @@ fn bloomChain(post: *Post, device: *c.SDL_GPUDevice, cmd: *c.SDL_GPUCommandBuffe if (post.bloom_tex[0] == null or post.bloom_w != w or post.bloom_h != h) { for (&post.bloom_tex, 0..) |*texture, i| { if (texture.*) |old| c.SDL_ReleaseGPUTexture(device, old); - var info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); - info.type = c.SDL_GPU_TEXTURETYPE_2D; - info.format = bloom_format; - info.usage = c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER; - info.width = @max(1, w >> @intCast(i + 1)); - info.height = @max(1, h >> @intCast(i + 1)); - info.layer_count_or_depth = 1; - info.num_levels = 1; - info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - texture.* = c.SDL_CreateGPUTexture(device, &info) orelse return error.GpuCreate; + texture.* = gui.texture2d(device, bloom_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, @max(1, w >> @intCast(i + 1)), @max(1, h >> @intCast(i + 1))) orelse return error.GpuCreate; } post.bloom_w = w; post.bloom_h = h; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 4c0c0c37..71635cb2 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2137,16 +2137,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di _ = c.SDL_SyncWindow(window); } - var tex_info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); - tex_info.type = c.SDL_GPU_TEXTURETYPE_2D; - tex_info.format = c.SDL_GPU_TEXTUREFORMAT_R8_UNORM; - tex_info.usage = c.SDL_GPU_TEXTUREUSAGE_SAMPLER; - tex_info.width = atlas_w; - tex_info.height = atlas_h; - tex_info.layer_count_or_depth = 1; - tex_info.num_levels = 1; - tex_info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - const atlas_tex = c.SDL_CreateGPUTexture(device, &tex_info) orelse return error.GpuCreate; + const atlas_tex = texture2d(device, c.SDL_GPU_TEXTUREFORMAT_R8_UNORM, c.SDL_GPU_TEXTUREUSAGE_SAMPLER, atlas_w, atlas_h) orelse return error.GpuCreate; var samp_info = std.mem.zeroes(c.SDL_GPUSamplerCreateInfo); samp_info.min_filter = c.SDL_GPU_FILTER_NEAREST; @@ -6166,16 +6157,7 @@ fn uploadNativeTexture( return; }; - var tex_info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); - tex_info.type = c.SDL_GPU_TEXTURETYPE_2D; - tex_info.format = c.SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM; - tex_info.usage = c.SDL_GPU_TEXTUREUSAGE_SAMPLER; - tex_info.width = @intCast(place.iw); - tex_info.height = @intCast(place.ih); - tex_info.layer_count_or_depth = 1; - tex_info.num_levels = 1; - tex_info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - const texture = c.SDL_CreateGPUTexture(g.device, &tex_info) orelse return error.GpuCreate; + const texture = texture2d(g.device, c.SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, c.SDL_GPU_TEXTUREUSAGE_SAMPLER, @intCast(place.iw), @intCast(place.ih)) orelse return error.GpuCreate; errdefer c.SDL_ReleaseGPUTexture(g.device, texture); try uploadTextureRows(g, cmd, texture, place.rgba[0..byte_len], place.iw, 0, place.ih); try g.native_images.put(gpa, key, texture); @@ -8789,18 +8771,23 @@ fn makeShader(device: *c.SDL_GPUDevice, code: []const u8, stage: c.SDL_GPUShader return c.SDL_CreateGPUShader(device, &info) orelse error.GpuCreate; } -fn ensureSceneTexture(g: *Gui, width: u32, height: u32) !void { - if (g.scene_tex != null and g.scene_tex_w == width and g.scene_tex_h == height) return; +/// A 2D texture of one level, one layer and one sample. +pub fn texture2d(device: *c.SDL_GPUDevice, format: c.SDL_GPUTextureFormat, usage: c.SDL_GPUTextureUsageFlags, width: u32, height: u32) ?*c.SDL_GPUTexture { var info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); info.type = c.SDL_GPU_TEXTURETYPE_2D; - info.format = g.swapchain_format; - info.usage = c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER; + info.format = format; + info.usage = usage; info.width = width; info.height = height; info.layer_count_or_depth = 1; info.num_levels = 1; info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - const next = c.SDL_CreateGPUTexture(g.device, &info) orelse return error.GpuCreate; + return c.SDL_CreateGPUTexture(device, &info); +} + +fn ensureSceneTexture(g: *Gui, width: u32, height: u32) !void { + if (g.scene_tex != null and g.scene_tex_w == width and g.scene_tex_h == height) return; + const next = texture2d(g.device, g.swapchain_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | c.SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height) orelse return error.GpuCreate; if (g.scene_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture); g.scene_tex = next; g.scene_tex_w = width; @@ -8809,16 +8796,7 @@ fn ensureSceneTexture(g: *Gui, width: u32, height: u32) !void { fn ensureCaptureTexture(g: *Gui, width: u32, height: u32) !void { if (g.capture_tex != null and g.capture_tex_w == width and g.capture_tex_h == height) return; - var info = std.mem.zeroes(c.SDL_GPUTextureCreateInfo); - info.type = c.SDL_GPU_TEXTURETYPE_2D; - info.format = g.swapchain_format; - info.usage = c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET; - info.width = width; - info.height = height; - info.layer_count_or_depth = 1; - info.num_levels = 1; - info.sample_count = c.SDL_GPU_SAMPLECOUNT_1; - const next = c.SDL_CreateGPUTexture(g.device, &info) orelse return error.GpuCreate; + const next = texture2d(g.device, g.swapchain_format, c.SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, width, height) orelse return error.GpuCreate; if (g.capture_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture); g.capture_tex = next; g.capture_tex_w = width; |
