Update winit to 0.20
This commit is contained in:
parent
4e9e051caa
commit
fb4a7968ca
7 changed files with 92 additions and 71 deletions
|
|
@ -92,7 +92,7 @@ impl Renderer {
|
|||
log::debug!("Drawing");
|
||||
|
||||
let (width, height) = target.dimensions();
|
||||
let dpi = target.dpi();
|
||||
let scale_factor = target.scale_factor();
|
||||
let transformation = target.transformation();
|
||||
let frame = target.next_frame();
|
||||
|
||||
|
|
@ -132,7 +132,13 @@ impl Renderer {
|
|||
self.draw_overlay(overlay, &mut layers);
|
||||
|
||||
for layer in layers {
|
||||
self.flush(dpi, transformation, &layer, &mut encoder, &frame.view);
|
||||
self.flush(
|
||||
scale_factor,
|
||||
transformation,
|
||||
&layer,
|
||||
&mut encoder,
|
||||
&frame.view,
|
||||
);
|
||||
}
|
||||
|
||||
self.queue.submit(&[encoder.finish()]);
|
||||
|
|
@ -330,19 +336,19 @@ impl Renderer {
|
|||
|
||||
fn flush(
|
||||
&mut self,
|
||||
dpi: f32,
|
||||
scale_factor: f32,
|
||||
transformation: Transformation,
|
||||
layer: &Layer<'_>,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
target: &wgpu::TextureView,
|
||||
) {
|
||||
let bounds = layer.bounds * dpi;
|
||||
let bounds = layer.bounds * scale_factor;
|
||||
|
||||
if layer.meshes.len() > 0 {
|
||||
let translated = transformation
|
||||
* Transformation::translate(
|
||||
-(layer.offset.x as f32) * dpi,
|
||||
-(layer.offset.y as f32) * dpi,
|
||||
-(layer.offset.x as f32) * scale_factor,
|
||||
-(layer.offset.y as f32) * scale_factor,
|
||||
);
|
||||
|
||||
self.triangle_pipeline.draw(
|
||||
|
|
@ -350,7 +356,7 @@ impl Renderer {
|
|||
encoder,
|
||||
target,
|
||||
translated,
|
||||
dpi,
|
||||
scale_factor,
|
||||
&layer.meshes,
|
||||
bounds,
|
||||
);
|
||||
|
|
@ -362,7 +368,7 @@ impl Renderer {
|
|||
encoder,
|
||||
&layer.quads,
|
||||
transformation,
|
||||
dpi,
|
||||
scale_factor,
|
||||
bounds,
|
||||
target,
|
||||
);
|
||||
|
|
@ -370,7 +376,7 @@ impl Renderer {
|
|||
|
||||
if layer.images.len() > 0 {
|
||||
let translated_and_scaled = transformation
|
||||
* Transformation::scale(dpi, dpi)
|
||||
* Transformation::scale(scale_factor, scale_factor)
|
||||
* Transformation::translate(
|
||||
-(layer.offset.x as f32),
|
||||
-(layer.offset.y as f32),
|
||||
|
|
@ -383,7 +389,7 @@ impl Renderer {
|
|||
translated_and_scaled,
|
||||
bounds,
|
||||
target,
|
||||
dpi,
|
||||
scale_factor,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -396,25 +402,25 @@ impl Renderer {
|
|||
// bit "jumpy". We may be able to do better once we improve
|
||||
// our text rendering/caching pipeline.
|
||||
screen_position: (
|
||||
(text.screen_position.0 * dpi).round(),
|
||||
(text.screen_position.1 * dpi).round(),
|
||||
(text.screen_position.0 * scale_factor).round(),
|
||||
(text.screen_position.1 * scale_factor).round(),
|
||||
),
|
||||
// TODO: Fix precision issues with some DPI factors.
|
||||
// TODO: Fix precision issues with some scale factors.
|
||||
//
|
||||
// The `ceil` here can cause some words to render on the
|
||||
// same line when they should not.
|
||||
//
|
||||
// Ideally, `wgpu_glyph` should be able to compute layout
|
||||
// using logical positions, and then apply the proper
|
||||
// DPI scaling. This would ensure that both measuring and
|
||||
// rendering follow the same layout rules.
|
||||
// scaling when rendering. This would ensure that both
|
||||
// measuring and rendering follow the same layout rules.
|
||||
bounds: (
|
||||
(text.bounds.0 * dpi).ceil(),
|
||||
(text.bounds.1 * dpi).ceil(),
|
||||
(text.bounds.0 * scale_factor).ceil(),
|
||||
(text.bounds.1 * scale_factor).ceil(),
|
||||
),
|
||||
scale: wgpu_glyph::Scale {
|
||||
x: text.scale.x * dpi,
|
||||
y: text.scale.y * dpi,
|
||||
x: text.scale.x * scale_factor,
|
||||
y: text.scale.y * scale_factor,
|
||||
},
|
||||
..*text
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ use raw_window_handle::HasRawWindowHandle;
|
|||
#[derive(Debug)]
|
||||
pub struct Target {
|
||||
surface: wgpu::Surface,
|
||||
width: u16,
|
||||
height: u16,
|
||||
dpi: f32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
scale_factor: f32,
|
||||
transformation: Transformation,
|
||||
swap_chain: wgpu::SwapChain,
|
||||
}
|
||||
|
||||
impl Target {
|
||||
pub(crate) fn dimensions(&self) -> (u16, u16) {
|
||||
pub(crate) fn dimensions(&self) -> (u32, u32) {
|
||||
(self.width, self.height)
|
||||
}
|
||||
|
||||
pub(crate) fn dpi(&self) -> f32 {
|
||||
self.dpi
|
||||
pub(crate) fn scale_factor(&self) -> f32 {
|
||||
self.scale_factor
|
||||
}
|
||||
|
||||
pub(crate) fn transformation(&self) -> Transformation {
|
||||
|
|
@ -37,9 +37,9 @@ impl window::Target for Target {
|
|||
|
||||
fn new<W: HasRawWindowHandle>(
|
||||
window: &W,
|
||||
width: u16,
|
||||
height: u16,
|
||||
dpi: f32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
scale_factor: f32,
|
||||
renderer: &Renderer,
|
||||
) -> Target {
|
||||
let surface = wgpu::Surface::create(window);
|
||||
|
|
@ -50,7 +50,7 @@ impl window::Target for Target {
|
|||
surface,
|
||||
width,
|
||||
height,
|
||||
dpi,
|
||||
scale_factor,
|
||||
transformation: Transformation::orthographic(width, height),
|
||||
swap_chain,
|
||||
}
|
||||
|
|
@ -58,14 +58,14 @@ impl window::Target for Target {
|
|||
|
||||
fn resize(
|
||||
&mut self,
|
||||
width: u16,
|
||||
height: u16,
|
||||
dpi: f32,
|
||||
width: u32,
|
||||
height: u32,
|
||||
scale_factor: f32,
|
||||
renderer: &Renderer,
|
||||
) {
|
||||
self.width = width;
|
||||
self.height = height;
|
||||
self.dpi = dpi;
|
||||
self.scale_factor = scale_factor;
|
||||
self.transformation = Transformation::orthographic(width, height);
|
||||
self.swap_chain =
|
||||
new_swap_chain(&self.surface, width, height, &renderer.device);
|
||||
|
|
@ -74,8 +74,8 @@ impl window::Target for Target {
|
|||
|
||||
fn new_swap_chain(
|
||||
surface: &wgpu::Surface,
|
||||
width: u16,
|
||||
height: u16,
|
||||
width: u32,
|
||||
height: u32,
|
||||
device: &wgpu::Device,
|
||||
) -> wgpu::SwapChain {
|
||||
device.create_swap_chain(
|
||||
|
|
@ -83,8 +83,8 @@ fn new_swap_chain(
|
|||
&wgpu::SwapChainDescriptor {
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||
width: u32::from(width),
|
||||
height: u32::from(height),
|
||||
width,
|
||||
height,
|
||||
present_mode: wgpu::PresentMode::Vsync,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ impl Transformation {
|
|||
|
||||
/// Creates an orthographic projection.
|
||||
#[rustfmt::skip]
|
||||
pub fn orthographic(width: u16, height: u16) -> Transformation {
|
||||
pub fn orthographic(width: u32, height: u32) -> Transformation {
|
||||
Transformation(Mat4::from_cols(
|
||||
Vec4::new(2.0 / f32::from(width), 0.0, 0.0, 0.0),
|
||||
Vec4::new(0.0, 2.0 / f32::from(height), 0.0, 0.0),
|
||||
Vec4::new(2.0 / width as f32, 0.0, 0.0, 0.0),
|
||||
Vec4::new(0.0, 2.0 / height as f32, 0.0, 0.0),
|
||||
Vec4::new(0.0, 0.0, -1.0, 0.0),
|
||||
Vec4::new(-1.0, -1.0, 0.0, 1.0)
|
||||
))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue