fixed compile check for ui
This commit is contained in:
parent
1916c46e14
commit
6c06d4ee1d
|
|
@ -61,6 +61,10 @@ pub const asserts = p2.asserts;
|
|||
pub const assertf = p2.assertf;
|
||||
pub const stringStrip = p2.stringStrip;
|
||||
|
||||
pub const MakeInterface = p2.MakeInterface;
|
||||
|
||||
pub const Reference = p2.Reference;
|
||||
|
||||
pub const names = p2.names;
|
||||
pub const BumpArena = p2.BumpArena;
|
||||
pub const ObjectHandle = p2.ObjectHandle;
|
||||
|
|
@ -89,12 +93,26 @@ pub const setNameRegistry = p2.setNameRegistry;
|
|||
pub const NameRegistry = p2.NameRegistry;
|
||||
pub const NameInvalid = p2.NameInvalid;
|
||||
|
||||
pub const getFileExtension = p2.getFileExtension;
|
||||
pub const getBasePath = p2.getBasePath;
|
||||
pub const getDir = p2.getDir;
|
||||
pub const getFolder = p2.getFolder;
|
||||
|
||||
pub const MergedSpans = p2.MergedSpans;
|
||||
pub const Span = p2.Span;
|
||||
pub const shell = p2.shell;
|
||||
|
||||
pub const algorithm = @import("p2");
|
||||
pub const math = @import("math.zig");
|
||||
pub const f32x4 = math.f32x4; // __m128_int
|
||||
pub const f32x8 = math.f32x8; // __m256_int
|
||||
pub const f32x16 = math.f32x16; // __m512_int
|
||||
pub const f32x4_zero = math.f32x4_zero;
|
||||
pub const f32x8_zero = math.f32x8_zero;
|
||||
pub const f32x16_zero = math.f32x16_zero;
|
||||
|
||||
//
|
||||
pub const radians = math.radians;
|
||||
pub const Mat = math.Mat;
|
||||
pub const Transform = math.Transform;
|
||||
pub const Quat = math.Quat;
|
||||
|
|
@ -136,6 +154,9 @@ pub const console_logs = logging.console_logs;
|
|||
pub const engine_logs = logging.engine_logs;
|
||||
pub const engine_log = logging.engine_log;
|
||||
|
||||
pub const graphics_logs = logging.graphics_logs;
|
||||
pub const graphics_log = logging.graphics_log;
|
||||
|
||||
pub const engine_err = logging.engine_err;
|
||||
pub const engine_errs = logging.engine_errs;
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ pub const PngContents = struct {
|
|||
try core.assertf(len == pixels.len, "decoded pixel size not buffer size {d} != {d}", .{ len, pixels.len });
|
||||
|
||||
return PngContents{
|
||||
.path = try core.dupe(u8, allocator, pathName),
|
||||
.path = try allocator.dupe(u8, pathName),
|
||||
.pixels = pixels,
|
||||
.size = .{ .x = header.width, .y = header.height },
|
||||
.allocator = allocator,
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ pub fn loadIndexedMeshForPoolingGltf(allocator: std.mem.Allocator, meshName: cor
|
|||
// std.debug.print("\n", .{});
|
||||
// parser.debugPrint();
|
||||
|
||||
if (parser.data.meshes.items.len > 1) {
|
||||
if (parser.data.meshes.len > 1) {
|
||||
return error.OnlyOneMeshPerGltfImplemented;
|
||||
}
|
||||
|
||||
if (parser.data.skins.items.len > 1) {
|
||||
if (parser.data.skins.len > 1) {
|
||||
return error.TooManySkins;
|
||||
}
|
||||
|
||||
|
|
@ -42,97 +42,130 @@ pub fn loadIndexedMeshForPoolingGltf(allocator: std.mem.Allocator, meshName: cor
|
|||
|
||||
defer if (binaryFile) |f| core.fs().unmap(f);
|
||||
|
||||
const m = parser.data.meshes.items[0];
|
||||
core.engine_log("mesh name {s} number of primitives = {d}", .{ m.name, m.primitives.items.len });
|
||||
|
||||
var positions = std.ArrayList(f32).init(allocator);
|
||||
defer positions.deinit();
|
||||
|
||||
var texcoords = std.ArrayList(f32).init(allocator);
|
||||
defer texcoords.deinit();
|
||||
|
||||
var normals = std.ArrayList(f32).init(allocator);
|
||||
defer normals.deinit();
|
||||
|
||||
var joints = std.ArrayList(u16).init(allocator);
|
||||
defer joints.deinit();
|
||||
// add a different joint format one, todo- i need to fix up zgltf
|
||||
const m = parser.data.meshes[0];
|
||||
core.engine_log("mesh name {?s} number of primitives = {d}", .{ m.name, m.primitives.len });
|
||||
|
||||
var positions: ?[]f32 = null;
|
||||
var texcoords: ?[]f32 = null;
|
||||
var normals: ?[]f32 = null;
|
||||
var joints: ?[]u16 = null;
|
||||
var joints8: ?[]u8 = null;
|
||||
var useJoints8: bool = false;
|
||||
var joints8 = std.ArrayList(u8).init(allocator);
|
||||
defer joints8.deinit();
|
||||
var weights: ?[]f32 = null;
|
||||
|
||||
var weights = std.ArrayList(f32).init(allocator);
|
||||
defer weights.deinit();
|
||||
defer {
|
||||
if (positions) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
if (texcoords) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
if (normals) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
if (joints) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
if (joints8) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
if (weights) |x| {
|
||||
allocator.free(x);
|
||||
}
|
||||
}
|
||||
|
||||
// var positions = std.ArrayList(f32){};
|
||||
// defer positions.deinit(allocator);
|
||||
|
||||
// var texcoords = std.ArrayList(f32){};
|
||||
// defer texcoords.deinit(allocator);
|
||||
|
||||
// var normals = std.ArrayList(f32){};
|
||||
// defer normals.deinit(allocator);
|
||||
|
||||
// var joints = std.ArrayList(u16){};
|
||||
// defer joints.deinit(allocator);
|
||||
// // add a different joint format one, todo- i need to fix up zgltf
|
||||
|
||||
// var useJoints8: bool = false;
|
||||
// var joints8 = std.ArrayList(u8){};
|
||||
// defer joints8.deinit(allocator);
|
||||
|
||||
// var weights = std.ArrayList(f32){};
|
||||
// defer weights.deinit(allocator);
|
||||
|
||||
var weightCount: usize = 4;
|
||||
|
||||
if (m.primitives.items.len > 1) {
|
||||
if (m.primitives.len > 1) {
|
||||
@panic("sorry, havent implemented support for multiple primitives yet, would require more work on the way i handle materials");
|
||||
}
|
||||
|
||||
var indexList = std.ArrayList(u32).init(allocator);
|
||||
for (m.primitives.items) |primitive| {
|
||||
//var indexList = std.ArrayList(u32).init(allocator;
|
||||
var indexList = std.ArrayList(u32){};
|
||||
|
||||
for (m.primitives) |primitive| {
|
||||
if (primitive.indices) |indices| {
|
||||
const accessor = parser.data.accessors.items[indices];
|
||||
const accessor = parser.data.accessors[indices];
|
||||
// core.engine_log("index accessor info: {any}", .{accessor});
|
||||
|
||||
if (accessor.component_type == .unsigned_short) {
|
||||
var temp = std.ArrayList(u16).init(allocator);
|
||||
defer temp.deinit();
|
||||
parser.getDataFromBufferView(u16, &temp, accessor, @alignCast(binaryBytes));
|
||||
for (temp.items) |t| {
|
||||
try indexList.append(@intCast(t));
|
||||
const temp = try parser.getDataFromBufferView(u16, allocator, accessor, @alignCast(binaryBytes));
|
||||
defer allocator.free(temp);
|
||||
|
||||
for (temp) |t| {
|
||||
try indexList.append(allocator, @intCast(t));
|
||||
}
|
||||
} else if (accessor.component_type == .unsigned_integer) {
|
||||
parser.getDataFromBufferView(u32, &indexList, accessor, @alignCast(binaryBytes));
|
||||
const temp = try parser.getDataFromBufferView(u32, allocator, accessor, @alignCast(binaryBytes));
|
||||
defer allocator.free(temp);
|
||||
try indexList.appendSlice(allocator, temp);
|
||||
// ... do we need to rotate winding orders?
|
||||
}
|
||||
}
|
||||
|
||||
for (primitive.attributes.items) |attribute| {
|
||||
for (primitive.attributes) |attribute| {
|
||||
// core.engine_log("attribute: {any}", .{attribute});
|
||||
|
||||
switch (attribute) {
|
||||
.position => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
// core.engine_log("accessor info: {any}", .{accessor});
|
||||
|
||||
parser.getDataFromBufferView(f32, &positions, accessor, @alignCast(binaryBytes));
|
||||
positions = try parser.getDataFromBufferView(f32, allocator, accessor, @alignCast(binaryBytes));
|
||||
// core.engine_log("positions loaded: {d}", .{positions.items.len});
|
||||
},
|
||||
.normal => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
// core.engine_log("accessor info: {any}", .{accessor});
|
||||
|
||||
parser.getDataFromBufferView(f32, &normals, accessor, @alignCast(binaryBytes));
|
||||
normals = try parser.getDataFromBufferView(f32, allocator, accessor, @alignCast(binaryBytes));
|
||||
// core.engine_log("normals loaded: {d}", .{normals.items.len});
|
||||
},
|
||||
.texcoord => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
// core.engine_log("accessor info: {any}", .{accessor});
|
||||
|
||||
parser.getDataFromBufferView(f32, &texcoords, accessor, @alignCast(binaryBytes));
|
||||
texcoords = try parser.getDataFromBufferView(f32, allocator, accessor, @alignCast(binaryBytes));
|
||||
// core.engine_log("texcoords loaded: {d}", .{texcoords.items.len});
|
||||
},
|
||||
.joints => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
// core.engine_log("accessor info: {any} acecssor index {d}", .{ accessor, x });
|
||||
|
||||
if (accessor.component_type == .unsigned_byte) {
|
||||
useJoints8 = true;
|
||||
parser.getDataFromBufferView(u8, &joints8, accessor, @alignCast(binaryBytes));
|
||||
joints8 = try parser.getDataFromBufferView(u8, allocator, accessor, @alignCast(binaryBytes));
|
||||
// core.engine_log("joints8 loaded: {d} - {d} {d} {d} {d}", .{ joints8.items.len, joints8.items[0], joints8.items[1], joints8.items[2], joints8.items[3] });
|
||||
} else {
|
||||
parser.getDataFromBufferView(u16, &joints, accessor, @alignCast(binaryBytes));
|
||||
joints = try parser.getDataFromBufferView(u16, allocator, accessor, @alignCast(binaryBytes));
|
||||
// core.engine_log("joints loaded: {d} - {d} {d} {d} {d}", .{ joints.items.len, joints.items[0], joints.items[1], joints.items[2], joints.items[3] });
|
||||
}
|
||||
},
|
||||
.weights => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
// core.engine_log("accessor info: {any}", .{accessor});
|
||||
|
||||
parser.getDataFromBufferView(f32, &weights, accessor, @alignCast(binaryBytes));
|
||||
weights = try parser.getDataFromBufferView(f32, allocator, accessor, @alignCast(binaryBytes));
|
||||
|
||||
if (accessor.type == .vec3) {
|
||||
weightCount = 3;
|
||||
|
|
@ -141,74 +174,74 @@ pub fn loadIndexedMeshForPoolingGltf(allocator: std.mem.Allocator, meshName: cor
|
|||
// core.engine_log("weights loaded: {d} - {d} {d} {d} {d}", .{ weights.items.len, weights.items[0], weights.items[1], weights.items[2], weights.items[3] });
|
||||
},
|
||||
.tangent => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
core.engine_log("accessor info: {any} NOT PARSED", .{accessor});
|
||||
},
|
||||
.color => |x| {
|
||||
const accessor = parser.data.accessors.items[x];
|
||||
const accessor = parser.data.accessors[x];
|
||||
core.engine_log("accessor info: {any} NOT PARSED", .{accessor});
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parser.data.skins.items.len > 1) {
|
||||
if (parser.data.skins.len > 1) {
|
||||
@panic("too many skins, not supported");
|
||||
}
|
||||
|
||||
var jointNameList: std.ArrayList(JointNameEntry) = std.ArrayList(JointNameEntry).init(allocator);
|
||||
var jointNameList: std.ArrayList(JointNameEntry) = std.ArrayList(JointNameEntry){};
|
||||
|
||||
if (weights.items.len > 0) {
|
||||
if (weights.?.len > 0) {
|
||||
core.engine_log("skin found, building joint map", .{});
|
||||
if (parser.data.skins.items[0].skeleton) |skeletonIndex| {
|
||||
for (parser.data.nodes.items[skeletonIndex..], 0..) |node, i| {
|
||||
if (parser.data.skins[0].skeleton) |skeletonIndex| {
|
||||
for (parser.data.nodes[skeletonIndex..], 0..) |node, i| {
|
||||
// core.engine_log("gltf: {s} -> {d} (skeleton index)", .{ node.name, i });
|
||||
// const gcAllocator = graphics.getContext().allocator;
|
||||
try jointNameList.append(.{ .index = @intCast(i), .name = try gcAllocator.dupe(u8, node.name) });
|
||||
try jointNameList.append(allocator, .{ .index = @intCast(i), .name = try gcAllocator.dupe(u8, node.name orelse "unknown") });
|
||||
}
|
||||
} else {
|
||||
if (parser.data.skins.items[0].joints.items.len > 0) {
|
||||
for (parser.data.skins.items[0].joints.items, 0..) |i, j| {
|
||||
const node = parser.data.nodes.items[i];
|
||||
if (parser.data.skins[0].joints.len > 0) {
|
||||
for (parser.data.skins[0].joints, 0..) |i, j| {
|
||||
const node = parser.data.nodes[i];
|
||||
// core.engine_log("gltf: {s} -> {d} (joints map)", .{ node.name, j });
|
||||
// const gcAllocator = graphics.getContext().allocator;
|
||||
try jointNameList.append(.{ .index = @intCast(j), .name = try gcAllocator.dupe(u8, node.name) });
|
||||
try jointNameList.append(allocator, .{ .index = @intCast(j), .name = try gcAllocator.dupe(u8, node.name orelse "unknown") });
|
||||
}
|
||||
} else {
|
||||
for (parser.data.nodes.items, 0..) |node, i| {
|
||||
for (parser.data.nodes, 0..) |node, i| {
|
||||
// core.engine_log("gltf: {s} -> {d} (fallback)", .{ node.name, i });
|
||||
// const gcAllocator = graphics.getContext().allocator;
|
||||
try jointNameList.append(.{ .index = @intCast(i), .name = try gcAllocator.dupe(u8, node.name) });
|
||||
try jointNameList.append(allocator, .{ .index = @intCast(i), .name = try gcAllocator.dupe(u8, node.name orelse "unknown") });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var vertexList = std.ArrayList(MeshVertex).init(allocator);
|
||||
var vertexList = std.ArrayList(MeshVertex){};
|
||||
|
||||
var i: usize = 0;
|
||||
const vertexCount = positions.items.len / 3;
|
||||
const vertexCount = positions.?.len / 3;
|
||||
while (i < vertexCount) : (i += 1) {
|
||||
const normalIndex = i * 3;
|
||||
const positionIndex = i * 3;
|
||||
const uvIndex = i * 2;
|
||||
|
||||
const uv: core.Vector2f = if (uvIndex < texcoords.items.len) .{
|
||||
.x = texcoords.items[uvIndex],
|
||||
.y = texcoords.items[uvIndex + 1],
|
||||
const uv: core.Vector2f = if (uvIndex < texcoords.?.len) .{
|
||||
.x = texcoords.?[uvIndex],
|
||||
.y = texcoords.?[uvIndex + 1],
|
||||
} else core.Vector2f{};
|
||||
|
||||
const normal = if (normalIndex < normals.items.len) core.Vectorf{
|
||||
.x = normals.items[i],
|
||||
.y = normals.items[i + 1],
|
||||
.z = normals.items[i + 2],
|
||||
const normal = if (normalIndex < normals.?.len) core.Vectorf{
|
||||
.x = normals.?[i],
|
||||
.y = normals.?[i + 1],
|
||||
.z = normals.?[i + 2],
|
||||
} else core.Vectorf{};
|
||||
|
||||
try vertexList.append(.{
|
||||
try vertexList.append(allocator, .{
|
||||
.position = .{
|
||||
.x = positions.items[positionIndex],
|
||||
.y = positions.items[positionIndex + 1],
|
||||
.z = positions.items[positionIndex + 2],
|
||||
.x = positions.?[positionIndex],
|
||||
.y = positions.?[positionIndex + 1],
|
||||
.z = positions.?[positionIndex + 2],
|
||||
},
|
||||
.normal = normal,
|
||||
.color = .{},
|
||||
|
|
@ -218,33 +251,33 @@ pub fn loadIndexedMeshForPoolingGltf(allocator: std.mem.Allocator, meshName: cor
|
|||
const jointsIndex = weightCount * i;
|
||||
if (weightCount == 4) {
|
||||
if (useJoints8) {
|
||||
if (jointsIndex < joints8.items.len) {
|
||||
if (jointsIndex < joints8.?.len) {
|
||||
vertexList.items[vertexList.items.len - 1].bones = .{
|
||||
@intCast(joints8.items[jointsIndex + 0]),
|
||||
@intCast(joints8.items[jointsIndex + 1]),
|
||||
@intCast(joints8.items[jointsIndex + 2]),
|
||||
@intCast(joints8.items[jointsIndex + 3]),
|
||||
@intCast(joints8.?[jointsIndex + 0]),
|
||||
@intCast(joints8.?[jointsIndex + 1]),
|
||||
@intCast(joints8.?[jointsIndex + 2]),
|
||||
@intCast(joints8.?[jointsIndex + 3]),
|
||||
};
|
||||
vertexList.items[vertexList.items.len - 1].weights = .{
|
||||
@intFromFloat(weights.items[jointsIndex + 0] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 1] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 2] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 3] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 0] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 1] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 2] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 3] * 255),
|
||||
};
|
||||
}
|
||||
} else {
|
||||
if (jointsIndex < joints.items.len) {
|
||||
if (jointsIndex < joints.?.len) {
|
||||
vertexList.items[vertexList.items.len - 1].bones = .{
|
||||
@intCast(joints.items[jointsIndex + 0]),
|
||||
@intCast(joints.items[jointsIndex + 1]),
|
||||
@intCast(joints.items[jointsIndex + 2]),
|
||||
@intCast(joints.items[jointsIndex + 3]),
|
||||
@intCast(joints.?[jointsIndex + 0]),
|
||||
@intCast(joints.?[jointsIndex + 1]),
|
||||
@intCast(joints.?[jointsIndex + 2]),
|
||||
@intCast(joints.?[jointsIndex + 3]),
|
||||
};
|
||||
vertexList.items[vertexList.items.len - 1].weights = .{
|
||||
@intFromFloat(weights.items[jointsIndex + 0] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 1] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 2] * 255),
|
||||
@intFromFloat(weights.items[jointsIndex + 3] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 0] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 1] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 2] * 255),
|
||||
@intFromFloat(weights.?[jointsIndex + 3] * 255),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -255,15 +288,15 @@ pub fn loadIndexedMeshForPoolingGltf(allocator: std.mem.Allocator, meshName: cor
|
|||
|
||||
if (indexList.items.len == 0) {
|
||||
for (0..vertexList.items.len) |x| {
|
||||
try indexList.append(@intCast(x));
|
||||
try indexList.append(allocator, @intCast(x));
|
||||
}
|
||||
}
|
||||
|
||||
const rv: MeshUpdate = .{
|
||||
.new = .{
|
||||
.vertices = try vertexList.toOwnedSlice(),
|
||||
.indices = try indexList.toOwnedSlice(),
|
||||
.jointNames = try jointNameList.toOwnedSlice(),
|
||||
.vertices = try vertexList.toOwnedSlice(allocator),
|
||||
.indices = try indexList.toOwnedSlice(allocator),
|
||||
.jointNames = try jointNameList.toOwnedSlice(allocator),
|
||||
.skeletonName = skeletonName,
|
||||
.name = meshName,
|
||||
},
|
||||
|
|
@ -284,4 +317,4 @@ const MeshVertex = meshes.MeshVertex;
|
|||
|
||||
const core = @import("core");
|
||||
const std = @import("std");
|
||||
const zgltf = @import("zgltf");
|
||||
const zgltf = @import("zgltf").Gltf;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ pub fn loadIndexedMeshForPoolingObj(allocator: std.mem.Allocator, meshName: core
|
|||
|
||||
var vertexMap = std.AutoHashMap(MeshVertexTransmute, u32).init(allocator);
|
||||
defer vertexMap.deinit();
|
||||
var vertexList = std.ArrayList(MeshVertex).init(allocator);
|
||||
var indexList = std.ArrayList(u32).init(allocator);
|
||||
var vertexList = std.ArrayList(MeshVertex){};
|
||||
var indexList = std.ArrayList(u32){};
|
||||
|
||||
const m: *objLoader.ObjMesh = &Objs.meshes.items[0];
|
||||
|
||||
|
|
@ -37,9 +37,9 @@ pub fn loadIndexedMeshForPoolingObj(allocator: std.mem.Allocator, meshName: core
|
|||
index = cachedIndex;
|
||||
} else {
|
||||
try vertexMap.put(transmute, index);
|
||||
try vertexList.append(meshVertex);
|
||||
try vertexList.append(allocator, meshVertex);
|
||||
}
|
||||
try indexList.append(index);
|
||||
try indexList.append(allocator, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,20 +63,20 @@ pub fn loadIndexedMeshForPoolingObj(allocator: std.mem.Allocator, meshName: core
|
|||
index = cachedIndex;
|
||||
} else {
|
||||
try vertexMap.put(transmute, index);
|
||||
try vertexList.append(meshVertex);
|
||||
try vertexList.append(allocator, meshVertex);
|
||||
}
|
||||
try indexList.append(index);
|
||||
try indexList.append(allocator, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var jointNames = std.ArrayList(JointNameEntry).init(allocator);
|
||||
var jointNames = std.ArrayList(JointNameEntry){};
|
||||
|
||||
const rv: MeshUpdate = .{
|
||||
.new = .{
|
||||
.vertices = try vertexList.toOwnedSlice(),
|
||||
.indices = try indexList.toOwnedSlice(),
|
||||
.jointNames = try jointNames.toOwnedSlice(),
|
||||
.vertices = try vertexList.toOwnedSlice(allocator),
|
||||
.indices = try indexList.toOwnedSlice(allocator),
|
||||
.jointNames = try jointNames.toOwnedSlice(allocator),
|
||||
.skeletonName = null,
|
||||
.name = meshName,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -170,12 +170,12 @@ pub fn createPipeline(self: *@This()) !*gpu.GPUGraphicsPipeline {
|
|||
pci.vertex_shader = vertex;
|
||||
pci.fragment_shader = fragment;
|
||||
|
||||
var attributes = std.ArrayList(gpu.GPUVertexAttribute).init(self.allocator);
|
||||
defer attributes.deinit();
|
||||
var attributes = std.ArrayList(gpu.GPUVertexAttribute){};
|
||||
defer attributes.deinit(self.allocator);
|
||||
|
||||
var offset: u32 = 0;
|
||||
{
|
||||
try addAttribute(&attributes, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
try addAttribute(self.allocator, &attributes, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
}
|
||||
|
||||
pci.vertex_input_state = .{
|
||||
|
|
@ -220,8 +220,8 @@ pub fn createPipeline(self: *@This()) !*gpu.GPUGraphicsPipeline {
|
|||
return pipe;
|
||||
}
|
||||
|
||||
fn addAttribute(list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void {
|
||||
try list.append(.{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 });
|
||||
fn addAttribute(allocator: std.mem.Allocator, list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void {
|
||||
try list.append(allocator, .{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 });
|
||||
offset.* = offset.* + size;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ fn createPipeline(self: *@This()) !void {
|
|||
//var attributes = try ctx.generateVertexAttributeList();
|
||||
|
||||
var attributes = try ctx.addVertexAttributes(&pci);
|
||||
defer attributes.deinit();
|
||||
defer attributes.deinit(self.allocator);
|
||||
|
||||
pci.vertex_input_state = .{
|
||||
.num_vertex_buffers = 1,
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ pub fn uploadCubeFromPaths(self: *@This(), name: core.Name, paths: []const []con
|
|||
return error.CubeNeedsSixFaces;
|
||||
}
|
||||
|
||||
var cubeList = std.ArrayList(core.png.PngContents).init(self.allocator);
|
||||
defer cubeList.deinit();
|
||||
var cubeList = std.ArrayList(core.png.PngContents){}; //std.ArrayList(core.png.PngContents).init(self.allocator);
|
||||
defer cubeList.deinit(self.allocator);
|
||||
|
||||
var gpuTexture: *gpu.GPUTexture = undefined;
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ pub fn uploadCubeFromPaths(self: *@This(), name: core.Name, paths: []const []con
|
|||
var textureSize: u32 = 0;
|
||||
|
||||
for (paths) |path| {
|
||||
try cubeList.append(try core.png.PngContents.initFromFS(core.fs(), self.allocator, path));
|
||||
try cubeList.append(self.allocator, try core.png.PngContents.initFromFS(core.fs(), self.allocator, path));
|
||||
const png = &cubeList.items[cubeList.items.len - 1];
|
||||
|
||||
const cmd = self.device.acquireGPUCommandBuffer();
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ pub const MeshPool = struct {
|
|||
.indexSpans = try core.MergedSpans.init(allocator, settings.indexCount),
|
||||
.vertexSpans = try core.MergedSpans.init(allocator, settings.vertexCount),
|
||||
.meshUpdates = try core.RingQueue(rend.MeshUpdate).init(allocator, 128),
|
||||
.destroyList = std.ArrayList(*gpu.GPUTransferBuffer).init(allocator),
|
||||
.destroyListSizes = std.ArrayList(usize).init(allocator),
|
||||
.destroyList = std.ArrayList(*gpu.GPUTransferBuffer){},
|
||||
.destroyListSizes = std.ArrayList(usize){},
|
||||
.device = device,
|
||||
};
|
||||
|
||||
|
|
@ -175,8 +175,8 @@ pub const MeshPool = struct {
|
|||
const newSpan = try mergedSpans.allocate(@intCast(uploadSlice.len));
|
||||
const uploadSize = @sizeOf(T) * newSpan.size;
|
||||
const upload = rend.renderer.createGPUTransferBuffer(&.{ .usage = .transferbufferusageUpload, .size = uploadSize, .props = 0 });
|
||||
try self.destroyList.append(upload);
|
||||
try self.destroyListSizes.append(uploadSize);
|
||||
try self.destroyList.append(self.allocator, upload);
|
||||
try self.destroyListSizes.append(self.allocator, uploadSize);
|
||||
|
||||
var mappedSlice: []T = undefined;
|
||||
mappedSlice.ptr = @ptrCast(@alignCast(self.device.mapGPUTransferBuffer(upload, false)));
|
||||
|
|
@ -211,8 +211,8 @@ pub const MeshPool = struct {
|
|||
self.device.releaseGPUBuffer(self.vertexBuffer);
|
||||
|
||||
self.installedMeshes.deinit(self.allocator);
|
||||
self.destroyList.deinit();
|
||||
self.destroyListSizes.deinit();
|
||||
self.destroyList.deinit(self.allocator);
|
||||
self.destroyListSizes.deinit(self.allocator);
|
||||
self.indexSpans.deinit();
|
||||
self.meshUpdates.deinit();
|
||||
self.vertexSpans.deinit();
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ pub const Renderer = struct {
|
|||
//var attributes = try self.generateVertexAttributeList();
|
||||
|
||||
var attributes = try addVertexAttributesFromStruct(rend.MeshVertex, &pci);
|
||||
defer attributes.deinit();
|
||||
defer attributes.deinit(self.allocator);
|
||||
|
||||
pci.vertex_input_state = .{
|
||||
.num_vertex_buffers = 1,
|
||||
|
|
@ -435,20 +435,21 @@ pub const Renderer = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn addAttribute(list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void {
|
||||
try list.append(.{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 });
|
||||
pub fn addAttribute(allocator: std.mem.Allocator, list: *std.ArrayList(gpu.GPUVertexAttribute), offset: *u32, size: u32, format: gpu.GPUVertexElementFormat) !void {
|
||||
try list.append(allocator, .{ .location = @intCast(list.items.len), .offset = offset.*, .format = format, .buffer_slot = 0 });
|
||||
offset.* = offset.* + size;
|
||||
}
|
||||
|
||||
pub fn generateVertexAttributeList_deprecated(self: *@This()) !std.ArrayList(gpu.GPUVertexAttribute) {
|
||||
var list = std.ArrayList(gpu.GPUVertexAttribute).init(self.allocator);
|
||||
var list = std.ArrayList(gpu.GPUVertexAttribute){};
|
||||
|
||||
var offset: u32 = 0;
|
||||
{
|
||||
try addAttribute(&list, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
try addAttribute(&list, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
try addAttribute(&list, &offset, @sizeOf(f32) * 4, .vertexelementformatFloat4);
|
||||
try addAttribute(&list, &offset, @sizeOf(f32) * 2, .vertexelementformatFloat2);
|
||||
try addAttribute(&list, &offset, @sizeOf(u32), .vertexelementformatUint);
|
||||
try addAttribute(self.allocator, &list, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
try addAttribute(self.allocator, &list, &offset, @sizeOf(f32) * 3, .vertexelementformatFloat3);
|
||||
try addAttribute(self.allocator, &list, &offset, @sizeOf(f32) * 4, .vertexelementformatFloat4);
|
||||
try addAttribute(self.allocator, &list, &offset, @sizeOf(f32) * 2, .vertexelementformatFloat2);
|
||||
try addAttribute(self.allocator, &list, &offset, @sizeOf(u32), .vertexelementformatUint);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
|
@ -464,7 +465,7 @@ pub const Renderer = struct {
|
|||
|
||||
// var attributes = try self.generateVertexAttributeList();
|
||||
var attributes = try self.addVertexAttributes(&pci);
|
||||
defer attributes.deinit();
|
||||
defer attributes.deinit(self.allocator);
|
||||
|
||||
pci.vertex_input_state = .{
|
||||
.num_vertex_buffers = 1,
|
||||
|
|
@ -494,13 +495,14 @@ pub const Renderer = struct {
|
|||
}
|
||||
|
||||
const CreatePipelineInfo = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
attributes: ?std.ArrayList(gpu.GPUVertexAttribute) = null,
|
||||
pci: gpu.GPUGraphicsPipelineCreateInfo = std.mem.zeroes(gpu.GPUGraphicsPipelineCreateInfo),
|
||||
vertexBuffers: std.ArrayListUnmanaged(gpu.GPUVertexBufferDescription) = .{},
|
||||
colorTargets: std.ArrayListUnmanaged(gpu.GPUColorTargetDescription) = .{},
|
||||
vertexBuffers: std.ArrayList(gpu.GPUVertexBufferDescription) = .{},
|
||||
colorTargets: std.ArrayList(gpu.GPUColorTargetDescription) = .{},
|
||||
|
||||
pub fn init() @This() {
|
||||
return .{};
|
||||
pub fn init(a: std.mem.Allocator) @This() {
|
||||
return .{ .allocator = a };
|
||||
}
|
||||
|
||||
pub fn addMeshPci(self: *@This(), vertexShader: []const u8, fragmentShader: []const u8) !void {
|
||||
|
|
@ -584,7 +586,7 @@ pub const Renderer = struct {
|
|||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
if (self.attributes) |*a| {
|
||||
a.deinit();
|
||||
a.deinit(self.allocator);
|
||||
}
|
||||
self.vertexBuffers.deinit(context().allocator);
|
||||
self.colorTargets.deinit(context().allocator);
|
||||
|
|
@ -592,7 +594,7 @@ pub const Renderer = struct {
|
|||
};
|
||||
|
||||
pub fn createTransparentsPipeline(self: *@This()) !void {
|
||||
var createInfo = CreatePipelineInfo.init();
|
||||
var createInfo = CreatePipelineInfo.init(self.allocator);
|
||||
try createInfo.addMeshPci("meshes.vert", "lit_mesh.frag");
|
||||
defer createInfo.deinit();
|
||||
|
||||
|
|
@ -602,7 +604,7 @@ pub const Renderer = struct {
|
|||
}
|
||||
|
||||
pub fn createOpaquePipeline(self: *@This()) !void {
|
||||
var createInfo = CreatePipelineInfo.init();
|
||||
var createInfo = CreatePipelineInfo.init(self.allocator);
|
||||
try createInfo.addMeshPci("meshes.vert", "lit_mesh.frag");
|
||||
defer createInfo.deinit();
|
||||
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ pub fn createPipeline(self: *@This()) !void {
|
|||
pci.fragment_shader = fragment;
|
||||
|
||||
var vertexList = try ctx.addVertexAttributes(&pci);
|
||||
defer vertexList.deinit();
|
||||
defer vertexList.deinit(self.allocator);
|
||||
|
||||
pci.target_info.num_color_targets = 1;
|
||||
pci.target_info.color_target_descriptions = &[_]gpu.GPUColorTargetDescription{
|
||||
|
|
|
|||
|
|
@ -26,11 +26,12 @@ pub fn getVertexFormatFromType(comptime T: type) gpu.GPUVertexElementFormat {
|
|||
|
||||
pub fn addVertexAttributesFromStruct(comptime T: type, pci: *gpu.GPUGraphicsPipelineCreateInfo) !std.ArrayList(gpu.GPUVertexAttribute) {
|
||||
const ctx = rend.context();
|
||||
var list = std.ArrayList(gpu.GPUVertexAttribute).init(ctx.allocator);
|
||||
const allocator = ctx.allocator;
|
||||
var list = std.ArrayList(gpu.GPUVertexAttribute){};
|
||||
var offset: u32 = 0;
|
||||
|
||||
inline for (@typeInfo(T).@"struct".fields) |field| {
|
||||
try Renderer.addAttribute(&list, &offset, @sizeOf(field.type), getVertexFormatFromType(field.type));
|
||||
try Renderer.addAttribute(allocator, &list, &offset, @sizeOf(field.type), getVertexFormatFromType(field.type));
|
||||
}
|
||||
core.engine_log("# of attributes added : {d}", .{list.items.len});
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ const SsboBuffer = struct {
|
|||
|
||||
pub fn mapSlice(self: *@This(), comptime T: type, device: *gpu.GPUDevice) []T {
|
||||
var rv: []T = undefined;
|
||||
rv.ptr = @alignCast(@ptrCast(device.mapGPUTransferBuffer(self.staging, false)));
|
||||
rv.ptr = @ptrCast(@alignCast(device.mapGPUTransferBuffer(self.staging, false)));
|
||||
rv.len = self.count;
|
||||
|
||||
return rv;
|
||||
|
|
@ -130,7 +130,7 @@ pub fn create(allocator: std.mem.Allocator) !*@This() {
|
|||
.stringArena = std.heap.ArenaAllocator.init(allocator),
|
||||
.debugStringArena = std.heap.ArenaAllocator.init(allocator),
|
||||
.quadMeshName = core.MakeName("m_screenPlane"),
|
||||
.drawList = papyrus.DrawList.init(allocator),
|
||||
.drawList = papyrus.DrawList{},
|
||||
.debugTextQueue = try @TypeOf(self.debugTextQueue).init(allocator, 4096),
|
||||
.screenBuffers = undefined,
|
||||
};
|
||||
|
|
@ -278,7 +278,7 @@ pub fn destroy(self: *@This()) void {
|
|||
self.stringArena.deinit();
|
||||
self.debugStringArena.deinit();
|
||||
self.runtime.destroy();
|
||||
self.drawList.deinit();
|
||||
self.drawList.deinit(self.allocator);
|
||||
self.tempDrawCommand.deinit(self.allocator);
|
||||
self.allocator.destroy(self);
|
||||
}
|
||||
|
|
@ -295,7 +295,7 @@ pub fn createTextPipeline(self: *@This()) !void {
|
|||
pci.fragment_shader = fragment;
|
||||
|
||||
var attributes = try text_renderer.addVertexAttributes(&pci);
|
||||
defer attributes.deinit();
|
||||
defer attributes.deinit(ctx.allocator);
|
||||
|
||||
pci.target_info.num_color_targets = 1;
|
||||
|
||||
|
|
@ -331,7 +331,7 @@ pub fn createRectPipeline(self: *@This()) !void {
|
|||
pci.fragment_shader = fragment;
|
||||
|
||||
var attributes = try ctx.addVertexAttributes(&pci);
|
||||
defer attributes.deinit();
|
||||
defer attributes.deinit(ctx.allocator);
|
||||
|
||||
pci.vertex_input_state = .{
|
||||
.num_vertex_buffers = 1,
|
||||
|
|
@ -414,7 +414,7 @@ pub fn drawToTarget(self: *@This(), cmd: *gpu.GPUCommandBuffer, ctx: *papyrus.Co
|
|||
|
||||
ctx.drawDebug = stashedDrawDebug or self.reloadingShaders;
|
||||
|
||||
ctx.makeDrawList(&self.drawList, &self.stringArena) catch return;
|
||||
ctx.makeDrawList(self.allocator, &self.drawList, &self.stringArena) catch return;
|
||||
ctx.drawDebug = stashedDrawDebug;
|
||||
|
||||
const textRenderer = self.getTextRenderer(ctx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue