summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--shaders/shader.vert4
-rw-r--r--src/main.rs2
-rw-r--r--src/shader_data.rs39
3 files changed, 30 insertions, 15 deletions
diff --git a/shaders/shader.vert b/shaders/shader.vert
index b14c94b..c07575a 100644
--- a/shaders/shader.vert
+++ b/shaders/shader.vert
@@ -12,7 +12,7 @@ layout(binding = 0) uniform UniformBlock {
    mat4 projection;
 } uniform_block;
 
-layout(location = 0) in vec2 inPosition;
+layout(location = 0) in vec3 inPosition;
 layout(location = 1) in vec3 inColor;
 layout(location = 2) in vec2 inTextureCoordinate;
 
@@ -85,7 +85,7 @@ vec4 apply_all_transforms(vec3 position) {
 
 
 void main() {
-  gl_Position = apply_all_transforms(vec3(inPosition, 0.0));
+  gl_Position = apply_all_transforms(inPosition);
   fragmentColor = inColor;
   fragmentTextureCoordinate = inTextureCoordinate;
 }
diff --git a/src/main.rs b/src/main.rs
index 2433a40..478a179 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -292,7 +292,7 @@ fn render_uniforms(device: &Device, device_memory: &vk::DeviceMemory,
                   .rotate(&Vec3::new(0.0, 1.0, 0.0), time % TAU),
     translation: Vec3::new(0.0, 0.0, 0.0),
   };
-  let view = Transformation::look_at(&Vec3::new(0.0, -1.0, -2.0),
+  let view = Transformation::look_at(&Vec3::new(0.0, -2.0, -2.0),
                                      &Vec3::new(0.0, 0.0, 0.0),
                                      &Vec3::new(0.0, -1.0, 0.0));
   let aspect_ratio = extent.width as f32 / extent.height as f32;
diff --git a/src/shader_data.rs b/src/shader_data.rs
index 404d5fb..bd7ff82 100644
--- a/src/shader_data.rs
+++ b/src/shader_data.rs
@@ -5,24 +5,35 @@ 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),
+pub static VERTICES: [Vertex<f32>; 8] = [
+  Vertex::new(Vec3::new(-0.5, -0.5,  0.0), 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),
+  Vertex::new(Vec3::new( 0.5, -0.5,  0.0), 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),
+  Vertex::new(Vec3::new( 0.5,  0.5,  0.0), 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),
+  Vertex::new(Vec3::new(-0.5,  0.5,  0.0), Vec3::new(1.0, 1.0, 1.0),
+              Vec2::new(1.0, 1.0)),
+  Vertex::new(Vec3::new(-0.5, -0.5,  0.5), Vec3::new(1.0, 0.0, 0.0),
+              Vec2::new(1.0, 0.0)),
+  Vertex::new(Vec3::new( 0.5, -0.5,  0.5), Vec3::new(0.0, 1.0, 0.0),
+              Vec2::new(0.0, 0.0)),
+  Vertex::new(Vec3::new( 0.5,  0.5,  0.5), Vec3::new(0.0, 0.0, 1.0),
+              Vec2::new(0.0, 1.0)),
+  Vertex::new(Vec3::new(-0.5,  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];
+pub const INDICES: &[u16] = &[
+  0, 1, 2, 2, 3, 0,
+  4, 5, 6, 6, 7, 4,
+];
 
 
 #[repr(C)]
 #[derive(Clone, Debug)]
 pub struct Vertex<T: Copy> {
-  pub position: Vec2<T>,
+  pub position: Vec3<T>,
   pub color: Vec3<T>,
   pub texture_coordinates: Vec2<T>,
 }
@@ -37,7 +48,7 @@ pub struct UniformBlock<T: Copy> {
 }
 
 impl<T: Copy> Vertex<T> {
-  const fn new(position: Vec2<T>, color: Vec3<T>,
+  const fn new(position: Vec3<T>, color: Vec3<T>,
                texture_coordinates: Vec2<T>)
       -> Self
   {
@@ -55,25 +66,29 @@ impl<T: Copy> Vertex<T> {
   pub fn attribute_descriptions()
       -> [vk::VertexInputAttributeDescription; 3]
   {
+    let mut offset: usize = 0;
+
     let position = vk::VertexInputAttributeDescription::builder()
             .binding(0)
             .location(0)
-            .format(vk::Format::R32G32_SFLOAT)
-            .offset(0)
+            .format(vk::Format::R32G32B32_SFLOAT)
+            .offset(offset as u32)
             .build();
+    offset += size_of::<Vec3<f32>>();
 
     let color = vk::VertexInputAttributeDescription::builder()
             .binding(0)
             .location(1)
             .format(vk::Format::R32G32B32_SFLOAT)
-            .offset(size_of::<Vec2<f32>>() as u32)
+            .offset(offset as u32)
             .build();
+    offset += size_of::<Vec3<f32>>();
 
     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)
+            .offset(offset as u32)
             .build();
 
     [position, color, texture_coordinates]