cuboid and cube pipeline working
This commit is contained in:
parent
4494b68c26
commit
912659bb52
13 changed files with 230 additions and 162 deletions
src
71
src/scene.rs
71
src/scene.rs
|
@ -5,9 +5,7 @@ use anyhow::Result;
|
|||
use cgmath::{vec2, vec3, Vector3};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::app_data::AppData;
|
||||
use crate::buffer;
|
||||
|
@ -28,19 +26,26 @@ const MIN_CHUNK_SIZE: usize = CHUNK_SIZE / (2 as usize).pow(MAX_TREE_DEPTH as u3
|
|||
pub struct Scene {
|
||||
pub vertices: Vec<vertex::Vertex>,
|
||||
pub sized_vertices: Vec<vertex::SizedVertex>,
|
||||
pub indices: Vec<u32>,
|
||||
pub indices_cube: Vec<u32>,
|
||||
pub indices_cuboid: Vec<u32>,
|
||||
|
||||
pub vertex_buffer: vk::Buffer,
|
||||
pub vertex_buffer_memory: vk::DeviceMemory,
|
||||
pub vertex_buffer_cube: vk::Buffer,
|
||||
pub vertex_buffer_memory_cube: vk::DeviceMemory,
|
||||
|
||||
pub index_buffer: vk::Buffer,
|
||||
pub index_buffer_memory: vk::DeviceMemory,
|
||||
pub index_buffer_cube: vk::Buffer,
|
||||
pub index_buffer_memory_cube: vk::DeviceMemory,
|
||||
|
||||
pub vertex_buffer_cuboid: vk::Buffer,
|
||||
pub vertex_buffer_memory_cuboid: vk::DeviceMemory,
|
||||
|
||||
pub index_buffer_cuboid: vk::Buffer,
|
||||
pub index_buffer_memory_cuboid: vk::DeviceMemory,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
pub unsafe fn prepare_data(&mut self, instance: &vulkanalia::Instance, device: &vulkanalia::Device, data: &AppData) -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
let grid_size = CHUNK_SIZE as i32;
|
||||
let grid_size = 50; //CHUNK_SIZE as i32;
|
||||
|
||||
// todo store the chunks somewhere (or only use them as intermediary for neighbouthood calculation idc)
|
||||
let mut oct_tree = OctTree::create(CHUNK_SIZE)?;
|
||||
|
@ -62,40 +67,59 @@ impl Scene {
|
|||
|
||||
let oct_tree_iter = OctTreeIter::create(&oct_tree)?;
|
||||
for item in oct_tree_iter {
|
||||
let sized_index = self.sized_vertices.len();
|
||||
let index = self.vertices.len();
|
||||
match item {
|
||||
Some(cube) => {
|
||||
/*let cuboid = Cuboid {
|
||||
pos: cube.pos,
|
||||
color: cube.color,
|
||||
tex_coord: cube.tex_coord,
|
||||
size: Vector3 {x: 1.0, y: 1.0, z: 1.0},
|
||||
};
|
||||
cuboid.draw(&data.topology, index, self);*/
|
||||
cube.draw(&data.topology, index, self);
|
||||
|
||||
if (cube.pos.x + cube.pos.y) as usize % 2 == 0{
|
||||
/**/
|
||||
let cuboid = Cuboid {
|
||||
pos: cube.pos,
|
||||
color: cube.color,
|
||||
tex_coord: cube.tex_coord,
|
||||
size: Vector3 {x: 1.0, y: 1.0, z: 1.0},
|
||||
};
|
||||
cuboid.draw(&data.topology, sized_index, self);
|
||||
}
|
||||
else {
|
||||
cube.draw(&data.topology, index, self);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
(self.vertex_buffer, self.vertex_buffer_memory) = buffer::create_vertex_buffer(instance, device, &data, &self.vertices)?;
|
||||
(self.index_buffer, self.index_buffer_memory) = buffer::create_index_buffer(&instance, &device, &data, &self.indices)?;
|
||||
if self.vertices.len() != 0 {
|
||||
(self.vertex_buffer_cube, self.vertex_buffer_memory_cube) = buffer::create_vertex_buffer(instance, device, &data, &self.vertices)?;
|
||||
(self.index_buffer_cube, self.index_buffer_memory_cube) = buffer::create_index_buffer(&instance, &device, &data, &self.indices_cube)?;
|
||||
}
|
||||
|
||||
if self.sized_vertices.len() != 0 {
|
||||
(self.vertex_buffer_cuboid, self.vertex_buffer_memory_cuboid) = buffer::create_vertex_buffer(instance, device, &data, &self.sized_vertices)?;
|
||||
(self.index_buffer_cuboid, self.index_buffer_memory_cuboid) = buffer::create_index_buffer(&instance, &device, &data, &self.indices_cuboid)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
|
||||
pub unsafe fn destroy(&mut self, device: &vulkanalia::Device) {
|
||||
device.destroy_buffer(self.index_buffer, None);
|
||||
device.free_memory(self.index_buffer_memory, None);
|
||||
device.destroy_buffer(self.index_buffer_cube, None);
|
||||
device.free_memory(self.index_buffer_memory_cube, None);
|
||||
|
||||
device.destroy_buffer(self.vertex_buffer, None);
|
||||
device.free_memory(self.vertex_buffer_memory, None);
|
||||
device.destroy_buffer(self.vertex_buffer_cube, None);
|
||||
device.free_memory(self.vertex_buffer_memory_cube, None);
|
||||
|
||||
device.destroy_buffer(self.index_buffer_cuboid, None);
|
||||
device.free_memory(self.index_buffer_memory_cuboid, None);
|
||||
|
||||
device.destroy_buffer(self.vertex_buffer_cuboid, None);
|
||||
device.free_memory(self.vertex_buffer_memory_cuboid, None);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(non_snake_case)]
|
||||
struct OctTree {
|
||||
pub child_XYZ: Option<Rc<RefCell<Self>>>,
|
||||
pub child_xYZ: Option<Rc<RefCell<Self>>>,
|
||||
|
@ -110,6 +134,7 @@ struct OctTree {
|
|||
|
||||
size: usize,
|
||||
}
|
||||
#[warn(non_snake_case)]
|
||||
|
||||
impl OctTree {
|
||||
pub fn create(size: usize) -> Result<Self> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue