1
0
Fork 0

Format state file

This commit is contained in:
Florian RICHER 2022-06-17 20:18:06 +02:00
parent 5e22cf2310
commit fe8a47d14d
2 changed files with 39 additions and 24 deletions

View file

@ -1,14 +1,19 @@
mod state; mod state;
pub use state::State; pub use state::State;
pub mod render;
pub mod meshs;
pub mod input; 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() { 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); println!("Failed to start logger : {}", err);
} }

View file

@ -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::{ use super::render::{Camera, InstanceRaw, Texture, Vertex};
Vertex, Camera, Texture, InstanceRaw use winit::{event::WindowEvent, window::Window};
};
use winit::{
event::WindowEvent,
window::Window,
};
pub struct State { pub struct State {
pub surface: wgpu::Surface, pub surface: wgpu::Surface,
@ -80,19 +79,27 @@ impl State {
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
label: Some("Shader"), 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); let mut camera = Camera::new(config.width as f32, config.height as f32, 0.2);
camera.initialize(&device); camera.initialize(&device);
let depth_texture = let depth_texture = Texture::create_depth_texture(&device, &config, "depth_texture");
Texture::create_depth_texture(&device, &config, "depth_texture");
let render_pipeline_layout = let render_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Render Pipeline Layout"), 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: &[], push_constant_ranges: &[],
}); });
@ -143,14 +150,20 @@ impl State {
let diffuse_bind_group = texture_manager.create_texture_from_bytes( let diffuse_bind_group = texture_manager.create_texture_from_bytes(
&device, &device,
&queue, &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", "happy-tree.png",
); );
let diffuse_bind_group_pikachu = texture_manager.create_texture_from_bytes( let diffuse_bind_group_pikachu = texture_manager.create_texture_from_bytes(
&device, &device,
&queue, &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", "pikachu.png",
); );
@ -167,7 +180,7 @@ impl State {
camera, camera,
depth_texture, depth_texture,
mesh, mesh,
texture_manager texture_manager,
} }
} }
@ -178,11 +191,8 @@ impl State {
self.config.height = new_size.height; self.config.height = new_size.height;
self.surface.configure(&self.device, &self.config); self.surface.configure(&self.device, &self.config);
} }
self.depth_texture = Texture::create_depth_texture( self.depth_texture =
&self.device, Texture::create_depth_texture(&self.device, &self.config, "depth_texture");
&self.config,
"depth_texture",
);
} }
pub fn input(&mut self, event: &WindowEvent) -> bool { pub fn input(&mut self, event: &WindowEvent) -> bool {