Skip to content

Commit 46d6f1d

Browse files
committed
update build instructions
1 parent dffb453 commit 46d6f1d

6 files changed

Lines changed: 53 additions & 14 deletions

File tree

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ memmap2 = "0.9.5"
7777
url = "2.5.4"
7878

7979
[profile.release]
80-
codegen-units = 1 # reduces binary size by ~2%
80+
strip = "symbols" # See split-debuginfo - allows us to drop the size by ~65%
81+
split-debuginfo = "packed" # generates a separate *.dwp/*.dSYM so the binary can get stripped
8182
debug = "full" # No one needs an undebuggable release binary
83+
codegen-units = 1
84+
incremental = false
8285
lto = true # reduces binary size by ~14%
83-
opt-level = "s" # reduces binary size by ~25%
8486
panic = "abort" # reduces binary size by ~50% in combination with -Zbuild-std-features=panic_immediate_abort
85-
split-debuginfo = "packed" # generates a separate *.dwp/*.dSYM so the binary can get stripped
86-
strip = "symbols" # See split-debuginfo - allows us to drop the size by ~65%
87+
# opt-level = "s" # reduces binary size by ~25%
8788

8889
[profile.dev]
8990
split-debuginfo = "unpacked"

sugarloaf/examples/f16_test.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rio_window::{
77
};
88
use std::error::Error;
99
use sugarloaf::{
10-
layout::RootStyle, FragmentStyle, Sugarloaf, SugarloafWindow, SugarloafWindowSize,
10+
layout::RootStyle, RichText, Object, FragmentStyle, Sugarloaf, SugarloafWindow, SugarloafWindowSize,
1111
};
1212

1313
fn main() {
@@ -146,7 +146,6 @@ impl ApplicationHandler for Application {
146146
},
147147
)
148148
.new_line()
149-
.new_line()
150149
.add_text(
151150
"Texture Formats:",
152151
FragmentStyle {
@@ -183,9 +182,15 @@ impl ApplicationHandler for Application {
183182
color: [0.7, 0.7, 0.7, 1.0],
184183
..FragmentStyle::default()
185184
},
186-
);
187-
188-
let _ = sugarloaf.render();
185+
)
186+
.build();
187+
188+
sugarloaf.set_objects(vec![Object::RichText(RichText {
189+
id: self.rich_text,
190+
position: [10., 0.],
191+
lines: None,
192+
})]);
193+
sugarloaf.render();
189194
}
190195
_ => {}
191196
}

sugarloaf/src/components/layer/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,29 @@ impl LayerBrush {
506506
}
507507
}
508508

509+
pub fn clear_atlas(
510+
&mut self,
511+
device: &wgpu::Device,
512+
backend: wgpu::Backend,
513+
context: &crate::context::Context,
514+
) {
515+
self.texture_atlas.clear(device, backend, context);
516+
self.texture_version = self.texture_atlas.layer_count();
517+
518+
// Recreate the bind group with the new atlas
519+
self.texture = device.create_bind_group(&wgpu::BindGroupDescriptor {
520+
label: Some("image texture atlas bind group"),
521+
layout: &self.texture_layout,
522+
entries: &[wgpu::BindGroupEntry {
523+
binding: 0,
524+
resource: wgpu::BindingResource::TextureView(self.texture_atlas.view()),
525+
}],
526+
});
527+
528+
// Clear the raster cache as well
529+
self.raster_cache.borrow_mut().clear();
530+
}
531+
509532
pub fn end_frame(&mut self) {
510533
self.raster_cache.borrow_mut().trim(&mut self.texture_atlas);
511534

sugarloaf/src/components/layer/raster.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ impl Cache {
122122
}
123123
}
124124

125+
/// Clear all cached images
126+
pub fn clear(&mut self) {
127+
self.map.clear();
128+
self.hits.clear();
129+
}
130+
125131
/// Trim cache misses from cache
126132
pub fn trim(&mut self, atlas: &mut Atlas) {
127133
let hits = &self.hits;

sugarloaf/src/context/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,8 @@ impl Context<'_> {
240240
}
241241

242242
pub fn get_optimal_texture_sample_type(&self) -> wgpu::TextureSampleType {
243-
if self.supports_f16 {
244-
wgpu::TextureSampleType::Float { filterable: true }
245-
} else {
246-
wgpu::TextureSampleType::Float { filterable: true }
247-
}
243+
// Both Rgba16Float (f16) and Rgba8Unorm (f32) use Float sample type with filtering
244+
wgpu::TextureSampleType::Float { filterable: true }
248245
}
249246

250247
pub fn convert_rgba8_to_optimal_format(&self, rgba8_data: &[u8]) -> Vec<u8> {

sugarloaf/src/sugarloaf.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ impl Sugarloaf<'_> {
148148
// Clear the atlas to remove old font glyphs
149149
self.rich_text_brush.clear_atlas();
150150

151+
// Clear the layer atlas to remove old cached images
152+
self.layer_brush.clear_atlas(
153+
&self.ctx.device,
154+
self.ctx.adapter_info.backend,
155+
&self.ctx,
156+
);
157+
151158
self.state.reset();
152159
self.state
153160
.set_fonts(font_library, &mut self.rich_text_brush);

0 commit comments

Comments
 (0)