render-zig

A 3D rendering engine written in Zig
git clone git://git.christianermann.dev/render-zig
Log | Files | Refs

commit 8c123b66956a53e705b9cc050751d0850a69ffd4
parent 9c9f54c06951604f8b7821a082693fb9a2e00a8d
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sat, 18 May 2024 20:42:31 -0400

Simplify cube map texture loading

Diffstat:
Msrc/cubemap.zig | 39++++++++++-----------------------------
1 file changed, 10 insertions(+), 29 deletions(-)

diff --git a/src/cubemap.zig b/src/cubemap.zig @@ -59,43 +59,24 @@ pub fn init(paths: CubeMapPaths, allocator: std.mem.Allocator, app: *App) !CubeM .rows_per_image = @as(u32, @intCast(images[0].height)), }; - const encoder = app.device.createCommandEncoder(null); - - var staging_buf: [6]*gpu.Buffer = undefined; for (0..6) |i| { - staging_buf[i] = app.device.createBuffer(&.{ - .usage = .{ .copy_src = true, .map_write = true }, - .size = @as(u64, @intCast(images[0].width)) * @as(u64, @intCast(images[0].height)) * @sizeOf(u32), - .mapped_at_creation = .true, - }); + const destination = gpu.ImageCopyTexture{ + .texture = texture, + .origin = gpu.Origin3D{ .x = 0, .y = 0, .z = @as(u32, @intCast(i)) }, + }; switch (images[i].pixels) { .rgba32 => |pixels| { - const staging_map = staging_buf[i].getMappedRange(u32, 0, @as(u64, @intCast(images[0].width)) * @as(u64, @intCast(images[0].height))); - @memcpy(staging_map.?, @as([]u32, @ptrCast(@alignCast(pixels)))); - staging_buf[i].unmap(); + app.queue.writeTexture( + &destination, + &data_layout, + &img_size, + pixels, + ); }, else => @panic("unsupported image color format"), } - - const copy_buf = gpu.ImageCopyBuffer{ - .layout = data_layout, - .buffer = staging_buf[i], - }; - const copy_tex = gpu.ImageCopyTexture{ - .texture = texture, - .origin = gpu.Origin3D{ .x = 0, .y = 0, .z = @as(u32, @intCast(i)) }, - }; - - encoder.copyBufferToTexture(&copy_buf, &copy_tex, &img_size); - staging_buf[i].release(); } - var command = encoder.finish(null); - encoder.release(); - - app.queue.submit(&[_]*gpu.CommandBuffer{command}); - command.release(); - const view = texture.createView( &gpu.TextureView.Descriptor{ .dimension = .dimension_cube }, );