Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update with_bevy demo package #406

Merged
merged 12 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [

"examples/headless",
"examples/with_winit",
# "examples/with_bevy", # Disable for now until bevy is using wgpu 0.17
"examples/with_bevy",
"examples/run_wasm",
"examples/scenes",
]
Expand Down
2 changes: 1 addition & 1 deletion examples/with_bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.11"
bevy = "0.12"
vello = { path = "../../" }
17 changes: 12 additions & 5 deletions examples/with_bevy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::render::{Render, RenderSet};
use vello::kurbo::{Affine, Point, Rect};
use vello::peniko::{Color, Fill, Gradient, Stroke};
use vello::kurbo::{Affine, Point, Rect, Stroke};
use vello::peniko::{Color, Fill, Gradient};
use vello::{Renderer, RendererOptions, Scene, SceneBuilder, SceneFragment};

use bevy::{
Expand All @@ -19,6 +19,8 @@ use bevy::{
#[derive(Resource)]
struct VelloRenderer(Renderer);

unsafe impl Sync for VelloRenderer {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change VelloRenderer to use SyncCell instead of adding this implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the suggestion! I have no idea it can be done like this!


impl FromWorld for VelloRenderer {
fn from_world(world: &mut World) -> Self {
let device = world.resource::<RenderDevice>();
Expand All @@ -27,10 +29,11 @@ impl FromWorld for VelloRenderer {
VelloRenderer(
Renderer::new(
device.wgpu_device(),
&RendererOptions {
RendererOptions {
surface_format: None,
timestamp_period: queue.0.get_timestamp_period(),
antialiasing_support: vello::AaSupport::area_only(),
use_cpu: false,
},
)
.unwrap(),
Expand All @@ -42,13 +45,17 @@ struct VelloPlugin;

impl Plugin for VelloPlugin {
fn build(&self, app: &mut App) {
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return };
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
// This should probably use the render graph, but working out the dependencies there is awkward
render_app.add_systems(Render, render_scenes.in_set(RenderSet::Render));
}

fn finish(&self, app: &mut App) {
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else { return };
let Ok(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
};
render_app.init_resource::<VelloRenderer>();
}
}
Expand Down