Skip to content

Commit

Permalink
fix: runtime swapping of render settings
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Aug 4, 2024
1 parent 4e5cb8b commit 16be3cf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Subheadings to categorize changes are `added, changed, deprecated, removed, fixe

- `VelloPlugin` now has configuration. To retain previous behavior, use `VelloPlugin::default()`.
- `VelloRenderer` is now a resource.
- The `VelloRenderer` will attempt CPU fallback if it cannot obtain a GPU.
- The font API has changed significantly. Please visit `examples/text` for further usage. This is to prepare for additional text features such as linebreak behavior, bounded text, and text justification.
- `VelloText` has been renamed to `VelloTextSection`.
- `VelloText.content` has been renamed to `VelloText.value`.
Expand Down
10 changes: 4 additions & 6 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ impl VelloRenderer {
vello::RendererOptions {
surface_format: None,
use_cpu: settings.use_cpu,
antialiasing_support: AaSupport {
area: settings.antialiasing == AaConfig::Area,
msaa8: settings.antialiasing == AaConfig::Msaa8,
msaa16: settings.antialiasing == AaConfig::Msaa16,
},
// TODO: Vello doesn't currently allow adding additional AA support after initialization, so we need to use all support modes here instead.
antialiasing_support: AaSupport::all(),
num_init_threads: None,
},
)
Expand All @@ -98,10 +95,11 @@ impl FromWorld for VelloRenderer {
) {
Ok(r) => r,
Err(e) => {
error!("Attempting CPU fallback, failed to initialize renderer: {e:}");
error!("Attempting safe-mode fallback, failed to initialize renderer: {e:}");
{
let mut settings = world.get_resource_mut::<VelloRenderSettings>().unwrap();
settings.use_cpu = true;
settings.antialiasing = AaConfig::Area;
}
match VelloRenderer::try_new(
world.get_resource::<RenderDevice>().unwrap().wgpu_device(),
Expand Down
5 changes: 4 additions & 1 deletion src/render/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ impl Plugin for VelloRenderPlugin {
render_app
.insert_resource(self.render_settings.clone())
.insert_resource(ExtractedPixelScale(1.0))
.add_systems(Update, systems::render_settings_change_detection)
.add_systems(
Render,
systems::render_settings_change_detection.in_set(RenderSet::Cleanup),
)
.add_systems(
ExtractSchedule,
(
Expand Down
3 changes: 2 additions & 1 deletion src/render/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ pub fn render_settings_change_detection(
mut commands: Commands,
render_settings: Res<VelloRenderSettings>,
) {
if render_settings.is_changed() {
if render_settings.is_changed() && !render_settings.is_added() {
// Replace renderer
info!("Render settings changed, re-initializing vello...");
commands.remove_resource::<VelloRenderer>();
commands.init_resource::<VelloRenderer>();
}
Expand Down

0 comments on commit 16be3cf

Please sign in to comment.