diff --git a/client/src/plugins/environment/systems/voxels/meshing_gpu.rs b/client/src/plugins/environment/systems/voxels/meshing_gpu.rs index 13c60c5..9b5462d 100644 --- a/client/src/plugins/environment/systems/voxels/meshing_gpu.rs +++ b/client/src/plugins/environment/systems/voxels/meshing_gpu.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; use bevy_app_compute::prelude::*; -use super::structure::{MeshBufferPool, SparseVoxelOctree}; +use super::structure::{CHUNK_SIZE, MeshBufferPool, SparseVoxelOctree}; #[repr(C)] #[derive(ShaderType, Copy, Clone, Default)] @@ -22,6 +22,11 @@ pub struct VertexGpu { pub uv: Vec2, } +const MAX_VOXELS: usize = (CHUNK_SIZE as usize) * (CHUNK_SIZE as usize) * (CHUNK_SIZE as usize); +const MAX_QUADS: usize = MAX_VOXELS * 6; +const MAX_VERTICES: usize = MAX_QUADS * 4; +const MAX_INDICES: usize = MAX_QUADS * 6; + #[derive(TypePath)] struct GreedyMeshingShader; @@ -38,10 +43,10 @@ pub struct GpuMeshingWorker; impl ComputeWorker for GpuMeshingWorker { fn build(world: &mut World) -> AppComputeWorker { AppComputeWorkerBuilder::new(world) - .add_storage("voxels", &[0u32; 1]) + .add_storage("voxels", &[0u32; MAX_VOXELS]) .add_uniform("params", &Params::default()) - .add_storage("vertices", &[VertexGpu::default(); 1]) - .add_storage("indices", &[0u32; 1]) + .add_storage("vertices", &[VertexGpu::default(); MAX_VERTICES]) + .add_storage("indices", &[0u32; MAX_INDICES]) .add_storage("counts", &[0u32; 2]) .add_pass::( [1, 1, 1],