mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Fix buggy text withviewports on monitors with different scales (#3666)
* Closes https://github.com/emilk/egui/issues/3664 Bonus: optimize color conversions and font atlas upload, especially in debug builds.
This commit is contained in:
@@ -350,7 +350,7 @@ impl From<FontImage> for ImageData {
|
||||
|
||||
#[inline]
|
||||
fn fast_round(r: f32) -> u8 {
|
||||
(r + 0.5).floor() as _ // rust does a saturating cast since 1.45
|
||||
(r + 0.5) as _ // rust does a saturating cast since 1.45
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -425,6 +425,12 @@ impl Fonts {
|
||||
self.lock().fonts.atlas.clone()
|
||||
}
|
||||
|
||||
/// The full font atlas image.
|
||||
#[inline]
|
||||
pub fn image(&self) -> crate::FontImage {
|
||||
self.lock().fonts.atlas.lock().image().clone()
|
||||
}
|
||||
|
||||
/// Current size of the font image.
|
||||
/// Pass this to [`crate::Tessellator`].
|
||||
pub fn font_image_size(&self) -> [usize; 2] {
|
||||
@@ -590,7 +596,7 @@ impl FontsImpl {
|
||||
);
|
||||
|
||||
let texture_width = max_texture_side.at_most(8 * 1024);
|
||||
let initial_height = 64;
|
||||
let initial_height = 32; // Keep initial font atlas small, so it is fast to upload to GPU. This will expand as needed anyways.
|
||||
let atlas = TextureAtlas::new([texture_width, initial_height]);
|
||||
|
||||
let atlas = Arc::new(Mutex::new(atlas));
|
||||
|
||||
@@ -97,7 +97,7 @@ impl TextureAtlas {
|
||||
// for r in [1, 2, 4, 8, 16, 32, 64] {
|
||||
// let w = 2 * r + 3;
|
||||
// let hw = w as i32 / 2;
|
||||
const LARGEST_CIRCLE_RADIUS: f32 = 64.0;
|
||||
const LARGEST_CIRCLE_RADIUS: f32 = 8.0; // keep small so that the initial texture atlas is small
|
||||
for i in 0.. {
|
||||
let r = 2.0_f32.powf(i as f32 / 2.0 - 1.0);
|
||||
if r > LARGEST_CIRCLE_RADIUS {
|
||||
@@ -172,9 +172,21 @@ impl TextureAtlas {
|
||||
}
|
||||
}
|
||||
|
||||
/// The texture options suitable for a font texture
|
||||
#[inline]
|
||||
pub fn texture_options() -> crate::textures::TextureOptions {
|
||||
crate::textures::TextureOptions::LINEAR
|
||||
}
|
||||
|
||||
/// The full font atlas image.
|
||||
#[inline]
|
||||
pub fn image(&self) -> &FontImage {
|
||||
&self.image
|
||||
}
|
||||
|
||||
/// Call to get the change to the image since last call.
|
||||
pub fn take_delta(&mut self) -> Option<ImageDelta> {
|
||||
let texture_options = crate::textures::TextureOptions::LINEAR;
|
||||
let texture_options = Self::texture_options();
|
||||
|
||||
let dirty = std::mem::replace(&mut self.dirty, Rectu::NOTHING);
|
||||
if dirty == Rectu::NOTHING {
|
||||
|
||||
Reference in New Issue
Block a user