You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.7 KiB

use ash::vk;
use cgmath::Matrix4;
use memoffset::offset_of;
pub struct DeviceExtension {
pub names: [&'static str; 1],
// pub raw_names: [*const i8; 1],
}
pub struct SurfaceStuff {
pub surface_loader: ash::extensions::khr::Surface,
pub surface: vk::SurfaceKHR,
pub screen_width: u32,
pub screen_height: u32,
}
pub struct SwapChainStuff {
pub swapchain_loader: ash::extensions::khr::Swapchain,
pub swapchain: vk::SwapchainKHR,
pub swapchain_images: Vec<vk::Image>,
pub swapchain_format: vk::Format,
pub swapchain_extent: vk::Extent2D,
}
pub struct SwapChainSupportDetail {
pub capabilities: vk::SurfaceCapabilitiesKHR,
pub formats: Vec<vk::SurfaceFormatKHR>,
pub present_modes: Vec<vk::PresentModeKHR>,
}
pub struct QueueFamilyIndices {
pub graphics_family: Option<u32>,
pub present_family: Option<u32>,
}
impl QueueFamilyIndices {
pub fn new() -> QueueFamilyIndices {
QueueFamilyIndices {
graphics_family: None,
present_family: None,
}
}
pub fn is_complete(&self) -> bool {
self.graphics_family.is_some() && self.present_family.is_some()
}
}
pub struct SyncObjects {
pub image_available_semaphores: Vec<vk::Semaphore>,
pub render_finished_semaphores: Vec<vk::Semaphore>,
pub inflight_fences: Vec<vk::Fence>,
}
#[repr(C)]
#[derive(Clone, Debug, Copy)]
pub struct UniformBufferObject {
pub model: Matrix4<f32>,
pub view: Matrix4<f32>,
pub proj: Matrix4<f32>,
}
#[repr(C)]
#[derive(Clone, Debug, Copy)]
pub struct VertexV1 {
pub pos: [f32; 2],
pub color: [f32; 3],
}
impl VertexV1 {
pub fn get_binding_description() -> [vk::VertexInputBindingDescription; 1] {
[vk::VertexInputBindingDescription {
binding: 0,
stride: ::std::mem::size_of::<VertexV1>() as u32,
input_rate: vk::VertexInputRate::VERTEX,
}]
}
pub fn get_attribute_descriptions() -> [vk::VertexInputAttributeDescription; 2] {
[
vk::VertexInputAttributeDescription {
binding: 0,
location: 0,
format: vk::Format::R32G32_SFLOAT,
offset: offset_of!(VertexV1, pos) as u32,
},
vk::VertexInputAttributeDescription {
binding: 0,
location: 1,
format: vk::Format::R32G32B32_SFLOAT,
offset: offset_of!(VertexV1, color) as u32,
},
]
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct VertexV3 {
pub pos: [f32; 4],
pub color: [f32; 4],
pub tex_coord: [f32; 2],
}
impl VertexV3 {
pub fn get_binding_descriptions() -> [vk::VertexInputBindingDescription; 1] {
[vk::VertexInputBindingDescription {
binding: 0,
stride: ::std::mem::size_of::<Self>() as u32,
input_rate: vk::VertexInputRate::VERTEX,
}]
}
pub fn get_attribute_descriptions() -> [vk::VertexInputAttributeDescription; 3] {
[
vk::VertexInputAttributeDescription {
binding: 0,
location: 0,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: offset_of!(Self, pos) as u32,
},
vk::VertexInputAttributeDescription {
binding: 0,
location: 1,
format: vk::Format::R32G32B32A32_SFLOAT,
offset: offset_of!(Self, color) as u32,
},
vk::VertexInputAttributeDescription {
binding: 0,
location: 2,
format: vk::Format::R32G32_SFLOAT,
offset: offset_of!(Self, tex_coord) as u32,
},
]
}
}