From ec8c0c2cccc936962c6e5bec2f5b630543d01fec Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 6 Apr 2024 09:19:24 +0100 Subject: [PATCH] Move brickmap renderer into brickworld module --- src/core/app.rs | 4 +-- src/voxel/brickworld/mod.rs | 2 ++ src/voxel/{ => brickworld}/voxel_renderer.rs | 29 ++++++++++---------- src/voxel/mod.rs | 3 -- 4 files changed, 19 insertions(+), 19 deletions(-) rename src/voxel/{ => brickworld}/voxel_renderer.rs (92%) diff --git a/src/core/app.rs b/src/core/app.rs index 390f83f..c6cc69b 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -10,7 +10,7 @@ use winit::{ use super::camera; use crate::{ gfx::{self, Renderer}, - voxel, + voxel::{self, brickworld::BrickmapRenderer}, }; pub struct App<'window> { @@ -82,7 +82,7 @@ impl<'window> App<'window> { glam::uvec3(32, 32, 32), ); - let mut renderer = voxel::VoxelRenderer::new(&self.render_ctx, &camera_controller)?; + let mut renderer = BrickmapRenderer::new(&self.render_ctx, &camera_controller)?; let mut cumulative_dt = 0.0; let mut frames_accumulated = 0.0; diff --git a/src/voxel/brickworld/mod.rs b/src/voxel/brickworld/mod.rs index 274bef9..863b91e 100644 --- a/src/voxel/brickworld/mod.rs +++ b/src/voxel/brickworld/mod.rs @@ -3,5 +3,7 @@ mod brickmap; mod brickmap_cache; mod shading_table; mod util; +mod voxel_renderer; pub use brickmap::BrickmapManager; +pub use voxel_renderer::BrickmapRenderer; diff --git a/src/voxel/voxel_renderer.rs b/src/voxel/brickworld/voxel_renderer.rs similarity index 92% rename from src/voxel/voxel_renderer.rs rename to src/voxel/brickworld/voxel_renderer.rs index ebbde52..4eeced9 100644 --- a/src/voxel/voxel_renderer.rs +++ b/src/voxel/brickworld/voxel_renderer.rs @@ -2,24 +2,27 @@ use std::time::Duration; use anyhow::Result; -use crate::{core, gfx}; +use crate::{core, gfx, voxel::world::WorldManager}; + +use super::BrickmapManager; #[derive(Debug)] -pub struct VoxelRenderer { +pub struct BrickmapRenderer { clear_color: wgpu::Color, render_texture: gfx::Texture, render_pipeline: wgpu::RenderPipeline, - brickmap_manager: super::brickworld::BrickmapManager, + brickmap_manager: BrickmapManager, raycast_pipeline: wgpu::ComputePipeline, raycast_bind_group: wgpu::BindGroup, unpack_pipeline: wgpu::ComputePipeline, unpack_bind_group: wgpu::BindGroup, } -impl VoxelRenderer { +impl BrickmapRenderer { pub fn new(context: &gfx::Context, camera_controller: &core::CameraController) -> Result { log::info!("Creating render shader..."); - let shader_descriptor = wgpu::include_wgsl!("../../assets/shaders/shader.wgsl"); + // TODO: Load the shader better + let shader_descriptor = wgpu::include_wgsl!("../../../assets/shaders/shader.wgsl"); let shader = context.device.create_shader_module(shader_descriptor); log::info!("Creating render texture..."); @@ -64,7 +67,7 @@ impl VoxelRenderer { }); log::info!("Creating brickmap manager..."); - let brickmap_manager = super::brickworld::BrickmapManager::new( + let brickmap_manager = BrickmapManager::new( context, glam::uvec3(512, 64, 512), usize::pow(64, 3), @@ -74,7 +77,8 @@ impl VoxelRenderer { ); log::info!("Creating compute pipelines..."); - let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/brickmap_upload.wgsl"); + // TODO: Load the shader better + let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/brickmap_upload.wgsl"); let cs = context.device.create_shader_module(cs_descriptor); let unpack_layout = gfx::BindGroupLayoutBuilder::new() .with_label("GPU Unpack BGL") @@ -119,7 +123,8 @@ impl VoxelRenderer { entry_point: "compute", }); - let cs_descriptor = wgpu::include_wgsl!("../../assets/shaders/voxel_volume.wgsl"); + // TODO: Load the shader better + let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/voxel_volume.wgsl"); let cs = context.device.create_shader_module(cs_descriptor); let raycast_layout = gfx::BindGroupLayoutBuilder::new() .with_label("Voxel Raycast BGL") @@ -178,17 +183,13 @@ impl VoxelRenderer { }) } - pub fn update_brickmap( - &mut self, - context: &gfx::Context, - world: &mut super::world::WorldManager, - ) { + pub fn update_brickmap(&mut self, context: &gfx::Context, world: &mut WorldManager) { self.brickmap_manager .process_feedback_buffer(context, world); } } -impl gfx::Renderer for VoxelRenderer { +impl gfx::Renderer for BrickmapRenderer { fn render(&self, context: &gfx::Context) -> Result<()> { let frame = context.surface.get_current_texture()?; let view = frame diff --git a/src/voxel/mod.rs b/src/voxel/mod.rs index 8067e4d..cc86079 100644 --- a/src/voxel/mod.rs +++ b/src/voxel/mod.rs @@ -1,5 +1,2 @@ pub mod brickworld; -mod voxel_renderer; pub mod world; - -pub use voxel_renderer::*;