WebGPU Voxel Game

Refactor modules, resource cleanup

j0.lol 63a2f0c7 0cb5a99f

+2 -4
src/app.rs
··· 1 - mod gfx_state; 2 - 3 - use gfx_state::{Gfx, GfxBuilder, MaybeGfx}; 1 + use crate::gfx::{Gfx, GfxBuilder, MaybeGfx}; 4 2 use std::sync::Arc; 5 3 use winit::{ 6 4 application::ApplicationHandler, ··· 10 8 window::{Window, WindowAttributes, WindowId}, 11 9 }; 12 10 13 - const WASM_WIN_SIZE: (u32, u32) = (640, 480); 11 + pub(crate) const WASM_WIN_SIZE: (u32, u32) = (640, 480); 14 12 15 13 // TODO citation: 16 14 // https://github.com/Bentebent/rita/ for winit 29.0->30.0 migration
+10 -4
src/app/gfx_state.rs src/gfx.rs
··· 1 + mod camera; 2 + mod model; 3 + mod resources; 4 + mod texture; 5 + 1 6 use std::sync::Arc; 2 7 3 8 use glam::{vec3, Quat, Vec3}; ··· 5 10 use winit::{dpi::PhysicalSize, event::{ElementState, KeyEvent, WindowEvent}, event_loop::EventLoopProxy, keyboard::{KeyCode, PhysicalKey}, window::Window}; 6 11 7 12 use crate::{ 8 - app::WASM_WIN_SIZE, camera, model::{self, Vertex}, resources, texture, Instance, InstanceRaw, NUM_INSTANCES_PER_ROW 13 + app::WASM_WIN_SIZE, 14 + gfx::model::Vertex, Instance, InstanceRaw, NUM_INSTANCES_PER_ROW 9 15 }; 10 16 11 17 struct CameraState { ··· 165 171 let depth_texture = 166 172 texture::Texture::create_depth_texture(&device, &surface_config, "depth_texture"); 167 173 168 - let diffuse_bytes = include_bytes!("../happy-tree.png"); 174 + let diffuse_bytes = include_bytes!("../res/happy-tree.png"); 169 175 let diffuse_texture = 170 176 texture::Texture::from_bytes(&device, &queue, diffuse_bytes, "happy_tree.png").unwrap(); 171 177 ··· 285 291 286 292 let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { 287 293 label: Some("Shader"), 288 - source: wgpu::ShaderSource::Wgsl(include_str!("../shader.wgsl").into()), 294 + source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()), 289 295 }); 290 296 291 297 let render_pipeline_layout = ··· 433 439 &self.render_pipeline.0 434 440 }); 435 441 436 - use crate::model::DrawModel; 442 + use crate::gfx::model::DrawModel; 437 443 render_pass.draw_model_instanced( 438 444 &self.object.model, 439 445 0..self.object.instances.len() as u32,
src/camera.rs src/gfx/camera.rs
src/happy-tree.png res/happy-tree.png
+1 -4
src/lib.rs
··· 1 1 #![allow(rust_analyzer::inactive_code)] 2 2 3 - mod camera; 4 - mod model; 5 - mod resources; 6 - mod texture; 7 3 mod app; 4 + mod gfx; 8 5 9 6 use wasm_bindgen::UnwrapThrowExt; 10 7 use winit::{
+2 -1
src/model.rs src/gfx/model.rs
··· 1 - use crate::texture; 2 1 use std::ops::Range; 2 + 3 + use super::texture; 3 4 4 5 pub trait Vertex { 5 6 fn desc() -> wgpu::VertexBufferLayout<'static>;
+2 -1
src/resources.rs src/gfx/resources.rs
··· 1 - use crate::{model, texture}; 2 1 use cfg_if::cfg_if; 3 2 use std::error::Error; 4 3 use std::io::{BufReader, Cursor}; 5 4 use wgpu::util::DeviceExt; 5 + 6 + use super::{model, texture}; 6 7 7 8 #[cfg(target_arch = "wasm32")] 8 9 fn format_url(file_name: &str) -> reqwest::Url {
src/texture.rs src/gfx/texture.rs