makes geometry shader an option
This commit is contained in:
parent
5c971d0288
commit
a9d4aae1bc
10 changed files with 171 additions and 109 deletions
src
112
src/scene.rs
112
src/scene.rs
|
@ -1,3 +1,5 @@
|
|||
use std::thread::yield_now;
|
||||
|
||||
use vulkanalia::prelude::v1_0::*;
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
|
@ -6,6 +8,7 @@ use cgmath::{vec2, vec3, Matrix, SquareMatrix};
|
|||
use crate::app_data::AppData;
|
||||
use crate::buffer;
|
||||
use crate::vertex;
|
||||
use crate::primitives::cube::Cube;
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Scene {
|
||||
|
@ -28,110 +31,13 @@ impl Scene {
|
|||
for x_index in -grid_size..grid_size {
|
||||
for y_index in -grid_size..grid_size {
|
||||
let index = self.vertices.len();
|
||||
// 0 top left far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 1 top right far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 2 top left near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 3 top right near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
let cube = Cube {
|
||||
pos: vec3(x_index as f32, y_index as f32, 0.0),
|
||||
color: vec3(0.0, 1.0, 0.0),
|
||||
tex_coord: vec2(0.0, 0.0)
|
||||
};
|
||||
|
||||
// 4 bottom left far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 5 bottom right far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 6 bottom left near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 7 bottom right near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
|
||||
|
||||
// top
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 2);
|
||||
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 0);
|
||||
|
||||
// bottom
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// left
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 2);
|
||||
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 2);
|
||||
self.indices.push(index as u32 + 4);
|
||||
|
||||
// right
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 5);
|
||||
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// near
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 2);
|
||||
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// far
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 4);
|
||||
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 1);
|
||||
cube.draw(&vk::PrimitiveTopology::TRIANGLE_LIST, index, self);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue