Update to zig 0.16.0, update deps, Vulkan validation fixes
This commit is contained in:
@@ -172,12 +172,19 @@ pub fn getAtom(self: *const Textures, filename: Atom, usage: Texture.Usage) ?Id
|
||||
/// if necessary. Will not return any error if the texture already exists. When
|
||||
/// the filename is `null`, returns an empty texture ID appropriate for given
|
||||
/// usage.
|
||||
pub fn getOrLoad(self: *Textures, engine: *Engine, stbi: *media.stbi, maybe_filename: ?[]const u8, usage: Texture.Usage) !Id {
|
||||
pub fn getOrLoad(
|
||||
self: *Textures,
|
||||
engine: *Engine,
|
||||
stbi: *media.stbi,
|
||||
maybe_filename: ?[]const u8,
|
||||
usage: Texture.Usage,
|
||||
io: std.Io,
|
||||
) !Id {
|
||||
if (maybe_filename) |filename| {
|
||||
const key: Key = .{
|
||||
// If the texture already exists, then the atom must exist and the
|
||||
// following line will not return any error.
|
||||
.filename = try .fromString(filename),
|
||||
.filename = try .fromString(filename, io),
|
||||
.usage = usage,
|
||||
};
|
||||
|
||||
@@ -190,7 +197,7 @@ pub fn getOrLoad(self: *Textures, engine: *Engine, stbi: *media.stbi, maybe_file
|
||||
const id = Id.fromIndexSafe(self.array.items.len) catch |err| switch (err) {
|
||||
error.Overflow => return error.OutOfTextures,
|
||||
};
|
||||
const texture = try loadTexture(engine, stbi, filename, usage);
|
||||
const texture = try loadTexture(engine, stbi, filename, usage, io);
|
||||
|
||||
self.map.putAssumeCapacityNoClobber(key, id);
|
||||
self.array.appendAssumeCapacity(texture);
|
||||
@@ -207,7 +214,14 @@ pub fn getOrLoad(self: *Textures, engine: *Engine, stbi: *media.stbi, maybe_file
|
||||
/// if necessary. Will not return any error if the texture already exists. When
|
||||
/// the filename is `.empty`, returns an empty texture ID appropriate for given
|
||||
/// usage.
|
||||
pub fn getOrLoadAtom(self: *Textures, engine: *Engine, stbi: *media.stbi, filename: Atom, usage: Texture.Usage) !Id {
|
||||
pub fn getOrLoadAtom(
|
||||
self: *Textures,
|
||||
engine: *Engine,
|
||||
stbi: *media.stbi,
|
||||
filename: Atom,
|
||||
usage: Texture.Usage,
|
||||
io: std.Io,
|
||||
) !Id {
|
||||
if (filename != .empty) {
|
||||
const key: Key = .{
|
||||
.filename = filename,
|
||||
@@ -223,7 +237,7 @@ pub fn getOrLoadAtom(self: *Textures, engine: *Engine, stbi: *media.stbi, filena
|
||||
const id = Id.fromIndexSafe(self.array.items.len) catch |err| switch (err) {
|
||||
error.Overflow => return error.OutOfTextures,
|
||||
};
|
||||
const texture = try loadTexture(engine, stbi, filename.toString(), usage);
|
||||
const texture = try loadTexture(engine, stbi, filename.toString(), usage, io);
|
||||
|
||||
self.map.putAssumeCapacityNoClobber(key, id);
|
||||
self.array.appendAssumeCapacity(texture);
|
||||
@@ -235,21 +249,27 @@ pub fn getOrLoadAtom(self: *Textures, engine: *Engine, stbi: *media.stbi, filena
|
||||
}
|
||||
}
|
||||
|
||||
fn loadTexture(engine: *Engine, stbi: *media.stbi, filename: []const u8, usage: Texture.Usage) !Texture {
|
||||
fn loadTexture(
|
||||
engine: *Engine,
|
||||
stbi: *media.stbi,
|
||||
filename: []const u8,
|
||||
usage: Texture.Usage,
|
||||
io: std.Io,
|
||||
) !Texture {
|
||||
std.log.debug("Loading texture \"{s}\" as {s}...", .{ filename, @tagName(usage) });
|
||||
|
||||
const cwd = std.fs.cwd();
|
||||
const cwd = std.Io.Dir.cwd();
|
||||
|
||||
var dir = try cwd.openDir("assets/textures", .{});
|
||||
defer dir.close();
|
||||
var dir = try cwd.openDir(io, "assets/textures", .{});
|
||||
defer dir.close(io);
|
||||
|
||||
var file = try dir.openFile(filename, .{});
|
||||
defer file.close();
|
||||
var file = try dir.openFile(io, filename, .{});
|
||||
defer file.close(io);
|
||||
|
||||
// The textures are expected to be small; a standard block base color as a
|
||||
// PNG takes well below 1 kiB.
|
||||
var buf: [4096]u8 = undefined;
|
||||
var reader = file.reader(&buf);
|
||||
var reader = file.reader(io, &buf);
|
||||
|
||||
const img = try stbi.loadDynamicIo(&reader.interface);
|
||||
defer stbi.freeDynamic(img);
|
||||
|
||||
Reference in New Issue
Block a user