From 16be3cf028caa15f91b03c18953586f564d2fff3 Mon Sep 17 00:00:00 2001 From: "Spencer C. Imbleau" Date: Sun, 4 Aug 2024 15:05:04 -0400 Subject: [PATCH] fix: runtime swapping of render settings --- CHANGELOG.md | 1 + src/render/mod.rs | 10 ++++------ src/render/plugin.rs | 5 ++++- src/render/systems.rs | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ccb586..e811896 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/src/render/mod.rs b/src/render/mod.rs index f6556ae..9fbddc0 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -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, }, ) @@ -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::().unwrap(); settings.use_cpu = true; + settings.antialiasing = AaConfig::Area; } match VelloRenderer::try_new( world.get_resource::().unwrap().wgpu_device(), diff --git a/src/render/plugin.rs b/src/render/plugin.rs index 6b0b828..0fb258c 100644 --- a/src/render/plugin.rs +++ b/src/render/plugin.rs @@ -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, ( diff --git a/src/render/systems.rs b/src/render/systems.rs index 1ecf3ab..4afab4e 100644 --- a/src/render/systems.rs +++ b/src/render/systems.rs @@ -336,8 +336,9 @@ pub fn render_settings_change_detection( mut commands: Commands, render_settings: Res, ) { - 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::(); commands.init_resource::(); }