Use castle's stbi instead of zstbi

This commit is contained in:
2026-02-06 23:27:21 +01:00
parent 33a0b241ef
commit 39712e359d
10 changed files with 73 additions and 75 deletions

View File

@@ -1,8 +1,8 @@
const Skybox = @This();
const std = @import("std");
const media = @import("media");
const shaders = @import("../shaders.zig");
const stbi = @import("zstbi");
const vk = @import("vulkan");
const vm = @import("vecmath");
@@ -25,7 +25,7 @@ descriptor_set: vk.DescriptorSet,
pipeline_layout: vk.PipelineLayout,
pipeline: vk.Pipeline,
pub fn load(filename: []const u8, engine: *Engine, cube_size: u32, global_uniforms_buffer: vk.Buffer, render_pass: vk.RenderPass, temp_allocator: std.mem.Allocator) !Skybox {
pub fn load(filename: []const u8, engine: *Engine, stbi: *media.stbi, cube_size: u32, global_uniforms_buffer: vk.Buffer, render_pass: vk.RenderPass, temp_allocator: std.mem.Allocator) !Skybox {
std.log.debug("Loading skybox \"{s}\"...", .{filename});
// --- LOAD IMAGE FROM MEMORY ----------------------------------------------
@@ -38,14 +38,8 @@ pub fn load(filename: []const u8, engine: *Engine, cube_size: u32, global_unifor
const file_buf = try dir.readFileAlloc(temp_allocator, filename, std.math.maxInt(usize));
defer temp_allocator.free(file_buf);
var img = try stbi.Image.loadFromMemory(file_buf, 4);
defer img.deinit();
std.debug.assert(img.num_components == 4);
// clamp +inf to max half float
for (std.mem.bytesAsSlice(f16, img.data)) |*sample| {
sample.* = @min(sample.*, std.math.floatMax(f16));
}
const img = try stbi.loadHdrBuf(file_buf);
defer stbi.freeHdr(img);
// --- SYNCHRONIZATION PRIMITIVES ------------------------------------------
@@ -64,13 +58,13 @@ pub fn load(filename: []const u8, engine: *Engine, cube_size: u32, global_unifor
// --- LOAD IMAGE INTO STAGING BUFFER --------------------------------------
var staging_buffer = try StagingBuffer.init(engine, .{
.capacity = @intCast(img.data.len),
.capacity = @intCast(img.width * img.height * @sizeOf(vm.ColorHdr)),
.target_queue = .compute,
});
defer staging_buffer.deinit(engine);
const staging_memory = try staging_buffer.map(engine);
@memcpy(staging_memory, img.data);
@memcpy(staging_memory, @as([*]const u8, @ptrCast(img.data)));
staging_buffer.unmap(engine);
// --- CREATE EQUIRECTANGULAR IMAGE ----------------------------------------