Compare commits

..

No commits in common. "8a4909dced7b08cef835b175a83bac2b49856d0f" and "2bba6c8476ecbbbf027095db93c26961c2e2880b" have entirely different histories.

13 changed files with 37 additions and 43 deletions

View File

@ -9,8 +9,8 @@ use winit::{
use super::camera;
use crate::{
gfx,
voxel::{self, brickmap::BrickmapRenderer, VoxelRenderer},
gfx::{self, Renderer},
voxel,
};
pub struct App<'window> {
@ -82,7 +82,7 @@ impl<'window> App<'window> {
glam::uvec3(32, 32, 32),
);
let mut renderer = BrickmapRenderer::new(&self.render_ctx, &camera_controller)?;
let mut renderer = voxel::VoxelRenderer::new(&self.render_ctx, &camera_controller)?;
let mut cumulative_dt = 0.0;
let mut frames_accumulated = 0.0;

View File

@ -1,11 +1,13 @@
mod bind_group;
mod buffer;
mod context;
mod renderer;
mod texture;
pub use self::{
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
buffer::{BufferExt, BulkBufferBuilder},
context::Context,
renderer::Renderer,
texture::{Texture, TextureBuilder},
};

8
src/gfx/renderer.rs Normal file
View File

@ -0,0 +1,8 @@
use std::time::Duration;
use anyhow::Result;
pub trait Renderer {
fn update(&mut self, dt: &Duration, context: &super::Context) -> Result<()>;
fn render(&self, context: &super::Context) -> Result<()>;
}

View File

@ -1,9 +0,0 @@
mod brickgrid;
mod brickmap_cache;
mod manager;
mod renderer;
mod shading_table;
mod util;
pub use manager::BrickmapManager;
pub use renderer::BrickmapRenderer;

View File

@ -0,0 +1,7 @@
mod brickgrid;
mod brickmap;
mod brickmap_cache;
mod shading_table;
mod util;
pub use brickmap::BrickmapManager;

View File

@ -1,5 +1,5 @@
pub mod brickmap;
mod renderer;
pub mod brickworld;
mod voxel_renderer;
pub mod world;
pub use renderer::VoxelRenderer;
pub use voxel_renderer::*;

View File

@ -1,10 +0,0 @@
use std::time::Duration;
use anyhow::Result;
use crate::gfx::Context;
pub trait VoxelRenderer {
fn update(&mut self, dt: &Duration, context: &Context) -> Result<()>;
fn render(&self, context: &Context) -> Result<()>;
}

View File

@ -2,30 +2,24 @@ use std::time::Duration;
use anyhow::Result;
use crate::{
core, gfx,
voxel::{renderer::VoxelRenderer, world::WorldManager},
};
use super::BrickmapManager;
use crate::{core, gfx};
#[derive(Debug)]
pub struct BrickmapRenderer {
pub struct VoxelRenderer {
clear_color: wgpu::Color,
render_texture: gfx::Texture,
render_pipeline: wgpu::RenderPipeline,
brickmap_manager: BrickmapManager,
brickmap_manager: super::brickworld::BrickmapManager,
raycast_pipeline: wgpu::ComputePipeline,
raycast_bind_group: wgpu::BindGroup,
unpack_pipeline: wgpu::ComputePipeline,
unpack_bind_group: wgpu::BindGroup,
}
impl BrickmapRenderer {
impl VoxelRenderer {
pub fn new(context: &gfx::Context, camera_controller: &core::CameraController) -> Result<Self> {
log::info!("Creating render shader...");
// TODO: Load the shader better
let shader_descriptor = wgpu::include_wgsl!("../../../assets/shaders/shader.wgsl");
let shader_descriptor = wgpu::include_wgsl!("../../assets/shaders/shader.wgsl");
let shader = context.device.create_shader_module(shader_descriptor);
log::info!("Creating render texture...");
@ -70,7 +64,7 @@ impl BrickmapRenderer {
});
log::info!("Creating brickmap manager...");
let brickmap_manager = BrickmapManager::new(
let brickmap_manager = super::brickworld::BrickmapManager::new(
context,
glam::uvec3(512, 64, 512),
usize::pow(64, 3),
@ -80,8 +74,7 @@ impl BrickmapRenderer {
);
log::info!("Creating compute pipelines...");
// TODO: Load the shader better
let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/brickmap_upload.wgsl");
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")
@ -126,8 +119,7 @@ impl BrickmapRenderer {
entry_point: "compute",
});
// TODO: Load the shader better
let cs_descriptor = wgpu::include_wgsl!("../../../assets/shaders/voxel_volume.wgsl");
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")
@ -186,13 +178,17 @@ impl BrickmapRenderer {
})
}
pub fn update_brickmap(&mut self, context: &gfx::Context, world: &mut WorldManager) {
pub fn update_brickmap(
&mut self,
context: &gfx::Context,
world: &mut super::world::WorldManager,
) {
self.brickmap_manager
.process_feedback_buffer(context, world);
}
}
impl VoxelRenderer for BrickmapRenderer {
impl gfx::Renderer for VoxelRenderer {
fn render(&self, context: &gfx::Context) -> Result<()> {
let frame = context.surface.get_current_texture()?;
let view = frame