Commit ef82dfcd authored by Matt Keeler's avatar Matt Keeler Committed by Peter van der meulen

Scale padding with DPR

parent 1051d990
......@@ -147,7 +147,7 @@ impl Display {
.expect("glutin returns window size").to_physical(dpr);
// Create renderer
let mut renderer = QuadRenderer::new(config, viewport_size)?;
let mut renderer = QuadRenderer::new(config, viewport_size, dpr)?;
let (glyph_cache, cell_width, cell_height) =
Self::new_glyph_cache(dpr, &mut renderer, config)?;
......@@ -162,11 +162,11 @@ impl Display {
let height = cell_height as u32 * dimensions.lines_u32();
let new_viewport_size = PhysicalSize::new(
(width + 2 * u32::from(config.padding().x)) as f64,
(height + 2 * u32::from(config.padding().y)) as f64);
(width + 2 * u32::from(config.padding().x) * dpr.floor() as u32) as f64,
(height + 2 * u32::from(config.padding().y) * dpr.floor() as u32) as f64);
window.set_inner_size(new_viewport_size.to_logical(dpr));
renderer.resize(new_viewport_size);
renderer.resize(new_viewport_size, dpr);
viewport_size = new_viewport_size;
}
......@@ -178,8 +178,8 @@ impl Display {
height: viewport_size.height as f32,
cell_width: cell_width as f32,
cell_height: cell_height as f32,
padding_x: f32::from(config.padding().x),
padding_y: f32::from(config.padding().y),
padding_x: f32::from(config.padding().x) * dpr as f32,
padding_y: f32::from(config.padding().y) * dpr as f32,
};
// Channel for resize events
......@@ -296,6 +296,8 @@ impl Display {
if terminal.font_size != self.font_size || dpr != self.size_info.dpr {
self.font_size = terminal.font_size;
self.size_info.dpr = dpr;
self.size_info.padding_x = f32::from(config.padding().x) * dpr as f32;
self.size_info.padding_y = f32::from(config.padding().y) * dpr as f32;
self.update_glyph_cache(config);
if new_size == None {
......@@ -320,7 +322,7 @@ impl Display {
}
self.window.resize(psize);
self.renderer.resize(psize);
self.renderer.resize(psize, dpr);
}
}
......
......@@ -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();
}
}
......@@ -961,7 +961,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
......@@ -1025,21 +1026,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;
}
......@@ -1051,8 +1052,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.,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment