gpu: taked slice child type in writeTexture
This commit is contained in:
parent
6922435110
commit
b5d10fb167
4 changed files with 10 additions and 7 deletions
|
|
@ -518,7 +518,7 @@ const Brick = struct {
|
||||||
|
|
||||||
fn texture(device: gpu.Device) Texture {
|
fn texture(device: gpu.Device) Texture {
|
||||||
const slice: []const u8 = &data();
|
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 {
|
fn data() [W * H * 4]u8 {
|
||||||
|
|
@ -589,7 +589,7 @@ const Texture = struct {
|
||||||
self.sampler.release();
|
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{
|
const extent = gpu.Extent3D{
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
|
|
@ -631,12 +631,13 @@ const Texture = struct {
|
||||||
&gpu.ImageCopyTexture{
|
&gpu.ImageCopyTexture{
|
||||||
.texture = texture,
|
.texture = texture,
|
||||||
},
|
},
|
||||||
data,
|
|
||||||
&gpu.Texture.DataLayout{
|
&gpu.Texture.DataLayout{
|
||||||
.bytes_per_row = 4 * width,
|
.bytes_per_row = 4 * width,
|
||||||
.rows_per_image = height,
|
.rows_per_image = height,
|
||||||
},
|
},
|
||||||
&extent,
|
&extent,
|
||||||
|
T,
|
||||||
|
data,
|
||||||
);
|
);
|
||||||
|
|
||||||
const bind_group_layout = Self.bindGroupLayout(device);
|
const bind_group_layout = Self.bindGroupLayout(device);
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,10 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
|
|
||||||
queue.writeTexture(
|
queue.writeTexture(
|
||||||
&.{ .texture = texture },
|
&.{ .texture = texture },
|
||||||
texture_atlas_data.data,
|
|
||||||
&data_layout,
|
&data_layout,
|
||||||
&.{ .width = texture_atlas_data.size, .height = texture_atlas_data.size },
|
&.{ .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);
|
app.vertices = try std.ArrayList(draw.Vertex).initCapacity(engine.allocator, 9);
|
||||||
|
|
|
||||||
|
|
@ -129,11 +129,11 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
|
||||||
.rows_per_image = @intCast(u32, img.height),
|
.rows_per_image = @intCast(u32, img.height),
|
||||||
};
|
};
|
||||||
switch (img.pixels.?) {
|
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| {
|
.Rgb24 => |pixels| {
|
||||||
const data = try rgb24ToRgba32(engine.allocator, pixels);
|
const data = try rgb24ToRgba32(engine.allocator, pixels);
|
||||||
//defer data.deinit(allocator);
|
//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"),
|
else => @panic("unsupported image color format"),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,10 @@ pub inline fn writeBuffer(queue: Queue, buffer: Buffer, buffer_offset: u64, comp
|
||||||
pub inline fn writeTexture(
|
pub inline fn writeTexture(
|
||||||
queue: Queue,
|
queue: Queue,
|
||||||
destination: *const ImageCopyTexture,
|
destination: *const ImageCopyTexture,
|
||||||
data: anytype,
|
|
||||||
data_layout: *const Texture.DataLayout,
|
data_layout: *const Texture.DataLayout,
|
||||||
write_size: *const Extent3D,
|
write_size: *const Extent3D,
|
||||||
|
comptime T: type,
|
||||||
|
data: []const T,
|
||||||
) void {
|
) void {
|
||||||
queue.vtable.writeTexture(
|
queue.vtable.writeTexture(
|
||||||
queue.ptr,
|
queue.ptr,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue