switch to noise lib that works on arm neon (apple)
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
use crate::{
|
||||
client::camera::Camera,
|
||||
common::component::{ChunkMesh, ChunkPos}, util::oct_tree::OctTree,
|
||||
};
|
||||
|
||||
use super::{voxel::VoxelColor, Renderer};
|
||||
use bevy_ecs::entity::Entity;
|
||||
use nalgebra::{Rotation3, Vector3};
|
||||
use ndarray::Array3;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum RenderCommand {
|
||||
CreateVoxelGrid(CreateVoxelGrid),
|
||||
AddChunk(AddChunk),
|
||||
UpdateGridTransform(UpdateGridTransform),
|
||||
ViewUpdate(Camera),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CreateVoxelGrid {
|
||||
pub id: Entity,
|
||||
pub pos: Vector3<f32>,
|
||||
pub orientation: Rotation3<f32>,
|
||||
pub dimensions: Vector3<usize>,
|
||||
pub grid: Array3<VoxelColor>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AddChunk {
|
||||
pub id: Entity,
|
||||
pub pos: ChunkPos,
|
||||
pub mesh: ChunkMesh,
|
||||
pub tree: OctTree,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UpdateGridTransform {
|
||||
pub id: Entity,
|
||||
pub pos: Vector3<f32>,
|
||||
pub orientation: Rotation3<f32>,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn handle_commands(&mut self, commands: Vec<RenderCommand>) {
|
||||
let mut new_camera = false;
|
||||
for cmd in commands {
|
||||
match cmd {
|
||||
RenderCommand::CreateVoxelGrid(desc) => self.voxel_pipeline.add_group(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
desc,
|
||||
),
|
||||
RenderCommand::ViewUpdate(camera) => {
|
||||
new_camera = true;
|
||||
self.camera = camera;
|
||||
}
|
||||
RenderCommand::UpdateGridTransform(update) => self.voxel_pipeline.update_transform(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
update,
|
||||
),
|
||||
RenderCommand::AddChunk(desc) => self.voxel_pipeline.add_chunk(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
desc,
|
||||
),
|
||||
}
|
||||
}
|
||||
if new_camera {
|
||||
self.voxel_pipeline.update_view(
|
||||
&self.device,
|
||||
&mut self.encoder,
|
||||
&mut self.staging_belt,
|
||||
self.size,
|
||||
&self.camera,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
mod command;
|
||||
pub mod voxel;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use command::*;
|
||||
use vulkano::{
|
||||
device::{Device, DeviceCreateInfo, QueueCreateInfo, QueueFlags}, instance::{Instance, InstanceCreateInfo}, memory::allocator::StandardMemoryAllocator, VulkanLibrary
|
||||
};
|
||||
|
||||
use super::camera::Camera;
|
||||
use crate::client::rsc::CLEAR_COLOR;
|
||||
use nalgebra::Vector2;
|
||||
use voxel::VoxelPipeline;
|
||||
use winit::{dpi::PhysicalSize, window::Window};
|
||||
|
||||
pub struct Renderer {
|
||||
camera: Camera,
|
||||
}
|
||||
|
||||
impl Renderer {
|
||||
pub fn new(window: Arc<Window>) -> Self {
|
||||
let library = VulkanLibrary::new().expect("no local Vulkan library/DLL");
|
||||
let instance = Instance::new(library, InstanceCreateInfo::default())
|
||||
.expect("failed to create instance");
|
||||
let physical_device = instance
|
||||
.enumerate_physical_devices()
|
||||
.expect("could not enumerate devices")
|
||||
.next()
|
||||
.expect("no devices available");
|
||||
let queue_family_index = physical_device
|
||||
.queue_family_properties()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.position(|(_queue_family_index, queue_family_properties)| {
|
||||
queue_family_properties
|
||||
.queue_flags
|
||||
.contains(QueueFlags::GRAPHICS)
|
||||
})
|
||||
.expect("couldn't find a graphical queue family")
|
||||
as u32;
|
||||
|
||||
let (device, mut queues) = Device::new(
|
||||
physical_device,
|
||||
DeviceCreateInfo {
|
||||
// here we pass the desired queue family to use by index
|
||||
queue_create_infos: vec![QueueCreateInfo {
|
||||
queue_family_index,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.expect("failed to create device");
|
||||
|
||||
let queue = queues.next().unwrap();
|
||||
let memory_allocator = Arc::new(StandardMemoryAllocator::new_default(device.clone()));
|
||||
|
||||
Self {
|
||||
camera: Camera::default(),
|
||||
size: Vector2::new(size.width, size.height),
|
||||
voxel_pipeline: VoxelPipeline::new(&device, &config),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reset_shader(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn update_shader(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn draw(&mut self) {}
|
||||
|
||||
pub fn resize(&mut self, size: PhysicalSize<u32>) {
|
||||
self.size = Vector2::new(size.width, size.height);
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use vulkano::{buffer::{Buffer, BufferCreateInfo, BufferUsage}, memory::allocator::{AllocationCreateInfo, MemoryAllocator, MemoryTypeFilter}};
|
||||
|
||||
pub struct VoxelPipeline {
|
||||
|
||||
}
|
||||
|
||||
impl VoxelPipeline {
|
||||
pub fn init(memory_allocator: Arc<impl MemoryAllocator>) {
|
||||
let buffer = Buffer::from_data(
|
||||
memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::UNIFORM_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo {
|
||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||
..Default::default()
|
||||
},
|
||||
data,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user