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

feat!: make compatible with bevy@~0.14 #23

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_pixels"
description = "Bevy plugin that uses Pixels (a tiny pixel buffer) for rendering"
version = "0.13.0"
version = "0.14.0"
authors = ["David Cristofaro <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
Expand All @@ -22,10 +22,13 @@ wayland = ["bevy/wayland"]
x11 = ["bevy/x11"]

[dependencies]
bevy = { version = "0.13", default_features = false, features = ["bevy_winit"] }
winit = { version = "0.29", features = ["rwh_05"] }
bevy = { version = "0.14", default_features = false, features = ["bevy_winit"] }
winit = { version = "0.30", features = ["rwh_06"] }
pixels = "0.13"

[patch.crates-io]
pixels = { git = "https://github.com/mkrasnitski/pixels.git", branch = "bump-wgpu-winit" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
pollster = "0.3"

Expand Down
8 changes: 4 additions & 4 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Plugin for PixelsPlugin {
);

// Ensure `Draw` and `Render` schedules execute at the correct moment.
let mut order = app.world.resource_mut::<MainScheduleOrder>();
let mut order = app.world_mut().resource_mut::<MainScheduleOrder>();
order.insert_after(PostUpdate, Draw);
order.insert_after(Draw, Render);

Expand All @@ -57,11 +57,11 @@ impl Plugin for PixelsPlugin {
// [`create_pixels`] system for this entity which will initialize the [`Pixels`] buffer.
if let Some(options) = &self.primary_window {
let mut system_state: SystemState<Query<Entity, With<PrimaryWindow>>> =
SystemState::new(&mut app.world);
let query = system_state.get(&app.world);
SystemState::new(&mut app.world_mut());
let query = system_state.get(&app.world());

if let Ok(entity) = query.get_single() {
app.world.entity_mut(entity).insert(*options);
app.world_mut().entity_mut(entity).insert(*options);
};
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use std::time::Instant;
/// Create [`PixelsWrapper`] (and underlying [`Pixels`] buffer) for all suitable [`Window`] with
/// a [`PixelsOptions`] component.
#[allow(clippy::type_complexity)]
pub fn create_pixels(
pub fn create_pixels<'win: 'static>(
mut commands: Commands,
query: Query<
(Entity, &PixelsOptions, &Window),
(With<RawHandleWrapper>, Without<PixelsWrapper>),
(With<RawHandleWrapper>, Without<PixelsWrapper<'win>>),
>,
winit_windows: NonSend<WinitWindows>,
) {
Expand Down Expand Up @@ -66,9 +66,9 @@ pub fn create_pixels(
}

/// Resize buffer and surface to window when it is resized.
pub fn window_resize(
pub fn window_resize<'win: 'static>(
mut window_resized_events: EventReader<WindowResized>,
mut query: Query<(&mut PixelsWrapper, &mut PixelsOptions, &Window)>,
mut query: Query<(&mut PixelsWrapper<'win>, &mut PixelsOptions, &Window)>,
) {
for event in window_resized_events.read() {
if let Ok((mut wrapper, mut options, window)) = query.get_mut(event.window) {
Expand All @@ -85,9 +85,9 @@ pub fn window_resize(
}

/// Resize surface to window when scale factor changes.
pub fn window_change(
pub fn window_change<'win: 'static>(
mut window_backend_scale_factor_changed_events: EventReader<WindowBackendScaleFactorChanged>,
mut query: Query<(&mut PixelsWrapper, &PixelsOptions, &Window)>,
mut query: Query<(&mut PixelsWrapper<'win>, &PixelsOptions, &Window)>,
) {
for event in window_backend_scale_factor_changed_events.read() {
if let Ok((mut wrapper, options, window)) = query.get_mut(event.window) {
Expand All @@ -105,8 +105,8 @@ fn resize_surface_to_window(wrapper: &mut PixelsWrapper, window: &Window) {
}

/// Resize buffer when width and height change.
pub fn resize_buffer(
mut query: Query<(&mut PixelsWrapper, &PixelsOptions), Changed<PixelsOptions>>,
pub fn resize_buffer<'win: 'static>(
mut query: Query<(&mut PixelsWrapper<'win>, &PixelsOptions), Changed<PixelsOptions>>,
) {
for (mut wrapper, options) in &mut query {
if options.auto_resize_buffer {
Expand All @@ -117,10 +117,10 @@ pub fn resize_buffer(

/// Render buffer to surface.
#[cfg(feature = "render")]
pub fn render(
pub fn render<'win: 'static>(
// TODO: Support `RENDER_TIME` diagnostics on web.
#[cfg(not(target_arch = "wasm32"))] mut diagnostics: Diagnostics,
query: Query<&PixelsWrapper>,
query: Query<&PixelsWrapper<'win>>,
) {
#[cfg(not(target_arch = "wasm32"))]
let start = Instant::now();
Expand Down
4 changes: 2 additions & 2 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use pixels::Pixels;

/// Wrapper component for underlying [`Pixels`] struct.
#[derive(Component, Debug)]
pub struct PixelsWrapper {
pub pixels: Pixels,
pub struct PixelsWrapper<'win> {
pub pixels: Pixels<'win>,
}