From fe8a47d14d6db496ded2d3ea6c8798671e43c02f Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Fri, 17 Jun 2022 20:18:06 +0200 Subject: [PATCH] Format state file --- src/main.rs | 13 +++++++++---- src/state.rs | 50 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/main.rs b/src/main.rs index 45f46e0..ec2220c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,19 @@ mod state; pub use state::State; -pub mod render; -pub mod meshs; pub mod input; +pub mod meshs; +pub mod render; -use simplelog::{TermLogger, LevelFilter, Config, TerminalMode, ColorChoice}; +use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode}; fn main() { - if let Err(err) = TermLogger::init(LevelFilter::Info, Config::default(), TerminalMode::Mixed, ColorChoice::Auto) { + if let Err(err) = TermLogger::init( + LevelFilter::Info, + Config::default(), + TerminalMode::Mixed, + ColorChoice::Auto, + ) { println!("Failed to start logger : {}", err); } diff --git a/src/state.rs b/src/state.rs index 6532a92..8a642c0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,12 +1,11 @@ -use crate::{meshs::DefaultMesh, render::{Renderable, TextureManager}, input::Controllable}; +use crate::{ + input::Controllable, + meshs::DefaultMesh, + render::{Renderable, TextureManager}, +}; -use super::render::{ - Vertex, Camera, Texture, InstanceRaw -}; -use winit::{ - event::WindowEvent, - window::Window, -}; +use super::render::{Camera, InstanceRaw, Texture, Vertex}; +use winit::{event::WindowEvent, window::Window}; pub struct State { pub surface: wgpu::Surface, @@ -80,19 +79,27 @@ impl State { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: Some("Shader"), - source: wgpu::ShaderSource::Wgsl(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/res/shaders/main.wgsl")).into()), + source: wgpu::ShaderSource::Wgsl( + include_str!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/shaders/main.wgsl" + )) + .into(), + ), }); let mut camera = Camera::new(config.width as f32, config.height as f32, 0.2); camera.initialize(&device); - let depth_texture = - Texture::create_depth_texture(&device, &config, "depth_texture"); + let depth_texture = Texture::create_depth_texture(&device, &config, "depth_texture"); let render_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Render Pipeline Layout"), - bind_group_layouts: &[&texture_manager.get_texture_bind_group_layout(), camera.get_bind_group_layout()], + bind_group_layouts: &[ + &texture_manager.get_texture_bind_group_layout(), + camera.get_bind_group_layout(), + ], push_constant_ranges: &[], }); @@ -143,14 +150,20 @@ impl State { let diffuse_bind_group = texture_manager.create_texture_from_bytes( &device, &queue, - include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/res/images/happy-tree.png")), + include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/images/happy-tree.png" + )), "happy-tree.png", ); let diffuse_bind_group_pikachu = texture_manager.create_texture_from_bytes( &device, &queue, - include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/res/images/pikachu.png")), + include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/res/images/pikachu.png" + )), "pikachu.png", ); @@ -167,7 +180,7 @@ impl State { camera, depth_texture, mesh, - texture_manager + texture_manager, } } @@ -178,11 +191,8 @@ impl State { self.config.height = new_size.height; self.surface.configure(&self.device, &self.config); } - self.depth_texture = Texture::create_depth_texture( - &self.device, - &self.config, - "depth_texture", - ); + self.depth_texture = + Texture::create_depth_texture(&self.device, &self.config, "depth_texture"); } pub fn input(&mut self, event: &WindowEvent) -> bool {