diff --git a/src/config.rs b/src/config.rs index 90c8aee..c23f294 100644 --- a/src/config.rs +++ b/src/config.rs @@ -102,7 +102,7 @@ impl Config { .help("Colors for rendering the mesh using the Phong reflection model. Requires 3 colors as rgb hex values: ambient, diffuse, and specular. Defaults to blue.") .short('m') .long("material") - .value_names(&["ambient","diffuse","specular"]) + .value_names(["ambient","diffuse","specular"]) ) .arg( clap::Arg::new("background") @@ -138,17 +138,21 @@ impl Config { .expect("IMG_FILE not provided"); match matches.get_one::("format") { Some(x) => c.format = match_format(x), - None => match Path::new(&c.img_filename).extension() { - Some(ext) => c.format = match_format(ext.to_str().unwrap()), - _ => (), - }, + None => { + if let Some(ext) = Path::new(&c.img_filename).extension() { + c.format = match_format(ext.to_str().unwrap()); + } + } }; - matches - .get_one::("size") - .map(|x| c.width = x.parse::().expect("Invalid size")); - matches - .get_one::("size") - .map(|x| c.height = x.parse::().expect("Invalid size")); + + if let Some(x) = matches.get_one::("size") { + c.width = x.parse::().expect("Invalid size"); + } + + if let Some(x) = matches.get_one::("size") { + c.height = x.parse::().expect("Invalid size"); + } + c.visible = matches.contains_id("visible"); c.verbosity = matches.get_count("verbosity") as usize; if let Some(materials) = matches.get_many::("material") { @@ -159,17 +163,16 @@ impl Config { specular: iter.next().unwrap_or([0.0, 0.0, 0.0]), }; } - matches - .get_one::("background") - .map(|x| c.background = html_to_rgba(x)); - match matches.get_one::("aamethod") { - Some(x) => match x.as_str() { + if let Some(x) = matches.get_one::("background") { + c.background = html_to_rgba(x); + } + if let Some(x) = matches.get_one::("aamethod") { + match x.as_str() { "none" => c.aamethod = AAMethod::None, "fxaa" => c.aamethod = AAMethod::FXAA, _ => unreachable!(), - }, - None => (), - }; + } + } c.recalc_normals = matches.contains_id("recalc_normals"); c diff --git a/src/fxaa.rs b/src/fxaa.rs index 42a71de..9dabbca 100644 --- a/src/fxaa.rs +++ b/src/fxaa.rs @@ -30,9 +30,9 @@ struct SpriteVertex { implement_vertex!(SpriteVertex, position, i_tex_coords); impl FxaaSystem { - pub fn new(facade: &F) -> FxaaSystem + pub fn new(facade: &F) -> FxaaSystem where - F: Facade, + F: Facade + ?Sized, { FxaaSystem { context: facade.get_context().clone(), @@ -63,7 +63,7 @@ impl FxaaSystem { index_buffer: glium::index::IndexBuffer::new( facade, glium::index::PrimitiveType::TriangleStrip, - &[1 as u16, 2, 0, 3], + &[1u16, 2, 0, 3], ) .unwrap(), @@ -92,7 +92,7 @@ where let mut target_depth = system.target_depth.borrow_mut(); { - let clear = if let &Some(ref tex) = &*target_color { + let clear = if let Some(ref tex) = *target_color { tex.get_width() != target_dimensions.0 || tex.get_height().unwrap() != target_dimensions.1 } else { @@ -104,7 +104,7 @@ where } { - let clear = if let &Some(ref tex) = &*target_depth { + let clear = if let Some(ref tex) = *target_depth { tex.get_dimensions() != target_dimensions } else { false @@ -117,8 +117,8 @@ where if target_color.is_none() { let texture = glium::texture::Texture2d::empty( &system.context, - target_dimensions.0 as u32, - target_dimensions.1 as u32, + target_dimensions.0, + target_dimensions.1, ) .unwrap(); *target_color = Some(texture); @@ -129,8 +129,8 @@ where let texture = glium::framebuffer::DepthRenderBuffer::new( &system.context, glium::texture::DepthFormat::I24, - target_dimensions.0 as u32, - target_dimensions.1 as u32, + target_dimensions.0, + target_dimensions.1, ) .unwrap(); *target_depth = Some(texture); @@ -143,7 +143,7 @@ where ); let uniforms = uniform! { - tex: &*target_color, + tex: target_color, enabled: if enabled { 1i32 } else { 0i32 }, resolution: (target_dimensions.0 as f32, target_dimensions.1 as f32) }; diff --git a/src/lib.rs b/src/lib.rs index 0495716..632328d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,11 +36,8 @@ const CAM_POSITION: cgmath::Point3 = cgmath::Point3 { }; fn print_matrix(m: [[f32; 4]; 4]) { - for i in 0..4 { - debug!( - "{:.3}\t{:.3}\t{:.3}\t{:.3}", - m[i][0], m[i][1], m[i][2], m[i][3] - ); + for row in &m { + debug!("{:.3}\t{:.3}\t{:.3}\t{:.3}", row[0], row[1], row[2], row[3]); } debug!(""); } @@ -175,7 +172,7 @@ where let pixel_shader_src = include_str!("shaders/model.frag"); // TODO: Cache program binary - let program = glium::Program::from_source(display, &vertex_shader_src, &pixel_shader_src, None); + let program = glium::Program::from_source(display, vertex_shader_src, pixel_shader_src, None); let program = match program { Ok(p) => p, Err(glium::CompilationError(err, _)) => { @@ -246,7 +243,7 @@ where target .draw( (&vertex_buf, &normal_buf), - &indices, + indices, &program, &uniforms, ¶ms, @@ -261,9 +258,8 @@ where let pixels: glium::texture::RawImage2d = texture.read(); let img = image::ImageBuffer::from_raw(config.width, config.height, pixels.data.into_owned()) .unwrap(); - let img = image::DynamicImage::ImageRgba8(img).flipv(); - img + image::DynamicImage::ImageRgba8(img).flipv() } pub fn render_to_window(config: Config) -> Result<(), Box> { @@ -292,13 +288,14 @@ pub fn render_to_window(config: Config) -> Result<(), Box> { .unwrap(); match ev { - glutin::event::Event::WindowEvent { event, .. } - if event == glutin::event::WindowEvent::CloseRequested => - { + glutin::event::Event::WindowEvent { + event: glutin::event::WindowEvent::CloseRequested, + .. + } => { *control_flow = ControlFlow::Exit; return; } - glutin::event::Event::NewEvents(cause) if cause == glutin::event::StartCause::Init => { + glutin::event::Event::NewEvents(glutin::event::StartCause::Init) => { render_pipeline(&display, &config, &mesh, &mut framebuffer, &texture); } _ => (), @@ -330,13 +327,11 @@ pub fn render_to_image(config: &Config) -> Result