summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig48
1 files changed, 13 insertions, 35 deletions
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;