Compare commits
2 Commits
c3fa7115c8
...
a18fcb44ac
| Author | SHA1 | Date | |
|---|---|---|---|
| a18fcb44ac | |||
| 609321af2a |
@@ -50,7 +50,6 @@ skybox: Skybox,
|
|||||||
player: Player,
|
player: Player,
|
||||||
font: Fonts.Id,
|
font: Fonts.Id,
|
||||||
|
|
||||||
const max_textures = 1024;
|
|
||||||
const max_point_lights = 1024;
|
const max_point_lights = 1024;
|
||||||
const max_directional_lights = 4;
|
const max_directional_lights = 4;
|
||||||
const chunk_descriptor_pool = 1024;
|
const chunk_descriptor_pool = 1024;
|
||||||
@@ -138,9 +137,8 @@ pub fn init() !Game {
|
|||||||
.{
|
.{
|
||||||
.binding = 5,
|
.binding = 5,
|
||||||
.descriptor_type = .sampled_image,
|
.descriptor_type = .sampled_image,
|
||||||
.descriptor_count = max_textures,
|
.descriptor_count = Textures.max_textures,
|
||||||
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
|
.stage_flags = .{ .vertex_bit = true, .fragment_bit = true },
|
||||||
.flags = .{ .variable_descriptor_count_bit = true }, // TODO Get rid of this AND somehow integrate with Textures module?
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -418,7 +416,7 @@ pub fn init() !Game {
|
|||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.type = .sampled_image,
|
.type = .sampled_image,
|
||||||
.descriptor_count = max_textures,
|
.descriptor_count = Textures.max_textures,
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.type = .uniform_buffer,
|
.type = .uniform_buffer,
|
||||||
@@ -436,7 +434,6 @@ pub fn init() !Game {
|
|||||||
const global_descriptor_set = try engine.allocateDescriptorSet(.{
|
const global_descriptor_set = try engine.allocateDescriptorSet(.{
|
||||||
.descriptor_pool = descriptor_pool,
|
.descriptor_pool = descriptor_pool,
|
||||||
.set_layout = global_descriptor_set_layout,
|
.set_layout = global_descriptor_set_layout,
|
||||||
.variable_descriptor_count = @intCast(textures.array.items.len),
|
|
||||||
});
|
});
|
||||||
engine.setObjectName(global_descriptor_set, "DS Global", .{});
|
engine.setObjectName(global_descriptor_set, "DS Global", .{});
|
||||||
|
|
||||||
|
|||||||
@@ -421,30 +421,35 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
|
|||||||
const margin: f16 = 8;
|
const margin: f16 = 8;
|
||||||
const font_size: f32 = 16;
|
const font_size: f32 = 16;
|
||||||
|
|
||||||
|
// NOTE We have to do the number formatting semi-manually, because zig's
|
||||||
|
// std fmt is weird with signed numbers
|
||||||
|
|
||||||
|
var number_buf: [9]u8 = undefined; // sign ('-' or ' ') and 8 hex digits
|
||||||
|
|
||||||
gui.pushBox(.{
|
gui.pushBox(.{
|
||||||
.background_color = .init(0, 0, 0, 0.75),
|
.background_color = .init(0, 0, 0, 0.75),
|
||||||
.border_color = .init(0, 0, 0, 1),
|
.border_color = .init(0, 0, 0, 1),
|
||||||
.position_sspx = .init(0, 0),
|
.position_sspx = .init(0, 0),
|
||||||
.size_px = .init(157, 4 * margin + 3 * font_size),
|
.size_px = .init(164, 4 * margin + 3 * font_size),
|
||||||
.border_width_px = 0,
|
.border_width_px = 0,
|
||||||
.border_radius_px = 0,
|
.border_radius_px = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
gui.printLine("X {X:0>8}", .{@as(u32, @bitCast(self.position_sv.x))}, .{
|
gui.printLine("X {s}", .{formatHexCoord(self.position_sv.x, &number_buf)}, .{
|
||||||
.position_sspx = .init(margin, margin + font_size),
|
.position_sspx = .init(margin, margin + font_size),
|
||||||
.font_id = @enumFromInt(0),
|
.font_id = @enumFromInt(0),
|
||||||
.cap_height_px = font_size,
|
.cap_height_px = font_size,
|
||||||
.color = .init(1, 1, 1, 1),
|
.color = .init(1, 1, 1, 1),
|
||||||
});
|
});
|
||||||
|
|
||||||
gui.printLine("Y {X:0>8}", .{@as(u32, @bitCast(self.position_sv.y))}, .{
|
gui.printLine("Y {s}", .{formatHexCoord(self.position_sv.y, &number_buf)}, .{
|
||||||
.position_sspx = .init(margin, 2 * (margin + font_size)),
|
.position_sspx = .init(margin, 2 * (margin + font_size)),
|
||||||
.font_id = @enumFromInt(0),
|
.font_id = @enumFromInt(0),
|
||||||
.cap_height_px = font_size,
|
.cap_height_px = font_size,
|
||||||
.color = .init(1, 1, 1, 1),
|
.color = .init(1, 1, 1, 1),
|
||||||
});
|
});
|
||||||
|
|
||||||
gui.printLine("Z {X:0>8}", .{@as(u32, @bitCast(self.position_sv.z))}, .{
|
gui.printLine("Z {s}", .{formatHexCoord(self.position_sv.z, &number_buf)}, .{
|
||||||
.position_sspx = .init(margin, 3 * (margin + font_size)),
|
.position_sspx = .init(margin, 3 * (margin + font_size)),
|
||||||
.font_id = @enumFromInt(0),
|
.font_id = @enumFromInt(0),
|
||||||
.cap_height_px = font_size,
|
.cap_height_px = font_size,
|
||||||
@@ -508,6 +513,19 @@ pub fn update(self: *Player, dt: f32, game: *Game) void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn formatHexCoord(coord: i32, buf: *[9]u8) []const u8 {
|
||||||
|
buf[0] = ' ';
|
||||||
|
const coord_abs = @abs(coord);
|
||||||
|
_ = std.fmt.bufPrint(buf[1..9], "{X:>8}", .{coord_abs}) catch unreachable;
|
||||||
|
|
||||||
|
if (coord < 0) {
|
||||||
|
const i = std.mem.findScalarLast(u8, buf, ' ') orelse unreachable;
|
||||||
|
buf[i] = '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf[0..];
|
||||||
|
}
|
||||||
|
|
||||||
fn resetAllButtons(self: *Player) void {
|
fn resetAllButtons(self: *Player) void {
|
||||||
inline for (@typeInfo(Player).@"struct".fields) |field| {
|
inline for (@typeInfo(Player).@"struct".fields) |field| {
|
||||||
if (field.type == Button) {
|
if (field.type == Button) {
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ pub fn init() !*Engine {
|
|||||||
.shader_float_16 = .true,
|
.shader_float_16 = .true,
|
||||||
.descriptor_indexing = .true,
|
.descriptor_indexing = .true,
|
||||||
.descriptor_binding_partially_bound = .true,
|
.descriptor_binding_partially_bound = .true,
|
||||||
.descriptor_binding_variable_descriptor_count = .true,
|
|
||||||
.runtime_descriptor_array = .true,
|
.runtime_descriptor_array = .true,
|
||||||
.scalar_block_layout = .true,
|
.scalar_block_layout = .true,
|
||||||
.imageless_framebuffer = .true,
|
.imageless_framebuffer = .true,
|
||||||
@@ -745,13 +744,11 @@ pub const DescriptorPoolCreateInfo = struct {
|
|||||||
pub const DescriptorSetAllocateInfo = struct {
|
pub const DescriptorSetAllocateInfo = struct {
|
||||||
descriptor_pool: vk.DescriptorPool,
|
descriptor_pool: vk.DescriptorPool,
|
||||||
set_layout: vk.DescriptorSetLayout,
|
set_layout: vk.DescriptorSetLayout,
|
||||||
variable_descriptor_count: ?u32 = null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DescriptorSetsAllocateInfo = struct {
|
pub const DescriptorSetsAllocateInfo = struct {
|
||||||
descriptor_pool: vk.DescriptorPool,
|
descriptor_pool: vk.DescriptorPool,
|
||||||
set_layouts: []const vk.DescriptorSetLayout,
|
set_layouts: []const vk.DescriptorSetLayout,
|
||||||
variable_descriptor_counts: []const u32 = &.{},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const DescriptorSetLayoutBinding = struct {
|
pub const DescriptorSetLayoutBinding = struct {
|
||||||
@@ -969,28 +966,13 @@ pub fn allocateDescriptorSet(self: *Engine, allocate_info: DescriptorSetAllocate
|
|||||||
try self.allocateDescriptorSets(.{
|
try self.allocateDescriptorSets(.{
|
||||||
.descriptor_pool = allocate_info.descriptor_pool,
|
.descriptor_pool = allocate_info.descriptor_pool,
|
||||||
.set_layouts = &.{allocate_info.set_layout},
|
.set_layouts = &.{allocate_info.set_layout},
|
||||||
.variable_descriptor_counts = if (allocate_info.variable_descriptor_count) |x| &.{x} else &.{},
|
|
||||||
}, &descriptor_sets);
|
}, &descriptor_sets);
|
||||||
return descriptor_sets[0];
|
return descriptor_sets[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocateDescriptorSets(self: *Engine, allocate_info: DescriptorSetsAllocateInfo, descriptor_sets: []vk.DescriptorSet) !void {
|
pub fn allocateDescriptorSets(self: *Engine, allocate_info: DescriptorSetsAllocateInfo, descriptor_sets: []vk.DescriptorSet) !void {
|
||||||
std.debug.assert(descriptor_sets.len >= allocate_info.set_layouts.len);
|
std.debug.assert(descriptor_sets.len >= allocate_info.set_layouts.len);
|
||||||
|
|
||||||
const has_variable_descriptor_counts = allocate_info.variable_descriptor_counts.len > 0;
|
|
||||||
|
|
||||||
var p_next: ?*const anyopaque = null;
|
|
||||||
|
|
||||||
if (has_variable_descriptor_counts) {
|
|
||||||
p_next = &vk.DescriptorSetVariableDescriptorCountAllocateInfo{
|
|
||||||
.p_next = p_next,
|
|
||||||
.descriptor_set_count = @intCast(allocate_info.variable_descriptor_counts.len),
|
|
||||||
.p_descriptor_counts = allocate_info.variable_descriptor_counts.ptr,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
try self.device.allocateDescriptorSets(&.{
|
try self.device.allocateDescriptorSets(&.{
|
||||||
.p_next = p_next,
|
|
||||||
.descriptor_pool = allocate_info.descriptor_pool,
|
.descriptor_pool = allocate_info.descriptor_pool,
|
||||||
.descriptor_set_count = @intCast(allocate_info.set_layouts.len),
|
.descriptor_set_count = @intCast(allocate_info.set_layouts.len),
|
||||||
.p_set_layouts = allocate_info.set_layouts.ptr,
|
.p_set_layouts = allocate_info.set_layouts.ptr,
|
||||||
|
|||||||
Reference in New Issue
Block a user