From 05af8d00d4c0f7b8e0ece85224fd90a92da86da8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 17:15:44 +0200 Subject: Draft new `iced_graphics` crate :tada: --- glow/src/backend.rs | 423 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 423 insertions(+) create mode 100644 glow/src/backend.rs (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs new file mode 100644 index 00000000..7293eba1 --- /dev/null +++ b/glow/src/backend.rs @@ -0,0 +1,423 @@ +use crate::quad; +use crate::text; +use crate::triangle; +use crate::{Quad, Settings, Transformation, Viewport}; +use iced_graphics::backend; +use iced_graphics::Primitive; +use iced_native::mouse; +use iced_native::{Background, Font, Point, Rectangle, Size, Vector}; + +/// A [`glow`] renderer. +/// +/// [`glow`]: https://github.com/grovesNL/glow +#[derive(Debug)] +pub struct Backend { + quad_pipeline: quad::Pipeline, + text_pipeline: text::Pipeline, + triangle_pipeline: triangle::Pipeline, +} + +struct Layer<'a> { + bounds: Rectangle, + quads: Vec, + text: Vec>, + meshes: Vec<(Vector, Rectangle, &'a triangle::Mesh2D)>, +} + +impl<'a> Layer<'a> { + pub fn new(bounds: Rectangle) -> Self { + Self { + bounds, + quads: Vec::new(), + text: Vec::new(), + meshes: Vec::new(), + } + } + + pub fn intersection(&self, rectangle: Rectangle) -> Option> { + let layer_bounds: Rectangle = self.bounds.into(); + + layer_bounds.intersection(&rectangle).map(Into::into) + } +} + +impl Backend { + /// Creates a new [`Renderer`]. + /// + /// [`Renderer`]: struct.Renderer.html + pub fn new(gl: &glow::Context, settings: Settings) -> Self { + let text_pipeline = text::Pipeline::new(gl, settings.default_font); + let quad_pipeline = quad::Pipeline::new(gl); + let triangle_pipeline = + triangle::Pipeline::new(gl, settings.antialiasing); + + Self { + quad_pipeline, + text_pipeline, + triangle_pipeline, + } + } + + /// Draws the provided primitives in the given [`Target`]. + /// + /// The text provided as overlay will be renderer on top of the primitives. + /// This is useful for rendering debug information. + /// + /// [`Target`]: struct.Target.html + pub fn draw>( + &mut self, + gl: &glow::Context, + viewport: &Viewport, + (primitive, mouse_interaction): &(Primitive, mouse::Interaction), + scale_factor: f64, + overlay: &[T], + ) -> mouse::Interaction { + let (width, height) = viewport.dimensions(); + let scale_factor = scale_factor as f32; + let transformation = viewport.transformation(); + + let mut layers = Vec::new(); + + layers.push(Layer::new(Rectangle { + x: 0, + y: 0, + width: (width as f32 / scale_factor).round() as u32, + height: (height as f32 / scale_factor).round() as u32, + })); + + self.draw_primitive(Vector::new(0.0, 0.0), primitive, &mut layers); + self.draw_overlay(overlay, &mut layers); + + for layer in layers { + self.flush( + gl, + viewport, + scale_factor, + transformation, + &layer, + width, + height, + ); + } + + *mouse_interaction + } + + fn draw_primitive<'a>( + &mut self, + translation: Vector, + primitive: &'a Primitive, + layers: &mut Vec>, + ) { + match primitive { + Primitive::None => {} + Primitive::Group { primitives } => { + // TODO: Inspect a bit and regroup (?) + for primitive in primitives { + self.draw_primitive(translation, primitive, layers) + } + } + Primitive::Text { + content, + bounds, + size, + color, + font, + horizontal_alignment, + vertical_alignment, + } => { + let layer = layers.last_mut().unwrap(); + + layer.text.push(glow_glyph::Section { + text: &content, + screen_position: ( + bounds.x + translation.x, + bounds.y + translation.y, + ), + bounds: (bounds.width, bounds.height), + scale: glow_glyph::Scale { x: *size, y: *size }, + color: color.into_linear(), + font_id: self.text_pipeline.find_font(*font), + layout: glow_glyph::Layout::default() + .h_align(match horizontal_alignment { + iced_native::HorizontalAlignment::Left => { + glow_glyph::HorizontalAlign::Left + } + iced_native::HorizontalAlignment::Center => { + glow_glyph::HorizontalAlign::Center + } + iced_native::HorizontalAlignment::Right => { + glow_glyph::HorizontalAlign::Right + } + }) + .v_align(match vertical_alignment { + iced_native::VerticalAlignment::Top => { + glow_glyph::VerticalAlign::Top + } + iced_native::VerticalAlignment::Center => { + glow_glyph::VerticalAlign::Center + } + iced_native::VerticalAlignment::Bottom => { + glow_glyph::VerticalAlign::Bottom + } + }), + ..Default::default() + }) + } + Primitive::Quad { + bounds, + background, + border_radius, + border_width, + border_color, + } => { + let layer = layers.last_mut().unwrap(); + + // TODO: Move some of these computations to the GPU (?) + layer.quads.push(Quad { + position: [ + bounds.x + translation.x, + bounds.y + translation.y, + ], + scale: [bounds.width, bounds.height], + color: match background { + Background::Color(color) => color.into_linear(), + }, + border_radius: *border_radius as f32, + border_width: *border_width as f32, + border_color: border_color.into_linear(), + }); + } + Primitive::Mesh2D { size, buffers } => { + let layer = layers.last_mut().unwrap(); + + // Only draw visible content + if let Some(clip_bounds) = layer.intersection(Rectangle::new( + Point::new(translation.x, translation.y), + *size, + )) { + layer.meshes.push(( + translation, + clip_bounds.into(), + buffers, + )); + } + } + Primitive::Clip { + bounds, + offset, + content, + } => { + let layer = layers.last_mut().unwrap(); + + // Only draw visible content + if let Some(clip_bounds) = + layer.intersection(*bounds + translation) + { + let clip_layer = Layer::new(clip_bounds.into()); + let new_layer = Layer::new(layer.bounds); + + layers.push(clip_layer); + self.draw_primitive( + translation + - Vector::new(offset.x as f32, offset.y as f32), + content, + layers, + ); + layers.push(new_layer); + } + } + Primitive::Translate { + translation: new_translation, + content, + } => { + self.draw_primitive( + translation + *new_translation, + &content, + layers, + ); + } + + Primitive::Cached { cache } => { + self.draw_primitive(translation, &cache, layers); + } + + #[cfg(feature = "image")] + Primitive::Image { handle, bounds } => { + let layer = layers.last_mut().unwrap(); + + layer.images.push(Image { + handle: image::Handle::Raster(handle.clone()), + position: [ + bounds.x + translation.x, + bounds.y + translation.y, + ], + size: [bounds.width, bounds.height], + }); + } + #[cfg(not(feature = "image"))] + Primitive::Image { .. } => {} + + #[cfg(feature = "svg")] + Primitive::Svg { handle, bounds } => { + let layer = layers.last_mut().unwrap(); + + layer.images.push(Image { + handle: image::Handle::Vector(handle.clone()), + position: [ + bounds.x + translation.x, + bounds.y + translation.y, + ], + size: [bounds.width, bounds.height], + }); + } + #[cfg(not(feature = "svg"))] + Primitive::Svg { .. } => {} + } + } + + fn draw_overlay<'a, T: AsRef>( + &mut self, + lines: &'a [T], + layers: &mut Vec>, + ) { + let first = layers.first().unwrap(); + let mut overlay = Layer::new(first.bounds); + + let font_id = self.text_pipeline.overlay_font(); + let scale = glow_glyph::Scale { x: 20.0, y: 20.0 }; + + for (i, line) in lines.iter().enumerate() { + overlay.text.push(glow_glyph::Section { + text: line.as_ref(), + screen_position: (11.0, 11.0 + 25.0 * i as f32), + color: [0.9, 0.9, 0.9, 1.0], + scale, + font_id, + ..glow_glyph::Section::default() + }); + + overlay.text.push(glow_glyph::Section { + text: line.as_ref(), + screen_position: (10.0, 10.0 + 25.0 * i as f32), + color: [0.0, 0.0, 0.0, 1.0], + scale, + font_id, + ..glow_glyph::Section::default() + }); + } + + layers.push(overlay); + } + + fn flush( + &mut self, + gl: &glow::Context, + viewport: &Viewport, + scale_factor: f32, + transformation: Transformation, + layer: &Layer<'_>, + target_width: u32, + target_height: u32, + ) { + let bounds = layer.bounds * scale_factor; + + if !layer.quads.is_empty() { + self.quad_pipeline.draw( + gl, + viewport, + &layer.quads, + transformation, + scale_factor, + bounds, + ); + } + + if !layer.meshes.is_empty() { + let scaled = transformation + * Transformation::scale(scale_factor, scale_factor); + + self.triangle_pipeline.draw( + gl, + target_width, + target_height, + scaled, + scale_factor, + &layer.meshes, + ); + } + + if !layer.text.is_empty() { + for text in layer.text.iter() { + // Target physical coordinates directly to avoid blurry text + let text = glow_glyph::Section { + // TODO: We `round` here to avoid rerasterizing text when + // its position changes slightly. This can make text feel a + // bit "jumpy". We may be able to do better once we improve + // our text rendering/caching pipeline. + screen_position: ( + (text.screen_position.0 * scale_factor).round(), + (text.screen_position.1 * scale_factor).round(), + ), + // 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 + // scaling when rendering. This would ensure that both + // measuring and rendering follow the same layout rules. + bounds: ( + (text.bounds.0 * scale_factor).ceil(), + (text.bounds.1 * scale_factor).ceil(), + ), + scale: glow_glyph::Scale { + x: text.scale.x * scale_factor, + y: text.scale.y * scale_factor, + }, + ..*text + }; + + self.text_pipeline.queue(text); + } + + self.text_pipeline.draw_queued( + gl, + transformation, + glow_glyph::Region { + x: bounds.x, + y: viewport.height() + - (bounds.y + bounds.height).min(viewport.height()), + width: bounds.width, + height: bounds.height, + }, + ); + } + } +} + +impl iced_graphics::Backend for Backend { + fn trim_measurements(&mut self) { + self.text_pipeline.trim_measurement_cache() + } +} + +impl backend::Text for Backend { + const ICON_FONT: Font = text::BUILTIN_ICONS; + const CHECKMARK_ICON: char = text::CHECKMARK_ICON; + + fn measure( + &self, + contents: &str, + size: f32, + font: Font, + bounds: Size, + ) -> (f32, f32) { + self.text_pipeline.measure(contents, size, font, bounds) + } + + fn space_width(&self, size: f32) -> f32 { + self.text_pipeline.space_width(size) + } +} -- cgit From f0480854a9cd76f443848dbfa14256089b56abfe Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 20:30:46 +0200 Subject: Move built-in fonts to `iced_graphics` --- glow/src/backend.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 7293eba1..94683e56 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -3,6 +3,7 @@ use crate::text; use crate::triangle; use crate::{Quad, Settings, Transformation, Viewport}; use iced_graphics::backend; +use iced_graphics::font; use iced_graphics::Primitive; use iced_native::mouse; use iced_native::{Background, Font, Point, Rectangle, Size, Vector}; @@ -404,8 +405,8 @@ impl iced_graphics::Backend for Backend { } impl backend::Text for Backend { - const ICON_FONT: Font = text::BUILTIN_ICONS; - const CHECKMARK_ICON: char = text::CHECKMARK_ICON; + const ICON_FONT: Font = font::ICONS; + const CHECKMARK_ICON: char = font::CHECKMARK_ICON; fn measure( &self, -- cgit From 720e7756f2afe30706b6b1a7fbde86b9f15e1d8c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 May 2020 22:55:12 +0200 Subject: Move `Layer` to `iced_graphics` --- glow/src/backend.rs | 291 +++++++--------------------------------------------- 1 file changed, 39 insertions(+), 252 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 94683e56..fb6782e6 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -1,12 +1,13 @@ use crate::quad; use crate::text; use crate::triangle; -use crate::{Quad, Settings, Transformation, Viewport}; +use crate::{Settings, Transformation, Viewport}; use iced_graphics::backend; use iced_graphics::font; +use iced_graphics::Layer; use iced_graphics::Primitive; use iced_native::mouse; -use iced_native::{Background, Font, Point, Rectangle, Size, Vector}; +use iced_native::{Font, HorizontalAlignment, Size, VerticalAlignment}; /// A [`glow`] renderer. /// @@ -18,30 +19,6 @@ pub struct Backend { triangle_pipeline: triangle::Pipeline, } -struct Layer<'a> { - bounds: Rectangle, - quads: Vec, - text: Vec>, - meshes: Vec<(Vector, Rectangle, &'a triangle::Mesh2D)>, -} - -impl<'a> Layer<'a> { - pub fn new(bounds: Rectangle) -> Self { - Self { - bounds, - quads: Vec::new(), - text: Vec::new(), - meshes: Vec::new(), - } - } - - pub fn intersection(&self, rectangle: Rectangle) -> Option> { - let layer_bounds: Rectangle = self.bounds.into(); - - layer_bounds.intersection(&rectangle).map(Into::into) - } -} - impl Backend { /// Creates a new [`Renderer`]. /// @@ -71,23 +48,14 @@ impl Backend { viewport: &Viewport, (primitive, mouse_interaction): &(Primitive, mouse::Interaction), scale_factor: f64, - overlay: &[T], + overlay_text: &[T], ) -> mouse::Interaction { let (width, height) = viewport.dimensions(); let scale_factor = scale_factor as f32; let transformation = viewport.transformation(); - let mut layers = Vec::new(); - - layers.push(Layer::new(Rectangle { - x: 0, - y: 0, - width: (width as f32 / scale_factor).round() as u32, - height: (height as f32 / scale_factor).round() as u32, - })); - - self.draw_primitive(Vector::new(0.0, 0.0), primitive, &mut layers); - self.draw_overlay(overlay, &mut layers); + let mut layers = Layer::generate(primitive, viewport); + layers.push(Layer::overlay(overlay_text, viewport)); for layer in layers { self.flush( @@ -104,213 +72,6 @@ impl Backend { *mouse_interaction } - fn draw_primitive<'a>( - &mut self, - translation: Vector, - primitive: &'a Primitive, - layers: &mut Vec>, - ) { - match primitive { - Primitive::None => {} - Primitive::Group { primitives } => { - // TODO: Inspect a bit and regroup (?) - for primitive in primitives { - self.draw_primitive(translation, primitive, layers) - } - } - Primitive::Text { - content, - bounds, - size, - color, - font, - horizontal_alignment, - vertical_alignment, - } => { - let layer = layers.last_mut().unwrap(); - - layer.text.push(glow_glyph::Section { - text: &content, - screen_position: ( - bounds.x + translation.x, - bounds.y + translation.y, - ), - bounds: (bounds.width, bounds.height), - scale: glow_glyph::Scale { x: *size, y: *size }, - color: color.into_linear(), - font_id: self.text_pipeline.find_font(*font), - layout: glow_glyph::Layout::default() - .h_align(match horizontal_alignment { - iced_native::HorizontalAlignment::Left => { - glow_glyph::HorizontalAlign::Left - } - iced_native::HorizontalAlignment::Center => { - glow_glyph::HorizontalAlign::Center - } - iced_native::HorizontalAlignment::Right => { - glow_glyph::HorizontalAlign::Right - } - }) - .v_align(match vertical_alignment { - iced_native::VerticalAlignment::Top => { - glow_glyph::VerticalAlign::Top - } - iced_native::VerticalAlignment::Center => { - glow_glyph::VerticalAlign::Center - } - iced_native::VerticalAlignment::Bottom => { - glow_glyph::VerticalAlign::Bottom - } - }), - ..Default::default() - }) - } - Primitive::Quad { - bounds, - background, - border_radius, - border_width, - border_color, - } => { - let layer = layers.last_mut().unwrap(); - - // TODO: Move some of these computations to the GPU (?) - layer.quads.push(Quad { - position: [ - bounds.x + translation.x, - bounds.y + translation.y, - ], - scale: [bounds.width, bounds.height], - color: match background { - Background::Color(color) => color.into_linear(), - }, - border_radius: *border_radius as f32, - border_width: *border_width as f32, - border_color: border_color.into_linear(), - }); - } - Primitive::Mesh2D { size, buffers } => { - let layer = layers.last_mut().unwrap(); - - // Only draw visible content - if let Some(clip_bounds) = layer.intersection(Rectangle::new( - Point::new(translation.x, translation.y), - *size, - )) { - layer.meshes.push(( - translation, - clip_bounds.into(), - buffers, - )); - } - } - Primitive::Clip { - bounds, - offset, - content, - } => { - let layer = layers.last_mut().unwrap(); - - // Only draw visible content - if let Some(clip_bounds) = - layer.intersection(*bounds + translation) - { - let clip_layer = Layer::new(clip_bounds.into()); - let new_layer = Layer::new(layer.bounds); - - layers.push(clip_layer); - self.draw_primitive( - translation - - Vector::new(offset.x as f32, offset.y as f32), - content, - layers, - ); - layers.push(new_layer); - } - } - Primitive::Translate { - translation: new_translation, - content, - } => { - self.draw_primitive( - translation + *new_translation, - &content, - layers, - ); - } - - Primitive::Cached { cache } => { - self.draw_primitive(translation, &cache, layers); - } - - #[cfg(feature = "image")] - Primitive::Image { handle, bounds } => { - let layer = layers.last_mut().unwrap(); - - layer.images.push(Image { - handle: image::Handle::Raster(handle.clone()), - position: [ - bounds.x + translation.x, - bounds.y + translation.y, - ], - size: [bounds.width, bounds.height], - }); - } - #[cfg(not(feature = "image"))] - Primitive::Image { .. } => {} - - #[cfg(feature = "svg")] - Primitive::Svg { handle, bounds } => { - let layer = layers.last_mut().unwrap(); - - layer.images.push(Image { - handle: image::Handle::Vector(handle.clone()), - position: [ - bounds.x + translation.x, - bounds.y + translation.y, - ], - size: [bounds.width, bounds.height], - }); - } - #[cfg(not(feature = "svg"))] - Primitive::Svg { .. } => {} - } - } - - fn draw_overlay<'a, T: AsRef>( - &mut self, - lines: &'a [T], - layers: &mut Vec>, - ) { - let first = layers.first().unwrap(); - let mut overlay = Layer::new(first.bounds); - - let font_id = self.text_pipeline.overlay_font(); - let scale = glow_glyph::Scale { x: 20.0, y: 20.0 }; - - for (i, line) in lines.iter().enumerate() { - overlay.text.push(glow_glyph::Section { - text: line.as_ref(), - screen_position: (11.0, 11.0 + 25.0 * i as f32), - color: [0.9, 0.9, 0.9, 1.0], - scale, - font_id, - ..glow_glyph::Section::default() - }); - - overlay.text.push(glow_glyph::Section { - text: line.as_ref(), - screen_position: (10.0, 10.0 + 25.0 * i as f32), - color: [0.0, 0.0, 0.0, 1.0], - scale, - font_id, - ..glow_glyph::Section::default() - }); - } - - layers.push(overlay); - } - fn flush( &mut self, gl: &glow::Context, @@ -352,13 +113,14 @@ impl Backend { for text in layer.text.iter() { // Target physical coordinates directly to avoid blurry text let text = glow_glyph::Section { + text: text.content, // TODO: We `round` here to avoid rerasterizing text when // its position changes slightly. This can make text feel a // bit "jumpy". We may be able to do better once we improve // our text rendering/caching pipeline. screen_position: ( - (text.screen_position.0 * scale_factor).round(), - (text.screen_position.1 * scale_factor).round(), + (text.bounds.x * scale_factor).round(), + (text.bounds.y * scale_factor).round(), ), // TODO: Fix precision issues with some scale factors. // @@ -370,14 +132,39 @@ impl Backend { // scaling when rendering. This would ensure that both // measuring and rendering follow the same layout rules. bounds: ( - (text.bounds.0 * scale_factor).ceil(), - (text.bounds.1 * scale_factor).ceil(), + (text.bounds.width * scale_factor).ceil(), + (text.bounds.height * scale_factor).ceil(), ), scale: glow_glyph::Scale { - x: text.scale.x * scale_factor, - y: text.scale.y * scale_factor, + x: text.size * scale_factor, + y: text.size * scale_factor, }, - ..*text + color: text.color, + font_id: self.text_pipeline.find_font(text.font), + layout: glow_glyph::Layout::default() + .h_align(match text.horizontal_alignment { + HorizontalAlignment::Left => { + glow_glyph::HorizontalAlign::Left + } + HorizontalAlignment::Center => { + glow_glyph::HorizontalAlign::Center + } + HorizontalAlignment::Right => { + glow_glyph::HorizontalAlign::Right + } + }) + .v_align(match text.vertical_alignment { + VerticalAlignment::Top => { + glow_glyph::VerticalAlign::Top + } + VerticalAlignment::Center => { + glow_glyph::VerticalAlign::Center + } + VerticalAlignment::Bottom => { + glow_glyph::VerticalAlign::Bottom + } + }), + ..Default::default() }; self.text_pipeline.queue(text); -- cgit From a1a5fcfd46622d5b18d1716aa2adb4659835ccf3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 May 2020 20:28:35 +0200 Subject: Refactor `Viewport` and `Compositor` --- glow/src/backend.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index fb6782e6..5e2aa837 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -47,12 +47,10 @@ impl Backend { gl: &glow::Context, viewport: &Viewport, (primitive, mouse_interaction): &(Primitive, mouse::Interaction), - scale_factor: f64, overlay_text: &[T], ) -> mouse::Interaction { - let (width, height) = viewport.dimensions(); - let scale_factor = scale_factor as f32; - let transformation = viewport.transformation(); + let viewport_size = viewport.physical_size(); + let projection = viewport.projection(); let mut layers = Layer::generate(primitive, viewport); layers.push(Layer::overlay(overlay_text, viewport)); @@ -60,12 +58,11 @@ impl Backend { for layer in layers { self.flush( gl, - viewport, - scale_factor, - transformation, + viewport.scale_factor() as f32, + projection, &layer, - width, - height, + viewport_size.width, + viewport_size.height, ); } @@ -75,19 +72,18 @@ impl Backend { fn flush( &mut self, gl: &glow::Context, - viewport: &Viewport, scale_factor: f32, transformation: Transformation, layer: &Layer<'_>, target_width: u32, target_height: u32, ) { - let bounds = layer.bounds * scale_factor; + let bounds = (layer.bounds * scale_factor).round(); if !layer.quads.is_empty() { self.quad_pipeline.draw( gl, - viewport, + target_height, &layer.quads, transformation, scale_factor, @@ -175,8 +171,7 @@ impl Backend { transformation, glow_glyph::Region { x: bounds.x, - y: viewport.height() - - (bounds.y + bounds.height).min(viewport.height()), + y: target_height - (bounds.y + bounds.height), width: bounds.width, height: bounds.height, }, -- cgit From e0e4ee73feead3f05730625c7e1917b63f0b384e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 May 2020 00:37:47 +0200 Subject: Implement `iced_glutin` :tada: --- glow/src/backend.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 5e2aa837..8c578d5e 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -36,12 +36,6 @@ impl Backend { } } - /// Draws the provided primitives in the given [`Target`]. - /// - /// The text provided as overlay will be renderer on top of the primitives. - /// This is useful for rendering debug information. - /// - /// [`Target`]: struct.Target.html pub fn draw>( &mut self, gl: &glow::Context, @@ -50,6 +44,7 @@ impl Backend { overlay_text: &[T], ) -> mouse::Interaction { let viewport_size = viewport.physical_size(); + let scale_factor = viewport.scale_factor() as f32; let projection = viewport.projection(); let mut layers = Layer::generate(primitive, viewport); @@ -58,7 +53,7 @@ impl Backend { for layer in layers { self.flush( gl, - viewport.scale_factor() as f32, + scale_factor, projection, &layer, viewport_size.width, @@ -78,7 +73,8 @@ impl Backend { target_width: u32, target_height: u32, ) { - let bounds = (layer.bounds * scale_factor).round(); + let mut bounds = (layer.bounds * scale_factor).round(); + bounds.height = bounds.height.min(target_height); if !layer.quads.is_empty() { self.quad_pipeline.draw( @@ -204,3 +200,20 @@ impl backend::Text for Backend { self.text_pipeline.space_width(size) } } + +#[cfg(feature = "image")] +impl backend::Image for Backend { + fn dimensions(&self, _handle: &iced_native::image::Handle) -> (u32, u32) { + (50, 50) + } +} + +#[cfg(feature = "svg")] +impl backend::Svg for Backend { + fn viewport_dimensions( + &self, + _handle: &iced_native::svg::Handle, + ) -> (u32, u32) { + (50, 50) + } +} -- cgit From 1dd79c4697ce39589bea84142334b3cbd242fb59 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 22 May 2020 19:15:39 +0200 Subject: Use built-in OpenGL multisampling in `iced_glow` --- glow/src/backend.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 8c578d5e..c98aa5fe 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -26,8 +26,7 @@ impl Backend { pub fn new(gl: &glow::Context, settings: Settings) -> Self { let text_pipeline = text::Pipeline::new(gl, settings.default_font); let quad_pipeline = quad::Pipeline::new(gl); - let triangle_pipeline = - triangle::Pipeline::new(gl, settings.antialiasing); + let triangle_pipeline = triangle::Pipeline::new(gl); Self { quad_pipeline, @@ -56,7 +55,6 @@ impl Backend { scale_factor, projection, &layer, - viewport_size.width, viewport_size.height, ); } @@ -70,7 +68,6 @@ impl Backend { scale_factor: f32, transformation: Transformation, layer: &Layer<'_>, - target_width: u32, target_height: u32, ) { let mut bounds = (layer.bounds * scale_factor).round(); @@ -93,7 +90,6 @@ impl Backend { self.triangle_pipeline.draw( gl, - target_width, target_height, scaled, scale_factor, -- cgit From 823ea1573245b849a0696543838a7ad1d0f914d8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 27 May 2020 23:09:27 +0200 Subject: Update `glyph_brush` and `glow_glyph` --- glow/src/backend.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'glow/src/backend.rs') diff --git a/glow/src/backend.rs b/glow/src/backend.rs index c98aa5fe..6bd443ad 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -101,7 +101,6 @@ impl Backend { for text in layer.text.iter() { // Target physical coordinates directly to avoid blurry text let text = glow_glyph::Section { - text: text.content, // TODO: We `round` here to avoid rerasterizing text when // its position changes slightly. This can make text feel a // bit "jumpy". We may be able to do better once we improve @@ -123,12 +122,18 @@ impl Backend { (text.bounds.width * scale_factor).ceil(), (text.bounds.height * scale_factor).ceil(), ), - scale: glow_glyph::Scale { - x: text.size * scale_factor, - y: text.size * scale_factor, - }, - color: text.color, - font_id: self.text_pipeline.find_font(text.font), + text: vec![glow_glyph::Text { + text: text.content, + scale: glow_glyph::ab_glyph::PxScale { + x: text.size * scale_factor, + y: text.size * scale_factor, + }, + font_id: self.text_pipeline.find_font(text.font), + extra: glow_glyph::Extra { + color: text.color, + z: 0.0, + }, + }], layout: glow_glyph::Layout::default() .h_align(match text.horizontal_alignment { HorizontalAlignment::Left => { @@ -191,10 +196,6 @@ impl backend::Text for Backend { ) -> (f32, f32) { self.text_pipeline.measure(contents, size, font, bounds) } - - fn space_width(&self, size: f32) -> f32 { - self.text_pipeline.space_width(size) - } } #[cfg(feature = "image")] -- cgit