summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-08 13:22:22 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-05-08 13:41:12 +0200
commitbed53f81436c595e479009427e1fa4ff4a1048d3 (patch)
tree1905c66186c1f68513cdd0fdbbd82ec6b67ac8d3 /wgpu
parent447f3a2d14ab1c4bc20e232df1aa2375623af2de (diff)
downloadiced-bed53f81436c595e479009427e1fa4ff4a1048d3.tar.gz
iced-bed53f81436c595e479009427e1fa4ff4a1048d3.tar.bz2
iced-bed53f81436c595e479009427e1fa4ff4a1048d3.zip
Reuse `glyphon::Viewport` explicitly
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/src/lib.rs13
-rw-r--r--wgpu/src/text.rs42
2 files changed, 38 insertions, 17 deletions
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index 1fbdbe9a..ad88ce3e 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -79,6 +79,7 @@ pub struct Renderer {
triangle_storage: triangle::Storage,
text_storage: text::Storage,
+ text_viewport: text::Viewport,
// TODO: Centralize all the image feature handling
#[cfg(any(feature = "svg", feature = "image"))]
@@ -87,8 +88,8 @@ pub struct Renderer {
impl Renderer {
pub fn new(
- _device: &wgpu::Device,
- _engine: &Engine,
+ device: &wgpu::Device,
+ engine: &Engine,
default_font: Font,
default_text_size: Pixels,
) -> Self {
@@ -99,10 +100,11 @@ impl Renderer {
triangle_storage: triangle::Storage::new(),
text_storage: text::Storage::new(),
+ text_viewport: engine.text_pipeline.create_viewport(device),
#[cfg(any(feature = "svg", feature = "image"))]
image_cache: std::cell::RefCell::new(
- _engine.create_image_cache(_device),
+ engine.create_image_cache(device),
),
}
}
@@ -141,6 +143,8 @@ impl Renderer {
) {
let scale_factor = viewport.scale_factor() as f32;
+ self.text_viewport.update(queue, viewport.physical_size());
+
for layer in self.layers.iter_mut() {
if !layer.quads.is_empty() {
engine.quad_pipeline.prepare(
@@ -182,12 +186,12 @@ impl Renderer {
engine.text_pipeline.prepare(
device,
queue,
+ &self.text_viewport,
encoder,
&mut self.text_storage,
&layer.text,
layer.bounds,
Transformation::scale(scale_factor),
- viewport.physical_size(),
);
}
@@ -357,6 +361,7 @@ impl Renderer {
if !layer.text.is_empty() {
text_layer += engine.text_pipeline.render(
+ &self.text_viewport,
&self.text_storage,
text_layer,
&layer.text,
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index 68741461..9ecd5c99 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -113,13 +113,13 @@ impl Storage {
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
+ viewport: &glyphon::Viewport,
encoder: &mut wgpu::CommandEncoder,
format: wgpu::TextureFormat,
pipeline: &glyphon::Pipeline,
cache: &Cache,
new_transformation: Transformation,
bounds: Rectangle,
- target_size: Size<u32>,
) {
let group_count = self.groups.len();
@@ -152,6 +152,7 @@ impl Storage {
let _ = prepare(
device,
queue,
+ viewport,
encoder,
&mut upload.renderer,
&mut group.atlas,
@@ -159,7 +160,6 @@ impl Storage {
&cache.text,
bounds,
new_transformation,
- target_size,
);
}
@@ -189,6 +189,7 @@ impl Storage {
let _ = prepare(
device,
queue,
+ viewport,
encoder,
&mut renderer,
&mut group.atlas,
@@ -196,7 +197,6 @@ impl Storage {
&cache.text,
bounds,
new_transformation,
- target_size,
);
}
@@ -258,6 +258,20 @@ impl Storage {
}
}
+pub struct Viewport(glyphon::Viewport);
+
+impl Viewport {
+ pub fn update(&mut self, queue: &wgpu::Queue, resolution: Size<u32>) {
+ self.0.update(
+ queue,
+ glyphon::Resolution {
+ width: resolution.width,
+ height: resolution.height,
+ },
+ );
+ }
+}
+
#[allow(missing_debug_implementations)]
pub struct Pipeline {
state: glyphon::Pipeline,
@@ -293,12 +307,12 @@ impl Pipeline {
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
+ viewport: &Viewport,
encoder: &mut wgpu::CommandEncoder,
storage: &mut Storage,
batch: &Batch,
layer_bounds: Rectangle,
layer_transformation: Transformation,
- target_size: Size<u32>,
) {
for item in batch {
match item {
@@ -319,6 +333,7 @@ impl Pipeline {
let result = prepare(
device,
queue,
+ &viewport.0,
encoder,
renderer,
&mut self.atlas,
@@ -326,7 +341,6 @@ impl Pipeline {
text,
layer_bounds * layer_transformation,
layer_transformation * *transformation,
- target_size,
);
match result {
@@ -347,13 +361,13 @@ impl Pipeline {
storage.prepare(
device,
queue,
+ &viewport.0,
encoder,
self.format,
&self.state,
cache,
layer_transformation * *transformation,
layer_bounds * layer_transformation,
- target_size,
);
}
}
@@ -362,6 +376,7 @@ impl Pipeline {
pub fn render<'a>(
&'a self,
+ viewport: &'a Viewport,
storage: &'a Storage,
start: usize,
batch: &'a Batch,
@@ -383,7 +398,7 @@ impl Pipeline {
let renderer = &self.renderers[start + layer_count];
renderer
- .render(&self.atlas, render_pass)
+ .render(&self.atlas, &viewport.0, render_pass)
.expect("Render text");
layer_count += 1;
@@ -392,7 +407,7 @@ impl Pipeline {
if let Some((atlas, upload)) = storage.get(cache) {
upload
.renderer
- .render(atlas, render_pass)
+ .render(atlas, &viewport.0, render_pass)
.expect("Render cached text");
}
}
@@ -402,6 +417,10 @@ impl Pipeline {
layer_count
}
+ pub fn create_viewport(&self, device: &wgpu::Device) -> Viewport {
+ Viewport(glyphon::Viewport::new(device, &self.state))
+ }
+
pub fn end_frame(&mut self) {
self.atlas.trim();
self.cache.trim();
@@ -413,6 +432,7 @@ impl Pipeline {
fn prepare(
device: &wgpu::Device,
queue: &wgpu::Queue,
+ viewport: &glyphon::Viewport,
encoder: &mut wgpu::CommandEncoder,
renderer: &mut glyphon::TextRenderer,
atlas: &mut glyphon::TextAtlas,
@@ -420,7 +440,6 @@ fn prepare(
sections: &[Text],
layer_bounds: Rectangle,
layer_transformation: Transformation,
- target_size: Size<u32>,
) -> Result<(), glyphon::PrepareError> {
let mut font_system = font_system().write().expect("Write font system");
let font_system = font_system.raw();
@@ -617,10 +636,7 @@ fn prepare(
encoder,
font_system,
atlas,
- glyphon::Resolution {
- width: target_size.width,
- height: target_size.height,
- },
+ viewport,
text_areas,
&mut glyphon::SwashCache::new(),
)