2022-12-25 17:18:11 +11:00
|
|
|
use crate::error;
|
|
|
|
use crate::vulkan_primitives::VulkanBuffer;
|
2023-01-10 14:54:54 +11:00
|
|
|
use ash::vk;
|
2022-12-25 17:18:11 +11:00
|
|
|
|
2022-12-22 14:03:38 +11:00
|
|
|
#[rustfmt::skip]
|
2023-01-10 16:11:05 +11:00
|
|
|
pub(crate) static VBO_DEFAULT_FINAL: &[f32; 16] = &[
|
2022-12-11 17:06:28 +11:00
|
|
|
// Final
|
2022-12-22 14:03:38 +11:00
|
|
|
0.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 1.0,
|
|
|
|
1.0, 0.0, 1.0, 0.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0,
|
2022-12-11 17:06:28 +11:00
|
|
|
];
|
2022-12-25 17:18:11 +11:00
|
|
|
|
|
|
|
pub struct DrawQuad {
|
|
|
|
buffer: VulkanBuffer,
|
2023-01-10 14:54:54 +11:00
|
|
|
device: ash::Device,
|
2022-12-25 17:18:11 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl DrawQuad {
|
2023-01-10 14:54:54 +11:00
|
|
|
pub fn new(
|
|
|
|
device: &ash::Device,
|
|
|
|
mem_props: &vk::PhysicalDeviceMemoryProperties,
|
|
|
|
) -> error::Result<DrawQuad> {
|
|
|
|
let mut buffer = VulkanBuffer::new(
|
|
|
|
device,
|
|
|
|
mem_props,
|
|
|
|
vk::BufferUsageFlags::VERTEX_BUFFER,
|
2023-01-12 10:04:35 +11:00
|
|
|
std::mem::size_of::<[f32; 16]>(),
|
2023-01-10 14:54:54 +11:00
|
|
|
)?;
|
2022-12-25 17:18:11 +11:00
|
|
|
|
|
|
|
{
|
|
|
|
let mut map = buffer.map()?;
|
|
|
|
unsafe {
|
2023-01-12 10:04:35 +11:00
|
|
|
map.copy_from(0, bytemuck::cast_slice(VBO_DEFAULT_FINAL));
|
2022-12-25 17:18:11 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(DrawQuad {
|
|
|
|
buffer,
|
2023-01-10 14:54:54 +11:00
|
|
|
device: device.clone(),
|
2022-12-25 17:18:11 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-13 17:48:04 +11:00
|
|
|
pub fn bind_vbo(&self, cmd: vk::CommandBuffer) {
|
2022-12-25 17:18:11 +11:00
|
|
|
unsafe {
|
2023-01-13 13:29:42 +11:00
|
|
|
self.device
|
|
|
|
.cmd_bind_vertex_buffers(cmd, 0, &[self.buffer.handle], &[0])
|
2022-12-25 17:18:11 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|