diff options
author | 2022-10-24 17:06:02 -0700 | |
---|---|---|
committer | 2022-11-05 03:19:38 +0100 | |
commit | 5575e6ea0897e406674e7e4239808fbf9daa07c3 (patch) | |
tree | 888f1b22926a304e7e280710312727fc4137e373 /glow/src/backend.rs | |
parent | 2c7c42ee93a61f39562590f6a75eb2dd8b220fb8 (diff) | |
download | iced-5575e6ea0897e406674e7e4239808fbf9daa07c3.tar.gz iced-5575e6ea0897e406674e7e4239808fbf9daa07c3.tar.bz2 iced-5575e6ea0897e406674e7e4239808fbf9daa07c3.zip |
Add image/svg support to `iced_glow`
https://github.com/iced-rs/iced/issues/674
Uses image/svg support in `iced_graphics`. The is not currently using an
atlas, and uses one texture/draw per image. This should be good enough
for now; supporting images with glow is better than not supporting them,
and if something else performs better, that improvement can be made
without any change to the public API.
Diffstat (limited to '')
-rw-r--r-- | glow/src/backend.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/glow/src/backend.rs b/glow/src/backend.rs index 21af2ecf..1ba70a49 100644 --- a/glow/src/backend.rs +++ b/glow/src/backend.rs @@ -1,3 +1,5 @@ +#[cfg(any(feature = "image_rs", feature = "svg"))] +use crate::image; use crate::quad; use crate::text; use crate::{program, triangle}; @@ -15,6 +17,8 @@ use iced_native::{Font, Size}; /// [`iced`]: https://github.com/iced-rs/iced #[derive(Debug)] pub struct Backend { + #[cfg(any(feature = "image_rs", feature = "svg"))] + image_pipeline: image::Pipeline, quad_pipeline: quad::Pipeline, text_pipeline: text::Pipeline, triangle_pipeline: triangle::Pipeline, @@ -32,10 +36,14 @@ impl Backend { let shader_version = program::Version::new(gl); + #[cfg(any(feature = "image_rs", feature = "svg"))] + let image_pipeline = image::Pipeline::new(gl, &shader_version); let quad_pipeline = quad::Pipeline::new(gl, &shader_version); let triangle_pipeline = triangle::Pipeline::new(gl, &shader_version); Self { + #[cfg(any(feature = "image_rs", feature = "svg"))] + image_pipeline, quad_pipeline, text_pipeline, triangle_pipeline, @@ -70,6 +78,9 @@ impl Backend { viewport_size.height, ); } + + #[cfg(any(feature = "image_rs", feature = "svg"))] + self.image_pipeline.trim_cache(gl); } fn flush( @@ -112,6 +123,15 @@ impl Backend { ); } + #[cfg(any(feature = "image_rs", feature = "svg"))] + if !layer.images.is_empty() { + let scaled = transformation + * Transformation::scale(scale_factor, scale_factor); + + self.image_pipeline + .draw(gl, scaled, scale_factor, &layer.images); + } + if !layer.text.is_empty() { for text in layer.text.iter() { // Target physical coordinates directly to avoid blurry text @@ -236,10 +256,10 @@ impl backend::Text for Backend { } } -#[cfg(feature = "image")] +#[cfg(feature = "image_rs")] impl backend::Image for Backend { - fn dimensions(&self, _handle: &iced_native::image::Handle) -> (u32, u32) { - (50, 50) + fn dimensions(&self, handle: &iced_native::image::Handle) -> (u32, u32) { + self.image_pipeline.dimensions(handle) } } |