diff --git a/wezterm-gui/src/renderstate.rs b/wezterm-gui/src/renderstate.rs index 444f5b50c..ee0c955b7 100644 --- a/wezterm-gui/src/renderstate.rs +++ b/wezterm-gui/src/renderstate.rs @@ -70,10 +70,12 @@ impl RenderState { quads, }); } - Err(OutOfTextureSpace { size: Some(size) }) => { + Err(OutOfTextureSpace { + size: Some(size), .. + }) => { atlas_size = size; } - Err(OutOfTextureSpace { size: None }) => { + Err(OutOfTextureSpace { size: None, .. }) => { anyhow::bail!("requested texture size is impossible!?") } }; @@ -326,6 +328,7 @@ impl RenderState { if let Some(&OutOfTextureSpace { size: Some(needed_size), + .. }) = err.downcast_ref::() { size.replace(needed_size); diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index a60e98487..9ef23857c 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -85,12 +85,15 @@ impl super::TermWindow { match self.paint_opengl_pass() { Ok(_) => break, Err(err) => { - if let Some(&OutOfTextureSpace { size: Some(size) }) = - err.downcast_ref::() + if let Some(&OutOfTextureSpace { + size: Some(size), + current_size, + }) = err.downcast_ref::() { let result = if pass == 0 { // Let's try clearing out the atlas and trying again - self.clear_texture_atlas() + // self.clear_texture_atlas() + self.recreate_texture_atlas(Some(current_size)) } else { log::trace!("grow texture atlas to {}", size); self.recreate_texture_atlas(Some(size)) diff --git a/window/src/bitmaps/atlas.rs b/window/src/bitmaps/atlas.rs index 1410933c6..262503d2d 100644 --- a/window/src/bitmaps/atlas.rs +++ b/window/src/bitmaps/atlas.rs @@ -12,6 +12,7 @@ const PADDING: i32 = 1; #[error("Texture Size exceeded, need {:?}", size)] pub struct OutOfTextureSpace { pub size: Option, + pub current_size: usize, } /// Atlases are bitmaps of srgba data that are sized as a power of 2. @@ -72,12 +73,14 @@ where // If we can't convert the sizes to i32, then we'll never // be able to store this image - let reserve_width: i32 = width - .try_into() - .map_err(|_| OutOfTextureSpace { size: None })?; - let reserve_height: i32 = height - .try_into() - .map_err(|_| OutOfTextureSpace { size: None })?; + let reserve_width: i32 = width.try_into().map_err(|_| OutOfTextureSpace { + size: None, + current_size: self.side, + })?; + let reserve_height: i32 = height.try_into().map_err(|_| OutOfTextureSpace { + size: None, + current_size: self.side, + })?; // We pad each sprite reservation with blank space to avoid // surprising and unexpected artifacts when the texture is @@ -107,6 +110,7 @@ where let size = (reserve_width.max(reserve_height) as usize).next_power_of_two(); Err(OutOfTextureSpace { size: Some((self.side * 2).max(size)), + current_size: self.side, }) } } diff --git a/window/src/bitmaps/mod.rs b/window/src/bitmaps/mod.rs index 926c0ab89..f502dd155 100644 --- a/window/src/bitmaps/mod.rs +++ b/window/src/bitmaps/mod.rs @@ -55,7 +55,6 @@ impl Texture2d for SrgbTexture2d { .pixels() .iter() .map(|&p| { - let (r, g, b, a) = Color(p).as_rgba(); // convert from linear to srgb. // This brightens up the emoji glyphs so that the // colors match those of the software renderer and @@ -63,22 +62,23 @@ impl Texture2d for SrgbTexture2d { // I haven't run down exactly why this is needed but // suspect that it would be resolved if we could teach // glium to use SRGB for the texture. - fn conv(v: u8) -> u8 { - let f = (v as f32) / 255.; - let c = if f <= 0.003_130_8 { - f * 12.92 - } else { - f.powf(1.0 / 2.4) * 1.055 - 0.055 - }; - (c * 255.).ceil() as u8 - } - Color::rgba(conv(b), conv(g), conv(r), conv(a)).0 + let (r, g, b, a) = Color(p).as_rgba(); + // Switch from bgra to rgba + Color::with_linear_rgba_u8(b, g, r, a).0 }) .collect(), width: im_width as u32, height: im_height as u32, format: glium::texture::ClientFormat::U8U8U8U8, }; + /* Aspirationally, we want this: + let source = glium::texture::RawImage2d { + data: std::borrow::Cow::Borrowed(im .pixels()), + width: im_width as u32, + height: im_height as u32, + format: glium::texture::ClientFormat::U8U8U8U8, + }; + */ SrgbTexture2d::write( self,