mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
WinitPlugin
This commit is contained in:
parent
ec84a33b43
commit
45d4f25a93
7 changed files with 76 additions and 43 deletions
27
Cargo.toml
27
Cargo.toml
|
@ -8,27 +8,36 @@ edition = "2018"
|
|||
default = ["wgpu", "winit"]
|
||||
|
||||
[dependencies]
|
||||
legion = { path = "bevy_legion", features = ["serialize"] }
|
||||
# bevy
|
||||
bevy_derive = { path = "bevy_derive" }
|
||||
bevy_transform = { path = "bevy_transform" }
|
||||
|
||||
# rendering
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "a7b0d5ae5bc0934439ef559ed145e93f0117c39a", optional = true }
|
||||
winit = { version = "0.22.0", optional = true }
|
||||
spirv-reflect = "0.2.3"
|
||||
shaderc = "0.6"
|
||||
png = "0.16.0"
|
||||
gltf = "0.14.0"
|
||||
|
||||
# ecs
|
||||
legion = { path = "bevy_legion", features = ["serialize"] }
|
||||
|
||||
# logging
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
|
||||
# misc
|
||||
bitflags = "1.0"
|
||||
glam = "0.8.6"
|
||||
winit = { version = "0.22.0", optional = true }
|
||||
zerocopy = "0.3"
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
env_logger = "0.7"
|
||||
rand = "0.7.2"
|
||||
gltf = "0.14.0"
|
||||
serde = { version = "1", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||
erased-serde = "0.3"
|
||||
type-uuid = "0.1"
|
||||
shaderc = "0.6"
|
||||
libloading = "0.5.2"
|
||||
png = "0.16.0"
|
||||
spirv-reflect = "0.2.3"
|
||||
bevy_derive = { path = "bevy_derive" }
|
||||
bevy_transform = { path = "bevy_transform" }
|
||||
# TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788
|
||||
once_cell = "1.3.1"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
app::{system_stage, App},
|
||||
core::{window::winit::get_winit_run, CorePlugin},
|
||||
core::{winit::WinitPlugin, CorePlugin},
|
||||
legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World},
|
||||
plugin::{load_plugin, AppPlugin},
|
||||
render::{renderer::Renderer, *},
|
||||
|
@ -155,31 +155,20 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "wgpu"))]
|
||||
fn add_wgpu_renderer(mut self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
pub fn add_winit(mut self) -> Self {
|
||||
self.run = Some(get_winit_run());
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "winit"))]
|
||||
pub fn add_winit(mut self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_defaults(mut self) -> Self {
|
||||
self = self
|
||||
.add_winit()
|
||||
.add_default_systems()
|
||||
.add_plugin(CorePlugin::default())
|
||||
.add_plugin(RenderPlugin::default())
|
||||
.add_wgpu_renderer();
|
||||
.add_plugin(RenderPlugin::default());
|
||||
|
||||
#[cfg(feature = "wgpu")]
|
||||
{
|
||||
self = self.add_wgpu_renderer();
|
||||
}
|
||||
#[cfg(feature = "winit")]
|
||||
{}
|
||||
{
|
||||
self = self.add_plugin(WinitPlugin::default())
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
pub mod bytes;
|
||||
pub mod time;
|
||||
mod time;
|
||||
pub mod window;
|
||||
mod core_plugin;
|
||||
|
||||
pub use bytes::GetBytes;
|
||||
pub use time::Time;
|
||||
pub use window::Window;
|
||||
pub use bytes::*;
|
||||
pub use time::*;
|
||||
pub use window::*;
|
||||
pub use core_plugin::*;
|
||||
|
|
|
@ -1,13 +1,33 @@
|
|||
use crate::app::App;
|
||||
use crate::{
|
||||
app::{App, AppBuilder},
|
||||
plugin::AppPlugin,
|
||||
};
|
||||
|
||||
use super::Window;
|
||||
use winit::{
|
||||
event,
|
||||
event::WindowEvent,
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
};
|
||||
use super::Window;
|
||||
|
||||
pub fn get_winit_run() -> Box<dyn Fn(App)> {
|
||||
#[derive(Default)]
|
||||
pub struct WinitPlugin;
|
||||
|
||||
impl AppPlugin for WinitPlugin {
|
||||
fn build(&self, mut app: AppBuilder) -> AppBuilder {
|
||||
{
|
||||
app.run = Some(get_winit_run());
|
||||
}
|
||||
|
||||
app
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"Winit"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_winit_run() -> Box<dyn Fn(App) + Send + Sync> {
|
||||
Box::new(|mut app: App| {
|
||||
env_logger::init();
|
||||
let event_loop = EventLoop::new();
|
||||
|
@ -40,10 +60,7 @@ pub fn get_winit_run() -> Box<dyn Fn(App)> {
|
|||
window.height = size.height;
|
||||
}
|
||||
|
||||
renderer.resize(
|
||||
&mut app.world,
|
||||
&mut app.resources,
|
||||
);
|
||||
renderer.resize(&mut app.world, &mut app.resources);
|
||||
}
|
||||
}
|
||||
event::Event::WindowEvent { event, .. } => match event {
|
||||
|
@ -68,4 +85,4 @@ pub fn get_winit_run() -> Box<dyn Fn(App)> {
|
|||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ use super::{
|
|||
MeshResourceProvider, UiResourceProvider,
|
||||
},
|
||||
AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments,
|
||||
},
|
||||
}, RenderContext,
|
||||
};
|
||||
use crate::{
|
||||
app::AppBuilder,
|
||||
|
@ -57,6 +57,7 @@ impl AppPlugin for RenderPlugin {
|
|||
let mut asset_batchers = AssetBatchers::default();
|
||||
asset_batchers.batch_types2::<Mesh, StandardMaterial>();
|
||||
app = app
|
||||
.add_resource(RenderContext::default())
|
||||
.add_resource(RenderGraph::default())
|
||||
.add_resource(AssetStorage::<Mesh>::new())
|
||||
.add_resource(AssetStorage::<Texture>::new())
|
||||
|
|
|
@ -5,6 +5,8 @@ use std::{any::TypeId, collections::HashMap, hash::Hash};
|
|||
|
||||
// TODO: if/when const generics land, revisit this design in favor of generic array lengths
|
||||
|
||||
// TODO: add sorting by primary / secondary handle to reduce rebinds of data
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Debug, Ord, PartialOrd)]
|
||||
pub struct BatchKey2 {
|
||||
pub handle1: HandleId,
|
||||
|
|
|
@ -6,3 +6,18 @@ mod wgpu_type_converter;
|
|||
pub use wgpu_render_pass::*;
|
||||
pub use wgpu_renderer::*;
|
||||
pub use wgpu_resources::*;
|
||||
|
||||
use crate::{app::AppBuilder, plugin::AppPlugin};
|
||||
|
||||
pub struct WgpuRendererPlugin;
|
||||
|
||||
impl AppPlugin for WgpuRendererPlugin {
|
||||
fn build(&self, app: AppBuilder) -> AppBuilder {
|
||||
// let render_context = app.resources.get_mut::<RenderContext>().unwrap();
|
||||
// render_context.renderer = Some(Box::new(WgpuRenderer::new()));
|
||||
app
|
||||
}
|
||||
fn name(&self) -> &'static str {
|
||||
"WgpuRenderer"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue