Skip to content

Commit

Permalink
update to bevy 0.9 dev (#127)
Browse files Browse the repository at this point in the history
* update to bevy 0.9 dev

* Update the dependencies

* Fix texture formats

* Fix disabling WinitPlugin in tests

Co-authored-by: mvlabat <mvlabat@gmail.com>
  • Loading branch information
terhechte and mvlabat authored Nov 13, 2022
1 parent 85aff3b commit c906611
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 67 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ open_url = ["webbrowser"]
default_fonts = ["egui/default_fonts"]

[dependencies]
bevy = { version = "0.8", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }
bevy = { version = "0.9.0", default-features = false, features = ["bevy_render", "bevy_core_pipeline", "bevy_asset"] }
egui = { version = "0.19.0", default-features = false, features = ["bytemuck"] }
webbrowser = { version = "0.7", optional = true }
webbrowser = { version = "0.8.2", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
arboard = { version = "2.0.1", optional = true }
thread_local = { version = "1.1.0", optional = true }

[dev-dependencies]
once_cell = "1.9.0"
version-sync = "0.9.2"
bevy = { version = "0.8", default-features = false, features = [
once_cell = "1.16.0"
version-sync = "0.9.4"
bevy = { version = "0.9.0", default-features = false, features = [
"x11",
"png",
"bevy_pbr",
Expand Down
12 changes: 6 additions & 6 deletions examples/render_to_image_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct PreviewPassCube;
#[derive(Component)]
struct MainPassCube;

#[derive(Deref)]
#[derive(Deref, Resource)]
struct CubePreviewImage(Handle<Image>);

fn setup(
Expand Down Expand Up @@ -83,7 +83,7 @@ fn setup(

// The cube that will be rendered to the texture.
commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: cube_handle,
material: preview_material_handle,
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
Expand All @@ -94,13 +94,13 @@ fn setup(

// Light
// NOTE: Currently lights are shared between passes - see https://github.com/bevyengine/bevy/issues/3462
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 10.0)),
..default()
});

commands
.spawn_bundle(Camera3dBundle {
.spawn(Camera3dBundle {
camera_3d: Camera3d {
clear_color: ClearColorConfig::Custom(Color::rgba(1.0, 1.0, 1.0, 0.0)),
..default()
Expand All @@ -124,7 +124,7 @@ fn setup(

// Main pass cube.
commands
.spawn_bundle(PbrBundle {
.spawn(PbrBundle {
mesh: cube_handle,
material: main_material_handle,
transform: Transform {
Expand All @@ -137,7 +137,7 @@ fn setup(
.insert(MainPassCube);

// The main pass camera.
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: Transform::from_translation(Vec3::new(0.0, 0.0, 15.0))
.looking_at(Vec3::default(), Vec3::Y),
..default()
Expand Down
11 changes: 6 additions & 5 deletions examples/side_panel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::{prelude::*, render::camera::Projection};
use bevy_egui::{egui, EguiContext, EguiPlugin};

#[derive(Default)]
#[derive(Default, Resource)]
struct OccupiedScreenSpace {
left: f32,
top: f32,
Expand All @@ -11,6 +11,7 @@ struct OccupiedScreenSpace {

const CAMERA_TARGET: Vec3 = Vec3::ZERO;

#[derive(Resource)]
struct OriginalCameraTransform(Transform);

fn main() {
Expand Down Expand Up @@ -67,18 +68,18 @@ fn setup_system(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
commands.spawn_bundle(PbrBundle {
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..Default::default()
});
commands.spawn_bundle(PointLightBundle {
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
Expand All @@ -93,7 +94,7 @@ fn setup_system(
Transform::from_translation(camera_pos).looking_at(CAMERA_TARGET, Vec3::Y);
commands.insert_resource(OriginalCameraTransform(camera_transform));

commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
transform: camera_transform,
..Default::default()
});
Expand Down
5 changes: 3 additions & 2 deletions examples/two_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use once_cell::sync::Lazy;

static SECOND_WINDOW_ID: Lazy<WindowId> = Lazy::new(WindowId::new);

#[derive(Resource)]
struct Images {
bevy_icon: Handle<Image>,
}
Expand Down Expand Up @@ -51,7 +52,7 @@ fn create_new_window(mut create_window_events: EventWriter<CreateWindow>, mut co
},
});
// second window camera
commands.spawn_bundle(Camera3dBundle {
commands.spawn(Camera3dBundle {
camera: Camera {
target: RenderTarget::Window(*SECOND_WINDOW_ID),
..Default::default()
Expand All @@ -72,7 +73,7 @@ struct UiState {
input: String,
}

#[derive(Default)]
#[derive(Default, Resource)]
struct SharedUiState {
shared_input: String,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() {
.add_system(ui_example)
.run();
}
#[derive(Default)]
#[derive(Default, Resource)]
struct UiState {
label: String,
value: f32,
Expand Down
13 changes: 9 additions & 4 deletions src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::render_systems::{
use bevy::{
core::cast_slice,
ecs::world::{FromWorld, World},
prelude::Resource,
render::{
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::{
Expand All @@ -20,12 +21,13 @@ use bevy::{
VertexStepMode,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::{BevyDefault, Image},
texture::Image,
view::ExtractedWindows,
},
window::WindowId,
};

#[derive(Resource)]
pub struct EguiPipeline {
pipeline: RenderPipeline,

Expand Down Expand Up @@ -118,7 +120,7 @@ impl FromWorld for EguiPipeline {
module: &shader_module,
entry_point: "fs_main",
targets: &[Some(ColorTargetState {
format: TextureFormat::bevy_default(),
format: TextureFormat::Bgra8UnormSrgb,
blend: Some(BlendState {
color: BlendComponent {
src_factor: BlendFactor::One,
Expand Down Expand Up @@ -422,7 +424,10 @@ pub(crate) fn color_image_as_bevy_image(egui_image: &egui::ColorImage) -> Image
// We unmultiply Egui textures to premultiply them later in the fragment shader.
// As user textures loaded as Bevy assets are not premultiplied (and there seems to be no
// convenient way to convert them to premultiplied ones), we do the this with Egui ones.
.flat_map(|color| color.to_srgba_unmultiplied())
.flat_map(|color| {
let [r, g, b, a] = color.to_srgba_unmultiplied();
[b, g, r, a]
})
.collect();

Image::new(
Expand All @@ -433,6 +438,6 @@ pub(crate) fn color_image_as_bevy_image(egui_image: &egui::ColorImage) -> Image
},
TextureDimension::D2,
pixels,
TextureFormat::Rgba8UnormSrgb,
TextureFormat::Bgra8UnormSrgb,
)
}
Loading

0 comments on commit c906611

Please sign in to comment.