use vulkano::{buffer::BufferContents, pipeline::graphics::vertex_input::Vertex};
#[derive(BufferContents, Vertex, Debug)]
#[repr(C)]
pub(crate) struct VertexData {
#[format(R32_UINT)]
pub(crate) entity_id: u32,
#[format(R32G32B32_SFLOAT)]
pub(crate) position: [f32; 3],
}
impl VertexData {
pub(crate) fn new(entity_id: u32, position: [f32; 3]) -> Self {
VertexData {
entity_id,
position,
}
}
}
#[derive(BufferContents, Vertex, Debug)]
#[repr(C)]
pub(crate) struct ColorVertexData {
#[format(R32G32B32A32_SFLOAT)]
pub(crate) color: [f32; 4],
}
impl ColorVertexData {
pub(crate) fn new(color: [f32; 4]) -> Self {
ColorVertexData {
color,
}
}
}
#[derive(Debug, Clone, Vertex, BufferContents)]
#[repr(C)]
pub(crate) struct TransformVertexData {
#[format(R32G32B32A32_SFLOAT)]
pub(crate) vertex_matrix0: [f32 ; 4],
#[format(R32G32B32A32_SFLOAT)]
pub(crate) vertex_matrix1: [f32 ; 4],
#[format(R32G32B32A32_SFLOAT)]
pub(crate) vertex_matrix2: [f32 ; 4],
#[format(R32G32B32A32_SFLOAT)]
pub(crate) vertex_matrix3: [f32 ; 4],
}
impl TransformVertexData {
pub(crate) fn new() -> Self {
TransformVertexData {
vertex_matrix0: [1.0, 0.0, 0.0, 0.0],
vertex_matrix1: [0.0, 1.0, 0.0, 0.0],
vertex_matrix2: [0.0, 0.0, 1.0, 0.0],
vertex_matrix3: [0.0, 0.0, 0.0, 1.0],
}
}
}
#[derive(Debug, Clone, BufferContents)]
#[repr(C)]
pub(crate) struct GeneralData {
pub(crate) projection_matrix: [f32 ; 16],
pub(crate) view_matrix: [f32 ; 16],
pub(crate) resolution: [f32 ; 2],
pub(crate) time: f32,
}
impl GeneralData {
pub(crate) fn from_resolution(inner_size: [f32 ; 2]) -> Self {
GeneralData {
projection_matrix: [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
],
view_matrix: [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
],
resolution: inner_size,
time: 0.0,
}
}
}
impl Default for GeneralData {
fn default() -> Self {
GeneralData {
projection_matrix: [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
],
view_matrix: [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
],
resolution: [1.0, 1.0],
time: 0.0,
}
}
}
#[derive(Debug, Clone, BufferContents)]
#[repr(C)]
pub(crate) struct EntityData {
pub(crate) model_matrix: [f32 ; 16],
}
impl EntityData {
pub(crate) fn new() -> Self {
EntityData {
model_matrix: [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
],
}
}
}