diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics_window_dressing.rs | 2 | ||||
| -rw-r--r-- | src/linear_algebra.rs | 80 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/shader_data.rs | 82 |
4 files changed, 87 insertions, 81 deletions
diff --git a/src/graphics_window_dressing.rs b/src/graphics_window_dressing.rs index 27390e4..c1db68f 100644 --- a/src/graphics_window_dressing.rs +++ b/src/graphics_window_dressing.rs @@ -3,7 +3,7 @@ use crate::error::*; use crate::graphics_permanent::{ PermanentGraphicsState, GraphicsStateForReinit, QueueFamilyIndices }; -use crate::linear_algebra::{ Vertex, VERTICES, INDICES, UniformBlock }; +use crate::shader_data::{ VERTICES, INDICES, Vertex, UniformBlock }; use std::collections::BTreeSet; use std::io::Cursor; diff --git a/src/linear_algebra.rs b/src/linear_algebra.rs index 08e9306..acd949a 100644 --- a/src/linear_algebra.rs +++ b/src/linear_algebra.rs @@ -1,7 +1,6 @@ #![forbid(unsafe_code)] -use std::mem::{ size_of, MaybeUninit }; +use std::mem:: MaybeUninit; use std::ops::{ Add, Sub, Mul, Div, Neg }; -use vulkanalia::vk::{ self, HasBuilder }; pub trait Real: Add<Output=Self> + Sub<Output=Self> @@ -29,20 +28,6 @@ impl Real for f32 { } -pub static VERTICES: [Vertex<f32>; 4] = [ - Vertex::new(Vec2::new(-0.5, -0.5), Vec3::new(1.0, 0.0, 0.0), - Vec2::new(1.0, 0.0)), - Vertex::new(Vec2::new( 0.5, -0.5), Vec3::new(0.0, 1.0, 0.0), - Vec2::new(0.0, 0.0)), - Vertex::new(Vec2::new( 0.5, 0.5), Vec3::new(0.0, 0.0, 1.0), - Vec2::new(0.0, 1.0)), - Vertex::new(Vec2::new(-0.5, 0.5), Vec3::new(1.0, 1.0, 1.0), - Vec2::new(1.0, 1.0)), -]; - -pub const INDICES: &[u16] = &[0, 1, 2, 2, 3, 0]; - - #[repr(C)] #[derive(Clone, Debug)] pub struct Vec2<T: Copy>([T; 2]); @@ -618,66 +603,3 @@ impl<T: Copy> Transformation<T> { } } - - -#[repr(C)] -#[derive(Clone, Debug)] -pub struct Vertex<T: Copy> { - pub position: Vec2<T>, - pub color: Vec3<T>, - pub texture_coordinates: Vec2<T>, -} - -#[repr(C)] -#[derive(Clone, Debug)] -pub struct UniformBlock<T: Copy> { - pub scale: Vec3<T>, - pub model: Transformation<T>, - pub view: Transformation<T>, - pub projection: Mat4<T>, -} - -impl<T: Copy> Vertex<T> { - const fn new(position: Vec2<T>, color: Vec3<T>, - texture_coordinates: Vec2<T>) - -> Self - { - Self { position, color, texture_coordinates } - } - - pub fn binding_description() -> vk::VertexInputBindingDescription { - vk::VertexInputBindingDescription::builder() - .binding(0) - .stride(size_of::<Vertex<f32>>() as u32) - .input_rate(vk::VertexInputRate::VERTEX) - .build() - } - - pub fn attribute_descriptions() - -> [vk::VertexInputAttributeDescription; 3] - { - let position = vk::VertexInputAttributeDescription::builder() - .binding(0) - .location(0) - .format(vk::Format::R32G32_SFLOAT) - .offset(0) - .build(); - - let color = vk::VertexInputAttributeDescription::builder() - .binding(0) - .location(1) - .format(vk::Format::R32G32B32_SFLOAT) - .offset(size_of::<Vec2<f32>>() as u32) - .build(); - - let texture_coordinates = vk::VertexInputAttributeDescription::builder() - .binding(0) - .location(2) - .format(vk::Format::R32G32_SFLOAT) - .offset((size_of::<Vec2<f32>>() + size_of::<Vec3<f32>>()) as u32) - .build(); - - [position, color, texture_coordinates] - } -} - diff --git a/src/main.rs b/src/main.rs index e80e2be..2433a40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,8 @@ use crate::graphics_permanent::{ use crate::graphics_window_dressing::{ WindowDressing, N_SIMULTANEOUS_FRAMES }; -use crate::linear_algebra::{ Vec3, Vec4, Mat4, Transformation, UniformBlock }; +use crate::linear_algebra::{ Vec3, Vec4, Mat4, Transformation }; +use crate::shader_data::UniformBlock; use std::cell::RefCell; use std::f32::consts::{ FRAC_PI_2, FRAC_PI_4, TAU }; @@ -24,6 +25,7 @@ mod error; mod graphics_permanent; mod graphics_window_dressing; mod linear_algebra; +mod shader_data; struct Surreality { diff --git a/src/shader_data.rs b/src/shader_data.rs new file mode 100644 index 0000000..404d5fb --- /dev/null +++ b/src/shader_data.rs @@ -0,0 +1,82 @@ +#![forbid(unsafe_code)] +use crate::linear_algebra::{ Vec2, Vec3, Mat4, Transformation }; + +use std::mem::size_of; +use vulkanalia::vk::{ self, HasBuilder }; + + +pub static VERTICES: [Vertex<f32>; 4] = [ + Vertex::new(Vec2::new(-0.5, -0.5), Vec3::new(1.0, 0.0, 0.0), + Vec2::new(1.0, 0.0)), + Vertex::new(Vec2::new( 0.5, -0.5), Vec3::new(0.0, 1.0, 0.0), + Vec2::new(0.0, 0.0)), + Vertex::new(Vec2::new( 0.5, 0.5), Vec3::new(0.0, 0.0, 1.0), + Vec2::new(0.0, 1.0)), + Vertex::new(Vec2::new(-0.5, 0.5), Vec3::new(1.0, 1.0, 1.0), + Vec2::new(1.0, 1.0)), +]; + +pub const INDICES: &[u16] = &[0, 1, 2, 2, 3, 0]; + + +#[repr(C)] +#[derive(Clone, Debug)] +pub struct Vertex<T: Copy> { + pub position: Vec2<T>, + pub color: Vec3<T>, + pub texture_coordinates: Vec2<T>, +} + +#[repr(C)] +#[derive(Clone, Debug)] +pub struct UniformBlock<T: Copy> { + pub scale: Vec3<T>, + pub model: Transformation<T>, + pub view: Transformation<T>, + pub projection: Mat4<T>, +} + +impl<T: Copy> Vertex<T> { + const fn new(position: Vec2<T>, color: Vec3<T>, + texture_coordinates: Vec2<T>) + -> Self + { + Self { position, color, texture_coordinates } + } + + pub fn binding_description() -> vk::VertexInputBindingDescription { + vk::VertexInputBindingDescription::builder() + .binding(0) + .stride(size_of::<Vertex<f32>>() as u32) + .input_rate(vk::VertexInputRate::VERTEX) + .build() + } + + pub fn attribute_descriptions() + -> [vk::VertexInputAttributeDescription; 3] + { + let position = vk::VertexInputAttributeDescription::builder() + .binding(0) + .location(0) + .format(vk::Format::R32G32_SFLOAT) + .offset(0) + .build(); + + let color = vk::VertexInputAttributeDescription::builder() + .binding(0) + .location(1) + .format(vk::Format::R32G32B32_SFLOAT) + .offset(size_of::<Vec2<f32>>() as u32) + .build(); + + let texture_coordinates = vk::VertexInputAttributeDescription::builder() + .binding(0) + .location(2) + .format(vk::Format::R32G32_SFLOAT) + .offset((size_of::<Vec2<f32>>() + size_of::<Vec3<f32>>()) as u32) + .build(); + + [position, color, texture_coordinates] + } +} + |