WinitPlugin
This commit is contained in:
		
							parent
							
								
									ec84a33b43
								
							
						
					
					
						commit
						45d4f25a93
					
				
							
								
								
									
										27
									
								
								Cargo.toml
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								Cargo.toml
									
									
									
									
									
								
							| @ -8,27 +8,36 @@ edition = "2018" | |||||||
| default = ["wgpu", "winit"] | default = ["wgpu", "winit"] | ||||||
| 
 | 
 | ||||||
| [dependencies] | [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 } | 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" | bitflags = "1.0" | ||||||
| glam = "0.8.6" | glam = "0.8.6" | ||||||
| winit = { version = "0.22.0", optional = true } |  | ||||||
| zerocopy = "0.3" | zerocopy = "0.3" | ||||||
| log = { version = "0.4", features = ["release_max_level_info"] } |  | ||||||
| env_logger = "0.7" | env_logger = "0.7" | ||||||
| rand = "0.7.2" | rand = "0.7.2" | ||||||
| gltf = "0.14.0" |  | ||||||
| serde = { version = "1", features = ["derive"]} | serde = { version = "1", features = ["derive"]} | ||||||
| serde_json = "1.0" | serde_json = "1.0" | ||||||
| uuid = { version = "0.8", features = ["v4", "serde"] } | uuid = { version = "0.8", features = ["v4", "serde"] } | ||||||
| erased-serde = "0.3" | erased-serde = "0.3" | ||||||
| type-uuid = "0.1" | type-uuid = "0.1" | ||||||
| shaderc = "0.6" |  | ||||||
| libloading = "0.5.2" | 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 | # TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788 | ||||||
| once_cell = "1.3.1" | once_cell = "1.3.1" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     app::{system_stage, App}, |     app::{system_stage, App}, | ||||||
|     core::{window::winit::get_winit_run, CorePlugin}, |     core::{winit::WinitPlugin, CorePlugin}, | ||||||
|     legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World}, |     legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World}, | ||||||
|     plugin::{load_plugin, AppPlugin}, |     plugin::{load_plugin, AppPlugin}, | ||||||
|     render::{renderer::Renderer, *}, |     render::{renderer::Renderer, *}, | ||||||
| @ -155,31 +155,20 @@ impl AppBuilder { | |||||||
|         self |         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 { |     pub fn add_defaults(mut self) -> Self { | ||||||
|         self = self |         self = self | ||||||
|             .add_winit() |  | ||||||
|             .add_default_systems() |             .add_default_systems() | ||||||
|             .add_plugin(CorePlugin::default()) |             .add_plugin(CorePlugin::default()) | ||||||
|             .add_plugin(RenderPlugin::default()) |             .add_plugin(RenderPlugin::default()); | ||||||
|             .add_wgpu_renderer(); | 
 | ||||||
|  |         #[cfg(feature = "wgpu")] | ||||||
|  |         { | ||||||
|  |             self = self.add_wgpu_renderer(); | ||||||
|  |         } | ||||||
|         #[cfg(feature = "winit")] |         #[cfg(feature = "winit")] | ||||||
|         {} |         { | ||||||
|  |             self = self.add_plugin(WinitPlugin::default()) | ||||||
|  |         } | ||||||
|         self |         self | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,9 @@ | |||||||
| pub mod bytes; | pub mod bytes; | ||||||
| pub mod time; | mod time; | ||||||
| pub mod window; | pub mod window; | ||||||
| mod core_plugin; | mod core_plugin; | ||||||
| 
 | 
 | ||||||
| pub use bytes::GetBytes; | pub use bytes::*; | ||||||
| pub use time::Time; | pub use time::*; | ||||||
| pub use window::Window; | pub use window::*; | ||||||
| pub use core_plugin::*; | pub use core_plugin::*; | ||||||
|  | |||||||
| @ -1,13 +1,33 @@ | |||||||
| use crate::app::App; | use crate::{ | ||||||
|  |     app::{App, AppBuilder}, | ||||||
|  |     plugin::AppPlugin, | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
|  | use super::Window; | ||||||
| use winit::{ | use winit::{ | ||||||
|     event, |     event, | ||||||
|     event::WindowEvent, |     event::WindowEvent, | ||||||
|     event_loop::{ControlFlow, EventLoop}, |     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| { |     Box::new(|mut app: App| { | ||||||
|         env_logger::init(); |         env_logger::init(); | ||||||
|         let event_loop = EventLoop::new(); |         let event_loop = EventLoop::new(); | ||||||
| @ -40,10 +60,7 @@ pub fn get_winit_run() -> Box<dyn Fn(App)> { | |||||||
|                             window.height = size.height; |                             window.height = size.height; | ||||||
|                         } |                         } | ||||||
| 
 | 
 | ||||||
|                         renderer.resize( |                         renderer.resize(&mut app.world, &mut app.resources); | ||||||
|                             &mut app.world, |  | ||||||
|                             &mut app.resources, |  | ||||||
|                         ); |  | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|                 event::Event::WindowEvent { event, .. } => match event { |                 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, |             MeshResourceProvider, UiResourceProvider, | ||||||
|         }, |         }, | ||||||
|         AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments, |         AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments, | ||||||
|     }, |     }, RenderContext, | ||||||
| }; | }; | ||||||
| use crate::{ | use crate::{ | ||||||
|     app::AppBuilder, |     app::AppBuilder, | ||||||
| @ -57,6 +57,7 @@ impl AppPlugin for RenderPlugin { | |||||||
|         let mut asset_batchers = AssetBatchers::default(); |         let mut asset_batchers = AssetBatchers::default(); | ||||||
|         asset_batchers.batch_types2::<Mesh, StandardMaterial>(); |         asset_batchers.batch_types2::<Mesh, StandardMaterial>(); | ||||||
|         app = app |         app = app | ||||||
|  |             .add_resource(RenderContext::default()) | ||||||
|             .add_resource(RenderGraph::default()) |             .add_resource(RenderGraph::default()) | ||||||
|             .add_resource(AssetStorage::<Mesh>::new()) |             .add_resource(AssetStorage::<Mesh>::new()) | ||||||
|             .add_resource(AssetStorage::<Texture>::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: 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)] | #[derive(Hash, Eq, PartialEq, Debug, Ord, PartialOrd)] | ||||||
| pub struct BatchKey2 { | pub struct BatchKey2 { | ||||||
|     pub handle1: HandleId, |     pub handle1: HandleId, | ||||||
|  | |||||||
| @ -6,3 +6,18 @@ mod wgpu_type_converter; | |||||||
| pub use wgpu_render_pass::*; | pub use wgpu_render_pass::*; | ||||||
| pub use wgpu_renderer::*; | pub use wgpu_renderer::*; | ||||||
| pub use wgpu_resources::*; | 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 New Issue
	
	Block a user
	 Carter Anderson
						Carter Anderson