examples: Load all images from Memory (using embedFile) instead of File

This commit is contained in:
iddev5 2022-05-27 13:20:26 +05:30 committed by Stephen Gutekanst
parent ed0d9c100f
commit b5737af9cd
3 changed files with 4 additions and 4 deletions

View file

@ -37,8 +37,8 @@ pub fn build(b: *std.build.Builder) void {
.{ .name = "instanced-cube", .packages = &[_]Pkg{Packages.zmath} }, .{ .name = "instanced-cube", .packages = &[_]Pkg{Packages.zmath} },
.{ .name = "advanced-gen-texture-light", .packages = &[_]Pkg{Packages.zmath} }, .{ .name = "advanced-gen-texture-light", .packages = &[_]Pkg{Packages.zmath} },
.{ .name = "fractal-cube", .packages = &[_]Pkg{Packages.zmath} }, .{ .name = "fractal-cube", .packages = &[_]Pkg{Packages.zmath} },
.{ .name = "gkurve", .packages = &[_]Pkg{ Packages.zmath, Packages.zigimg }, .std_platform_only = true }, .{ .name = "gkurve", .packages = &[_]Pkg{ Packages.zmath, Packages.zigimg } },
.{ .name = "textured-cube", .packages = &[_]Pkg{ Packages.zmath, Packages.zigimg }, .std_platform_only = true }, .{ .name = "textured-cube", .packages = &[_]Pkg{ Packages.zmath, Packages.zigimg } },
}) |example| { }) |example| {
// FIXME: this is workaround for a problem that some examples (having the std_platform_only=true field) as // FIXME: this is workaround for a problem that some examples (having the std_platform_only=true field) as
// well as zigimg uses IO which is not supported in freestanding environments. So break out of this loop // well as zigimg uses IO which is not supported in freestanding environments. So break out of this loop

View file

@ -53,7 +53,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.rows_per_image = @intCast(u32, atlas_size.height), .rows_per_image = @intCast(u32, atlas_size.height),
}; };
const img = try zigimg.Image.fromFilePath(engine.allocator, "examples/assets/gotta-go-fast.png"); const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png"));
defer img.deinit(); defer img.deinit();
const atlas_img_region = try texture_atlas_data.reserve(engine.allocator, @truncate(u32, img.width), @truncate(u32, img.height)); const atlas_img_region = try texture_atlas_data.reserve(engine.allocator, @truncate(u32, img.width), @truncate(u32, img.height));

View file

@ -113,7 +113,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.min_filter = .linear, .min_filter = .linear,
}); });
const queue = engine.gpu_driver.device.getQueue(); const queue = engine.gpu_driver.device.getQueue();
const img = try zigimg.Image.fromFilePath(engine.allocator, "examples/assets/gotta-go-fast.png"); const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png"));
const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) }; const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) };
const cube_texture = engine.gpu_driver.device.createTexture(&.{ const cube_texture = engine.gpu_driver.device.createTexture(&.{
.size = img_size, .size = img_size,