diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 3acd09b085..468314e232 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -1,4 +1,4 @@ -use crate::ui::{BlankGraphic, ImageGraphic, VoxelGraphic}; +use crate::ui::img_ids::{BlankGraphic, ImageGraphic, VoxelGraphic, VoxelMs9Graphic}; image_ids! { pub struct Imgs { @@ -8,6 +8,8 @@ image_ids! { inv_grid: "/voxygen/element/frames/inv_grid.vox", inv_slot: "/voxygen/element/buttons/inv_slot.vox", + + // Buttons mmap_closed: "/voxygen/element/buttons/button_mmap_closed.vox", mmap_closed_hover: "/voxygen/element/buttons/button_mmap_closed_hover.vox", @@ -52,6 +54,8 @@ image_ids! { button_hover: "/voxygen/element/buttons/button_hover.vox", button_press: "/voxygen/element/buttons/button_press.vox", + + // MiniMap mmap_frame: "/voxygen/element/frames/mmap.vox", mmap_frame_closed: "/voxygen/element/frames/mmap_closed.vox", diff --git a/voxygen/src/ui/graphic/graphic.rs b/voxygen/src/ui/graphic/graphic.rs index 38b80a08e4..71748def81 100644 --- a/voxygen/src/ui/graphic/graphic.rs +++ b/voxygen/src/ui/graphic/graphic.rs @@ -7,7 +7,7 @@ use vek::*; pub enum Graphic { Image(Arc), - Voxel(Arc), + Voxel(Arc, Option), Blank, } @@ -94,9 +94,8 @@ impl GraphicCache { .pixels() .map(|p| p.data) .collect::>(), - Graphic::Voxel(ref vox) => { - super::renderer::draw_vox(&vox.as_ref().into(), aabr.size().into()) - } + Graphic::Voxel(ref vox, min_samples) => + super::renderer::draw_vox(&vox.as_ref().into(), aabr.size().into(), *min_samples), Graphic::Blank => return None, }; diff --git a/voxygen/src/ui/graphic/renderer.rs b/voxygen/src/ui/graphic/renderer.rs index 54945f8b96..ec3118e496 100644 --- a/voxygen/src/ui/graphic/renderer.rs +++ b/voxygen/src/ui/graphic/renderer.rs @@ -4,6 +4,7 @@ use common::{ vol::{ReadVol, SizedVol, Vox}, }; use euc::{buffer::Buffer2d, rasterizer, Pipeline}; +use image::{DynamicImage, RgbaImage}; use vek::*; struct Voxel { @@ -56,8 +57,13 @@ impl<'a> Pipeline for Voxel { } } -pub fn draw_vox(segment: &Segment, output_size: Vec2) -> Vec<[u8; 4]> { - let dims = output_size.map(|e| e as usize).into_array(); +pub fn draw_vox( + segment: &Segment, + output_size: Vec2, + min_samples: Option, +) -> Vec<[u8; 4]> { + let scale = min_samples.map_or(1.0, |s| s as f32).sqrt().ceil() as usize; + let dims = output_size.map(|e| e as usize * scale).into_array(); let mut color = Buffer2d::new(dims, [0; 4]); let mut depth = Buffer2d::new(dims, 1.0); @@ -79,8 +85,33 @@ pub fn draw_vox(segment: &Segment, output_size: Vec2) -> Vec<[u8; 4]> { &mut depth, ); - // TODO: remove this clone - color.as_ref().to_vec() + if scale > 1 { + DynamicImage::ImageRgba8( + RgbaImage::from_vec( + dims[0] as u32, + dims[1] as u32, + color + .as_ref() + .iter() + .flatten() + .cloned() + .collect::>(), + ) + .unwrap(), + ) + .resize_exact( + output_size.x as u32, + output_size.y as u32, + image::FilterType::Triangle, + ) + .to_rgba() + .pixels() + .map(|p| p.data) + .collect::>() + } else { + // TODO: remove clone + color.as_ref().to_vec() + } } fn ao_level(side1: bool, corner: bool, side2: bool) -> u8 { diff --git a/voxygen/src/ui/img_ids.rs b/voxygen/src/ui/img_ids.rs index 04167078d6..4107d4e990 100644 --- a/voxygen/src/ui/img_ids.rs +++ b/voxygen/src/ui/img_ids.rs @@ -3,9 +3,8 @@ use common::assets::{load, Error}; use dot_vox::DotVoxData; use image::DynamicImage; -pub struct BlankGraphic; -pub struct ImageGraphic; -pub struct VoxelGraphic; +pub enum BlankGraphic {} +pub enum ImageGraphic {} pub trait GraphicCreator<'a> { type Specifier; @@ -23,10 +22,37 @@ impl<'a> GraphicCreator<'a> for ImageGraphic { Ok(Graphic::Image(load::(specifier)?)) } } + +pub enum VoxelGraphic {} +pub enum VoxelMsGraphic {} +pub enum VoxelMs4Graphic {} +pub enum VoxelMs9Graphic {} + impl<'a> GraphicCreator<'a> for VoxelGraphic { type Specifier = &'a str; fn new_graphic(specifier: Self::Specifier) -> Result { - Ok(Graphic::Voxel(load::(specifier)?)) + Ok(Graphic::Voxel(load::(specifier)?, None)) + } +} +impl<'a> GraphicCreator<'a> for VoxelMsGraphic { + type Specifier = (&'a str, u8); + fn new_graphic(specifier: Self::Specifier) -> Result { + Ok(Graphic::Voxel( + load::(specifier.0)?, + Some(specifier.1), + )) + } +} +impl<'a> GraphicCreator<'a> for VoxelMs4Graphic { + type Specifier = &'a str; + fn new_graphic(specifier: Self::Specifier) -> Result { + Ok(Graphic::Voxel(load::(specifier)?, Some(4))) + } +} +impl<'a> GraphicCreator<'a> for VoxelMs9Graphic { + type Specifier = &'a str; + fn new_graphic(specifier: Self::Specifier) -> Result { + Ok(Graphic::Voxel(load::(specifier)?, Some(9))) } } @@ -59,7 +85,7 @@ macro_rules! image_ids { impl $Ids { pub fn load(ui: &mut crate::ui::Ui) -> Result { - use crate::ui::GraphicCreator; + use crate::ui::img_ids::GraphicCreator; Ok(Self { $($( $name: ui.add_graphic(<$T>::new_graphic($specifier)?), )*)* }) diff --git a/voxygen/src/ui/mod.rs b/voxygen/src/ui/mod.rs index 43c6000cf9..f151142e53 100644 --- a/voxygen/src/ui/mod.rs +++ b/voxygen/src/ui/mod.rs @@ -5,13 +5,12 @@ mod scale; mod util; mod widgets; #[macro_use] -mod img_ids; +pub mod img_ids; #[macro_use] mod font_ids; pub use event::Event; pub use graphic::Graphic; -pub use img_ids::{BlankGraphic, GraphicCreator, ImageGraphic, VoxelGraphic}; pub use scale::ScaleMode; pub use widgets::toggle_button::ToggleButton; @@ -315,8 +314,8 @@ impl Ui { srgb_to_linear(color.unwrap_or(conrod_core::color::WHITE).to_fsa().into()); let resolution = Vec2::new( - (rect.w() * p_scale_factor) as u16, - (rect.h() * p_scale_factor) as u16, + (rect.w() * p_scale_factor).round() as u16, + (rect.h() * p_scale_factor).round() as u16, ); // Transform the source rectangle into uv coordinate // TODO: make sure this is right