diff options
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r-- | src/renderer/mod.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index b0f03645..c260f64d 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -479,8 +479,8 @@ const ATLAS_SIZE: i32 = 1024; impl QuadRenderer { // TODO should probably hand this a transform instead of width/height - pub fn new(config: &Config, size: PhysicalSize) -> Result<QuadRenderer, Error> { - let program = ShaderProgram::new(config, size)?; + pub fn new(config: &Config, size: PhysicalSize, dpr: f64) -> Result<QuadRenderer, Error> { + let program = ShaderProgram::new(config, size, dpr)?; let mut vao: GLuint = 0; let mut vbo: GLuint = 0; @@ -639,7 +639,7 @@ impl QuadRenderer { while let Ok(msg) = self.rx.try_recv() { match msg { Msg::ShaderReload => { - self.reload_shaders(config, PhysicalSize::new(props.width as f64, props.height as f64)); + self.reload_shaders(config, PhysicalSize::new(props.width as f64, props.height as f64), props.dpr); } } } @@ -690,9 +690,9 @@ impl QuadRenderer { }) } - pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize) { + pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize, dpr: f64) { warn!("Reloading shaders ..."); - let program = match ShaderProgram::new(config, size) { + let program = match ShaderProgram::new(config, size, dpr) { Ok(program) => { warn!(" ... OK"); program @@ -718,11 +718,11 @@ impl QuadRenderer { self.program = program; } - pub fn resize(&mut self, size: PhysicalSize) { + pub fn resize(&mut self, size: PhysicalSize, dpr: f64) { let (width, height) : (u32, u32) = size.into(); - let padding_x = i32::from(self.program.padding_x); - let padding_y = i32::from(self.program.padding_y); + let padding_x = (self.program.padding_x as f64 * dpr).floor() as i32; + let padding_y = (self.program.padding_y as f64 * dpr).floor() as i32; // viewport unsafe { @@ -731,7 +731,7 @@ impl QuadRenderer { // update projection self.program.activate(); - self.program.update_projection(width as f32, height as f32); + self.program.update_projection(width as f32, height as f32, dpr as f32); self.program.deactivate(); } } @@ -955,7 +955,8 @@ impl ShaderProgram { pub fn new( config: &Config, - size: PhysicalSize + size: PhysicalSize, + dpr: f64 ) -> Result<ShaderProgram, ShaderCreationError> { let vertex_source = if cfg!(feature = "live-shader-reload") { None @@ -1019,21 +1020,21 @@ impl ShaderProgram { u_cell_dim: cell_dim, u_visual_bell: visual_bell, u_background: background, - padding_x: config.padding().x, - padding_y: config.padding().y, + padding_x: u8::from(config.padding().x), + padding_y: u8::from(config.padding().y), }; - shader.update_projection(size.width as f32, size.height as f32); + shader.update_projection(size.width as f32, size.height as f32, dpr as f32); shader.deactivate(); Ok(shader) } - fn update_projection(&self, width: f32, height: f32) { + fn update_projection(&self, width: f32, height: f32, dpr: f32) { // Bounds check - if (width as u32) < (2 * u32::from(self.padding_x)) || - (height as u32) < (2 * u32::from(self.padding_y)) + if (width as u32) < (2 * (self.padding_x as f32 * dpr).floor() as u32) || + (height as u32) < (2 * (self.padding_y as f32 * dpr).floor() as u32) { return; } @@ -1045,8 +1046,8 @@ impl ShaderProgram { // correctly. let ortho = cgmath::ortho( 0., - width - 2. * f32::from(self.padding_x), - 2. * f32::from(self.padding_y), + width - (2. * f32::from(self.padding_x) * dpr), + 2. * f32::from(self.padding_y) * dpr, height, -1., 1., |