[user textures] switch WHITE_UV to (0,0) and require clamped sampling
This commit is contained in:
parent
7093de0ff2
commit
8984302122
3 changed files with 18 additions and 13 deletions
|
@ -87,20 +87,16 @@ impl Fonts {
|
||||||
|
|
||||||
let mut atlas = TextureAtlas::new(512, 16); // TODO: better default?
|
let mut atlas = TextureAtlas::new(512, 16); // TODO: better default?
|
||||||
|
|
||||||
// Make the top left four pixels fully white:
|
|
||||||
{
|
{
|
||||||
let pos = atlas.allocate((2, 2));
|
// Make the top left pixel fully white:
|
||||||
|
let pos = atlas.allocate((1, 1));
|
||||||
assert_eq!(pos, (0, 0));
|
assert_eq!(pos, (0, 0));
|
||||||
let tex = atlas.texture_mut();
|
atlas.texture_mut()[pos] = 255;
|
||||||
tex[(0, 0)] = 255;
|
|
||||||
tex[(0, 1)] = 255;
|
|
||||||
tex[(1, 0)] = 255;
|
|
||||||
tex[(1, 1)] = 255;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let atlas = Arc::new(Mutex::new(atlas));
|
let atlas = Arc::new(Mutex::new(atlas));
|
||||||
|
|
||||||
// TODO: figure out a way to make the wasm smaller despite including a font. Zip it?
|
// TODO: figure out a way to make the WASM smaller despite including a font. Zip it?
|
||||||
let monospace_typeface_data = include_bytes!("../../fonts/ProggyClean.ttf"); // Use 13 for this. NOTHING ELSE.
|
let monospace_typeface_data = include_bytes!("../../fonts/ProggyClean.ttf"); // Use 13 for this. NOTHING ELSE.
|
||||||
|
|
||||||
// let monospace_typeface_data = include_bytes!("../../fonts/Roboto-Regular.ttf");
|
// let monospace_typeface_data = include_bytes!("../../fonts/Roboto-Regular.ttf");
|
||||||
|
|
|
@ -15,7 +15,10 @@ use {
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The UV coordinate of a white region of the texture mesh.
|
/// The UV coordinate of a white region of the texture mesh.
|
||||||
pub const WHITE_UV: (u16, u16) = (1, 1);
|
/// The default Egui texture has the top-left corner pixel fully white.
|
||||||
|
/// You need need use a clamping texture sampler for this to work
|
||||||
|
/// (so it doesn't do bilinear blending with bottom right corner).
|
||||||
|
pub const WHITE_UV: (u16, u16) = (0, 0);
|
||||||
|
|
||||||
/// The vertex type.
|
/// The vertex type.
|
||||||
///
|
///
|
||||||
|
@ -26,8 +29,11 @@ pub struct Vertex {
|
||||||
/// Logical pixel coordinates (points).
|
/// Logical pixel coordinates (points).
|
||||||
/// (0,0) is the top left corner of the screen.
|
/// (0,0) is the top left corner of the screen.
|
||||||
pub pos: Pos2, // 64 bit
|
pub pos: Pos2, // 64 bit
|
||||||
/// Texel coordinates in the texture
|
|
||||||
|
/// Texel coordinates in the texture.
|
||||||
|
/// (0, 0) is the top left corner of the texture.
|
||||||
pub uv: (u16, u16), // 32 bit
|
pub uv: (u16, u16), // 32 bit
|
||||||
|
|
||||||
/// sRGBA with premultiplied alpha
|
/// sRGBA with premultiplied alpha
|
||||||
pub color: Srgba, // 32 bit
|
pub color: Srgba, // 32 bit
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,10 @@ use {
|
||||||
paint::{PaintJobs, Triangles},
|
paint::{PaintJobs, Triangles},
|
||||||
Rect,
|
Rect,
|
||||||
},
|
},
|
||||||
glium::{implement_vertex, index::PrimitiveType, program, texture, uniform, Frame, Surface},
|
glium::{
|
||||||
|
implement_vertex, index::PrimitiveType, program, texture, uniform,
|
||||||
|
uniforms::SamplerWrapFunction, Frame, Surface,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Painter {
|
pub struct Painter {
|
||||||
|
@ -108,7 +111,7 @@ impl Painter {
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// glium expects linear rgba
|
// glium expects linear rgba
|
||||||
gl_FragColor = v_rgba * texture2D`(u_sampler, v_tc).r;
|
gl_FragColor = v_rgba * texture2D(u_sampler, v_tc).r;
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
},
|
},
|
||||||
|
@ -255,7 +258,7 @@ impl Painter {
|
||||||
let uniforms = uniform! {
|
let uniforms = uniform! {
|
||||||
u_screen_size: [width_points, height_points],
|
u_screen_size: [width_points, height_points],
|
||||||
u_tex_size: [texture.width as f32, texture.height as f32],
|
u_tex_size: [texture.width as f32, texture.height as f32],
|
||||||
u_sampler: &self.texture,
|
u_sampler: self.texture.sampled().wrap_function(SamplerWrapFunction::Clamp),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Egui outputs colors with premultiplied alpha:
|
// Egui outputs colors with premultiplied alpha:
|
||||||
|
|
Loading…
Reference in a new issue