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

Bevy 0.7 #79

Merged
merged 8 commits into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ multi_threaded = ["egui/multi_threaded"]
open_url = ["webbrowser"]

[dependencies]
bevy = { version = "0.6", default-features = false, features = [
bevy = { version = "0.7", default-features = false, features = [
"bevy_render",
"bevy_winit",
"bevy_core_pipeline"
"bevy_core_pipeline",
] }
# bevy = { version = "0.6", default-features = false, features = [
aevyrie marked this conversation as resolved.
Show resolved Hide resolved
# "bevy_render",
# "bevy_winit",
# "bevy_core_pipeline"
# ] }
egui = { version = "0.17", features = ["convert_bytemuck"] }
webbrowser = { version = "0.5.5", optional = true }
winit = { version = "0.26.0", features = ["x11"], default-features = false }
Expand All @@ -35,6 +40,10 @@ arboard = { version = "2.0.1", optional = true }
thread_local = { version = "1.1.0", optional = true }

[dev-dependencies]
bevy = "0.6"
once_cell = "1.9.0"
version-sync = "0.9.2"
bevy = { version = "0.7", default-features = false, features = [
"x11",
"png",
"bevy_pbr",
] }
7 changes: 6 additions & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
use bevy_egui::{egui, EguiContext, EguiPlugin};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.insert_resource(WinitSettings::desktop_app())
.insert_resource(WindowDescriptor {
present_mode: PresentMode::Mailbox,
Copy link
Owner

@mvlabat mvlabat Apr 16, 2022

Choose a reason for hiding this comment

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

Is PresentMode::Mailbox needed in this example?

..Default::default()
})
.add_plugin(EguiPlugin)
.add_system(ui_example)
.run();
Expand Down
64 changes: 7 additions & 57 deletions examples/two_windows.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use bevy::{
core_pipeline::{draw_3d_graph, node, AlphaMask3d, Opaque3d, Transparent3d},
prelude::*,
render::{
camera::{ActiveCameras, ExtractedCameraNames},
render_graph::{Node, NodeRunError, RenderGraph, RenderGraphContext, SlotValue},
render_phase::RenderPhase,
renderer::RenderContext,
RenderApp, RenderStage,
},
window::{CreateWindow, WindowId},
render::{camera::RenderTarget, render_graph::RenderGraph, RenderApp},
window::{CreateWindow, PresentMode, WindowId},
winit::WinitSettings,
};
use bevy_egui::{EguiContext, EguiPlugin};
use once_cell::sync::Lazy;
Expand All @@ -22,6 +16,7 @@ struct Images {
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.insert_resource(WinitSettings::desktop_app())
.add_plugin(EguiPlugin)
.init_resource::<SharedUiState>()
.add_startup_system(load_assets)
Expand All @@ -30,12 +25,7 @@ fn main() {
.add_system(ui_second_window);

let render_app = app.sub_app_mut(RenderApp);
render_app.add_system_to_stage(RenderStage::Extract, extract_secondary_camera_phases);
let mut graph = render_app.world.get_resource_mut::<RenderGraph>().unwrap();
graph.add_node(SECONDARY_PASS_DRIVER, SecondaryCameraDriver);
graph
.add_node_edge(node::MAIN_PASS_DEPENDENCIES, SECONDARY_PASS_DRIVER)
.unwrap();

bevy_egui::setup_pipeline(
&mut graph,
Expand All @@ -48,50 +38,29 @@ fn main() {
app.run();
}

fn extract_secondary_camera_phases(mut commands: Commands, active_cameras: Res<ActiveCameras>) {
if let Some(secondary) = active_cameras.get(SECONDARY_CAMERA_NAME) {
if let Some(entity) = secondary.entity {
commands.get_or_spawn(entity).insert_bundle((
RenderPhase::<Opaque3d>::default(),
RenderPhase::<AlphaMask3d>::default(),
RenderPhase::<Transparent3d>::default(),
));
}
}
}

const SECONDARY_CAMERA_NAME: &str = "Secondary";
const SECONDARY_PASS_DRIVER: &str = "secondary_pass_driver";
const SECONDARY_EGUI_PASS: &str = "secondary_egui_pass";

fn create_new_window(
mut create_window_events: EventWriter<CreateWindow>,
mut commands: Commands,
mut active_cameras: ResMut<ActiveCameras>,
) {
fn create_new_window(mut create_window_events: EventWriter<CreateWindow>, mut commands: Commands) {
// sends out a "CreateWindow" event, which will be received by the windowing backend
create_window_events.send(CreateWindow {
id: *SECOND_WINDOW_ID,
descriptor: WindowDescriptor {
width: 800.,
height: 600.,
vsync: false,
present_mode: PresentMode::Mailbox,
title: "Second window".to_string(),
..Default::default()
},
});
// second window camera
commands.spawn_bundle(PerspectiveCameraBundle {
camera: Camera {
window: *SECOND_WINDOW_ID,
name: Some(SECONDARY_CAMERA_NAME.into()),
target: RenderTarget::Window(*SECOND_WINDOW_ID),
..Default::default()
},
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});

active_cameras.add(SECONDARY_CAMERA_NAME);
}

fn load_assets(mut commands: Commands, assets: Res<AssetServer>) {
Expand All @@ -100,25 +69,6 @@ fn load_assets(mut commands: Commands, assets: Res<AssetServer>) {
});
}

struct SecondaryCameraDriver;
impl Node for SecondaryCameraDriver {
fn run(
&self,
graph: &mut RenderGraphContext,
_render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
let extracted_cameras = world.get_resource::<ExtractedCameraNames>().unwrap();
if let Some(camera_3d) = extracted_cameras.entities.get(SECONDARY_CAMERA_NAME) {
graph.run_sub_graph(
crate::draw_3d_graph::NAME,
vec![SlotValue::Entity(*camera_3d)],
)?;
}
Ok(())
}
}

#[derive(Default)]
struct UiState {
input: String,
Expand Down
7 changes: 6 additions & 1 deletion examples/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::prelude::*;
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
use bevy_egui::{egui, EguiContext, EguiPlugin, EguiSettings};

struct Images {
Expand Down Expand Up @@ -26,7 +26,12 @@ fn main() {
.insert_resource(Msaa { samples: 4 })
.init_resource::<UiState>()
.add_plugins(DefaultPlugins)
.insert_resource(WinitSettings::desktop_app())
.add_plugin(EguiPlugin)
.insert_resource(WindowDescriptor {
present_mode: PresentMode::Mailbox,
..Default::default()
})
.add_startup_system(configure_visuals)
.add_system(update_ui_scale_factor)
.add_system(ui_example)
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ pub fn setup_pipeline(render_graph: &mut RenderGraph, config: RenderGraphConfig)
#[cfg(test)]
mod tests {
use super::*;
use bevy::{render::options::WgpuOptions, winit::WinitPlugin, DefaultPlugins};
use bevy::{render::settings::WgpuSettings, winit::WinitPlugin, DefaultPlugins};

#[test]
fn test_readme_deps() {
Expand All @@ -608,7 +608,7 @@ mod tests {
#[test]
fn test_headless_mode() {
App::new()
.insert_resource(WgpuOptions {
.insert_resource(WgpuSettings {
backends: None,
..Default::default()
})
Expand Down
20 changes: 14 additions & 6 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ use crate::{EguiContext, EguiInput, EguiOutput, EguiRenderOutput, EguiSettings,
#[cfg(feature = "open_url")]
use bevy::log;
use bevy::{
app::EventReader,
core::Time,
ecs::system::{Local, Res, ResMut, SystemParam},
ecs::{
event::EventWriter,
system::{Local, Res, ResMut, SystemParam},
},
input::{
keyboard::{KeyCode, KeyboardInput},
mouse::{MouseButton, MouseButtonInput, MouseScrollUnit, MouseWheel},
ElementState, Input,
},
prelude::{EventReader, NonSend},
utils::HashMap,
window::{
CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, WindowCreated, WindowFocused,
WindowId, Windows,
CursorEntered, CursorLeft, CursorMoved, ReceivedCharacter, RequestRedraw, WindowCreated,
WindowFocused, WindowId, Windows,
},
winit::WinitWindows,
};
Expand Down Expand Up @@ -341,7 +344,8 @@ pub fn process_output(
mut egui_output: ResMut<HashMap<WindowId, EguiOutput>>,
mut egui_render_output: ResMut<HashMap<WindowId, EguiRenderOutput>>,
#[cfg(feature = "manage_clipboard")] mut egui_clipboard: ResMut<crate::EguiClipboard>,
winit_windows: Option<Res<WinitWindows>>,
winit_windows: Option<NonSend<WinitWindows>>,
mut event: EventWriter<RequestRedraw>,
) {
let window_ids: Vec<_> = egui_context.ctx.keys().copied().collect();
for window_id in window_ids {
Expand All @@ -350,7 +354,7 @@ pub fn process_output(
platform_output,
shapes,
textures_delta,
needs_repaint: _, // TODO: only repaint if needed
needs_repaint,
} = full_output;

let egui_render_output = egui_render_output.entry(window_id).or_default();
Expand All @@ -373,6 +377,10 @@ pub fn process_output(
}
}

if needs_repaint {
event.send(RequestRedraw)
}

// TODO: see if we can support `new_tab`.
#[cfg(feature = "open_url")]
if let Some(egui::output::OpenUrl {
Expand Down