diff --git a/examples/advanced-gen-texture-light/main.zig b/examples/advanced-gen-texture-light/main.zig index 01aba51c..32d6661f 100755 --- a/examples/advanced-gen-texture-light/main.zig +++ b/examples/advanced-gen-texture-light/main.zig @@ -518,7 +518,7 @@ const Brick = struct { fn texture(device: gpu.Device) Texture { const slice: []const u8 = &data(); - return Texture.fromData(device, W, H, slice); + return Texture.fromData(device, W, H, u8, slice); } fn data() [W * H * 4]u8 { @@ -589,7 +589,7 @@ const Texture = struct { self.sampler.release(); } - fn fromData(device: gpu.Device, width: u32, height: u32, data: anytype) Self { + fn fromData(device: gpu.Device, width: u32, height: u32, comptime T: type, data: []const T) Self { const extent = gpu.Extent3D{ .width = width, .height = height, @@ -631,12 +631,13 @@ const Texture = struct { &gpu.ImageCopyTexture{ .texture = texture, }, - data, &gpu.Texture.DataLayout{ .bytes_per_row = 4 * width, .rows_per_image = height, }, &extent, + T, + data, ); const bind_group_layout = Self.bindGroupLayout(device); diff --git a/examples/gkurve/main.zig b/examples/gkurve/main.zig index 4d2cd5cc..0803808b 100644 --- a/examples/gkurve/main.zig +++ b/examples/gkurve/main.zig @@ -78,9 +78,10 @@ pub fn init(app: *App, engine: *mach.Engine) !void { queue.writeTexture( &.{ .texture = texture }, - texture_atlas_data.data, &data_layout, &.{ .width = texture_atlas_data.size, .height = texture_atlas_data.size }, + zigimg.color.Rgba32, + texture_atlas_data.data, ); app.vertices = try std.ArrayList(draw.Vertex).initCapacity(engine.allocator, 9); diff --git a/examples/textured-cube/main.zig b/examples/textured-cube/main.zig index 4f4ccf66..fe12f746 100644 --- a/examples/textured-cube/main.zig +++ b/examples/textured-cube/main.zig @@ -129,11 +129,11 @@ pub fn init(app: *App, engine: *mach.Engine) !void { .rows_per_image = @intCast(u32, img.height), }; switch (img.pixels.?) { - .Rgba32 => |pixels| queue.writeTexture(&.{ .texture = cube_texture }, pixels, &data_layout, &img_size), + .Rgba32 => |pixels| queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, pixels), .Rgb24 => |pixels| { const data = try rgb24ToRgba32(engine.allocator, pixels); //defer data.deinit(allocator); - queue.writeTexture(&.{ .texture = cube_texture }, data.Rgba32, &data_layout, &img_size); + queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, data.Rgba32); }, else => @panic("unsupported image color format"), } diff --git a/gpu/src/Queue.zig b/gpu/src/Queue.zig index aba981f4..53f29598 100644 --- a/gpu/src/Queue.zig +++ b/gpu/src/Queue.zig @@ -63,9 +63,10 @@ pub inline fn writeBuffer(queue: Queue, buffer: Buffer, buffer_offset: u64, comp pub inline fn writeTexture( queue: Queue, destination: *const ImageCopyTexture, - data: anytype, data_layout: *const Texture.DataLayout, write_size: *const Extent3D, + comptime T: type, + data: []const T, ) void { queue.vtable.writeTexture( queue.ptr,