render-zig

A 3D rendering engine written in Zig
git clone git://git.christianermann.dev/render-zig
Log | Files | Refs

commit 50544678c6d4e3c38597da9dcf23562fa02942c6
parent 1e1a77b4ca78a098b8f054754a6eb4562e4f47fa
Author: Christian Ermann <christianermann@gmail.com>
Date:   Sun,  8 Dec 2024 13:44:05 -0800

Fix indirect offsets when mesh has no normals or texcoords

Diffstat:
Msrc/render_data.zig | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/render_data.zig b/src/render_data.zig @@ -195,8 +195,17 @@ pub fn addMesh( allocator: std.mem.Allocator, ) !*RenderObject { const offset_p = try self.positions.allocWrite(mesh.positions, self.queue); - _ = try self.normals.allocWrite(mesh.normals, self.queue); - _ = try self.tex_coords.allocWrite(mesh.tex_coords, self.queue); + const n: u32 = @intCast(mesh.positions.len); + if (mesh.normals.len > 0) { + _ = try self.normals.allocWrite(mesh.normals, self.queue); + } else { + _ = try self.normals.alloc(n); + } + if (mesh.tex_coords.len > 0) { + _ = try self.tex_coords.allocWrite(mesh.tex_coords, self.queue); + } else { + _ = try self.tex_coords.alloc(n); + } _ = try self.tangents.allocWrite(mesh.tangents, self.queue); _ = try self.bitangents.allocWrite(mesh.bitangents, self.queue); const offset_i = try self.indices.allocWrite(mesh.indices, self.queue);