I've got some vertex data I want to upload to the GPU(using SDL3 gpu api).
const vertices: []const Vertex = &[_]Vertex{
.{ .pos = .{ -1, -1 }, .color = .{ 1, 0, 0, 1 } },
.{ .pos = .{ 0, 1 }, .color = .{ 0, 1, 0, 1 } },
.{ .pos = .{ 1, -1 }, .color = .{ 0, 0, 1, 1 } },
};
try vert_buf.upload(queue, @ptrCast(vertices));
Here's the upload function
pub fn upload(self: Self, queue: *TransferQueue, data: []anyopaque) !void {
try queue.stage(.{
.data = data,
.location = .{ .buf = self.ptr },
});
}
And here's the item struct that is being passed to queue.stage()
const Item = struct {
data: []anyopaque,
location: union(enum) {
buf: *sdl.SDL_GPUBuffer,
},
};
But I get this TODO msg when I @ptrCast the slices
src/root.zig:196:32: error: TODO: implement @ptrCast between slices changing the length
try vert_buf.upload(queue, @ptrCast(vertices));
I tried std.mem.sliceAsBytes, but I get an error about type conversion
src/root.zig:196:52: error: expected type '[]anyopaque', found '[]align(4) const u8'
try vert_buf.upload(queue, std.mem.sliceAsBytes(vertices));
Any help with how to cast arbitrary slice data to []anyopaque?
Is there different way I should queue arbitrary data for GPU upload?