Implemented simple terrain generation

This commit is contained in:
Lorenzo Torres 2025-08-13 21:16:42 +02:00
parent fb9607b2b1
commit c0b8d021d4
16 changed files with 825 additions and 32 deletions

View file

@ -162,7 +162,12 @@ pub fn transitionImageLayout(self: Self, image: c.VkImage, format: c.VkFormat, o
try self.endSingleTimeCommands(command_buffer);
}
pub fn drawTerrain(self: Self, indices: u32, frame: usize, vertex_buffer: vk.Buffer, index_buffer: vk.Buffer) void {
std.debug.assert(frame < frames_in_flight);
c.vkCmdBindIndexBuffer(self.command_buffers[frame], index_buffer.handle, 0, c.VK_INDEX_TYPE_UINT32);
self.bindVertexBuffer(vertex_buffer, frame);
c.vkCmdDrawIndexed(self.command_buffers[frame], indices, 1, 0, 0, 0);
}
pub fn draw(self: Self, indices: u32, frame: usize, mesh: Mesh) void {
std.debug.assert(frame < frames_in_flight);
@ -210,6 +215,11 @@ pub fn bindDescriptorSets(self: Self, pipeline: vk.GraphicsPipeline, frame: usiz
c.vkCmdBindDescriptorSets(self.command_buffers[frame], c.VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 2, sets[0..].ptr, 0, null);
}
pub fn bindTerrainSets(self: Self, pipeline: vk.TerrainPipeline, frame: usize) void {
const sets = [_]c.VkDescriptorSet {pipeline.descriptor_set, pipeline.heightmap};
c.vkCmdBindDescriptorSets(self.command_buffers[frame], c.VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.layout, 0, 2, sets[0..].ptr, 0, null);
}
pub fn updateBuffer(self: Self, comptime T: type, buffer: vk.Buffer, data: [*]T, frame: usize) void {
c.vkCmdUpdateBuffer(self.command_buffers[frame], buffer.handle, 0, @sizeOf(T), @ptrCast(@alignCast(data)));
}