1use crate::{
2 assets::plugin::AssetPlugin,
3 ecs::{
4 plugin::Plugin,
5 system::{ENGINE_READY_PRIORITY, SystemStage},
6 system_param::IntoSystemConfig,
7 },
8 graphics::{
9 pipeline::{
10 compute::Compute,
11 cubemap::Cubemap,
12 layout::{ComputePipelineCache, GlobalLayoutPool, MaterialPipelineCache},
13 material::Material,
14 mesh::Mesh,
15 mipmap::init_mipmap_generator,
16 samplers::init_global_samplers,
17 texture_array::TextureArray,
18 textures::Texture,
19 },
20 render::{Backend, BackendPlugin},
21 types::flags::DeviceFeatures,
22 window::{WindowConfig, WindowPlugin},
23 },
24};
25
26pub mod pipeline;
27pub mod render;
28pub mod types;
29pub mod window;
30
31pub struct GraphicsPlugin {
35 features: DeviceFeatures,
36 window: WindowConfig,
37}
38
39impl GraphicsPlugin {
40 pub fn new() -> Self {
41 Self {
42 features: DeviceFeatures::empty(),
43 window: WindowConfig::default(),
44 }
45 }
46
47 pub fn with_features(features: DeviceFeatures) -> Self {
48 Self {
49 features,
50 window: WindowConfig::default(),
51 }
52 }
53
54 pub fn with_window(mut self, window: WindowConfig) -> Self {
58 self.window = window;
59 self
60 }
61}
62
63impl Plugin for GraphicsPlugin {
64 fn build(self, app: crate::app::App) -> crate::app::App {
65 app.add_plugin(WindowPlugin::new(self.window))
66 .add_plugin(BackendPlugin::with_features(self.features))
67 .add_plugin(BuiltinAssetsPlugin)
68 }
69}
70
71pub struct BuiltinAssetsPlugin;
75impl Plugin for BuiltinAssetsPlugin {
76 fn build(self, app: crate::app::App) -> crate::app::App {
77 app.insert_resource(GlobalLayoutPool::default())
78 .insert_resource(MaterialPipelineCache::default())
79 .insert_resource(ComputePipelineCache::default())
80 .add_system(SystemStage::Ready, init_global_samplers.priority(ENGINE_READY_PRIORITY))
81 .add_system(SystemStage::AssetSync, init_mipmap_generator)
82 .add_plugin(AssetPlugin::<Backend, Mesh>::new())
83 .add_plugin(AssetPlugin::<Backend, Texture>::new())
84 .add_plugin(AssetPlugin::<Backend, TextureArray>::new())
85 .add_plugin(AssetPlugin::<Backend, Cubemap>::new())
86 .add_plugin(AssetPlugin::<Backend, Material>::new())
87 .add_plugin(AssetPlugin::<Backend, Compute>::new())
88 }
89}
90
91#[cfg(test)]
92mod test {}