Skip to main content

pebble/graphics/
mod.rs

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            instance::{ComputeInstance, MaterialInstance},
13            layout::GlobalLayoutPool,
14            material::Material,
15            mesh::Mesh,
16            mipmap::init_mipmap_generator,
17            samplers::init_global_samplers,
18            texture_array::TextureArray,
19            textures::Texture,
20        },
21        render::{Backend, BackendPlugin},
22        types::flags::DeviceFeatures,
23        window::{WindowConfig, WindowPlugin},
24    },
25};
26
27pub mod pipeline;
28pub mod render;
29pub mod types;
30pub mod window;
31
32/// Windowing + GPU backend + every built-in asset type
33/// (`Mesh`/`Texture`/`TextureArray`/`Cubemap`/`Material`/`Compute`/
34/// `MaterialInstance`/`ComputeInstance`), all in one plugin. The usual
35/// starting point for an app that renders anything.
36pub struct GraphicsPlugin {
37    features: DeviceFeatures,
38    window: WindowConfig,
39}
40
41impl GraphicsPlugin {
42    pub fn new() -> Self {
43        Self {
44            features: DeviceFeatures::empty(),
45            window: WindowConfig::default(),
46        }
47    }
48
49    pub fn with_features(features: DeviceFeatures) -> Self {
50        Self {
51            features,
52            window: WindowConfig::default(),
53        }
54    }
55
56    /// Overrides the window title/size this plugin opens (default: 1280x720, "Pebble").
57    /// Don't add a separate `WindowPlugin` alongside `GraphicsPlugin` — it already
58    /// includes one, and adding both opens two windows.
59    pub fn with_window(mut self, window: WindowConfig) -> Self {
60        self.window = window;
61        self
62    }
63}
64
65impl Plugin for GraphicsPlugin {
66    fn build(self, app: crate::app::App) -> crate::app::App {
67        app.add_plugin(WindowPlugin::new(self.window))
68            .add_plugin(BackendPlugin::with_features(self.features))
69            .add_plugin(BuiltinAssetsPlugin)
70    }
71}
72
73/// Just the built-in asset types, without windowing — part of what
74/// [`GraphicsPlugin`] registers; add directly only if you're assembling
75/// your own windowing/backend setup around it.
76pub struct BuiltinAssetsPlugin;
77impl Plugin for BuiltinAssetsPlugin {
78    fn build(self, app: crate::app::App) -> crate::app::App {
79        app.insert_resource(GlobalLayoutPool::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            .add_plugin(AssetPlugin::<Backend, MaterialInstance>::new())
89            .add_plugin(AssetPlugin::<Backend, ComputeInstance>::new())
90    }
91}
92
93#[cfg(test)]
94mod test {}