diff --git a/examples/animation/main.rs b/examples/animation/main.rs index 1e4a4e4ec0..4b169ef241 100644 --- a/examples/animation/main.rs +++ b/examples/animation/main.rs @@ -35,7 +35,7 @@ use amethyst_rendy::{ use serde::{Deserialize, Serialize}; type MyPrefabData = ( - Option, Vec, Vec, Vec), f32>>, + Option, Vec, Vec, Vec)>>, Option>, ); diff --git a/examples/arc_ball_camera/main.rs b/examples/arc_ball_camera/main.rs index 12e8c98ad9..75c555f7d8 100644 --- a/examples/arc_ball_camera/main.rs +++ b/examples/arc_ball_camera/main.rs @@ -17,7 +17,7 @@ use amethyst::{ }; use std::hash::Hash; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; struct ExampleState; diff --git a/examples/custom_game_data/main.rs b/examples/custom_game_data/main.rs index 7cbe2531a1..b398b42f46 100644 --- a/examples/custom_game_data/main.rs +++ b/examples/custom_game_data/main.rs @@ -27,7 +27,7 @@ use amethyst::{ mod example_system; mod game_data; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; pub struct DemoState { light_angle: f32, diff --git a/examples/custom_ui/main.rs b/examples/custom_ui/main.rs index 124747796e..3d451a69d4 100644 --- a/examples/custom_ui/main.rs +++ b/examples/custom_ui/main.rs @@ -26,7 +26,7 @@ use amethyst::{ use serde::Deserialize; -type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec), f32>; +type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec)>; #[derive(Clone, Deserialize)] enum CustomUi { diff --git a/examples/fly_camera/main.rs b/examples/fly_camera/main.rs index 9a053c77ea..3e14035e50 100644 --- a/examples/fly_camera/main.rs +++ b/examples/fly_camera/main.rs @@ -11,7 +11,7 @@ use amethyst::{ Error, }; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; struct ExampleState; diff --git a/examples/prefab/main.rs b/examples/prefab/main.rs index b2efe28222..1957bba3c5 100644 --- a/examples/prefab/main.rs +++ b/examples/prefab/main.rs @@ -24,7 +24,7 @@ use amethyst::{ Error, }; -type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec), f32>; +type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec)>; struct AssetsExample; diff --git a/examples/renderable/main.rs b/examples/renderable/main.rs index b820e91b04..086f6fa9db 100644 --- a/examples/renderable/main.rs +++ b/examples/renderable/main.rs @@ -27,7 +27,7 @@ use amethyst::{ Error, }; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; #[derive(Default)] struct Loading { diff --git a/examples/separate_sphere/main.rs b/examples/separate_sphere/main.rs deleted file mode 100644 index e14032a28e..0000000000 --- a/examples/separate_sphere/main.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Displays a shaded sphere to the user. - -use amethyst::{ - assets::{PrefabLoader, PrefabLoaderSystem, RonFormat}, - core::transform::TransformBundle, - prelude::*, - renderer::*, - utils::{application_root_dir, scene::BasicScenePrefab}, -}; - -type MyPrefabData = BasicScenePrefab; - -struct Example; - -impl SimpleState for Example { - fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { - let handle = data.world.exec(|loader: PrefabLoader<'_, MyPrefabData>| { - loader.load("prefab/sphere.ron", RonFormat, (), ()) - }); - data.world.create_entity().with(handle).build(); - } -} - -fn main() -> amethyst::Result<()> { - amethyst::start_logger(Default::default()); - - let app_root = application_root_dir()?; - - let display_config_path = app_root.join("examples/separate_sphere/resources/display.ron"); - - let resources = app_root.join("examples/assets/"); - - let game_data = GameDataBuilder::default() - .with(PrefabLoaderSystem::::default(), "", &[]) - .with_bundle(TransformBundle::new())? - .with_basic_renderer(display_config_path, DrawShadedSeparate::new(), false)?; - let mut game = Application::new(resources, Example, game_data)?; - game.run(); - Ok(()) -} diff --git a/examples/separate_sphere/resources/display.ron b/examples/separate_sphere/resources/display.ron deleted file mode 100644 index f032ccbd79..0000000000 --- a/examples/separate_sphere/resources/display.ron +++ /dev/null @@ -1,10 +0,0 @@ -( - dimensions: None, - max_dimensions: None, - min_dimensions: None, - fullscreen: false, - multisampling: 0, - title: "Sphere example", - visibility: true, - vsync: true, -) diff --git a/examples/sphere/main.rs b/examples/sphere/main.rs index a19fb09f47..6ed1f186db 100644 --- a/examples/sphere/main.rs +++ b/examples/sphere/main.rs @@ -3,20 +3,34 @@ use amethyst::{ assets::{PrefabLoader, PrefabLoaderSystem, RonFormat}, core::transform::TransformBundle, + ecs::prelude::{ReadExpect, Resources, SystemData}, prelude::*, - renderer::{DrawShaded, PosNormTex}, + renderer::{ + rendy::{ + factory::Factory, + graph::{ + render::{RenderGroupDesc, SubpassBuilder}, + GraphBuilder, + }, + hal::format::Format, + mesh::{Normal, Position, TexCoord}, + }, + types::DefaultBackend, + GraphCreator, RenderingSystem, + pass::DrawShadedDesc, + }, utils::{application_root_dir, scene::BasicScenePrefab}, + window::{ScreenDimensions, Window, WindowBundle}, }; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec)>; struct Example; impl SimpleState for Example { fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) { - // Initialise the scene with an object, a light and a camera. let handle = data.world.exec(|loader: PrefabLoader<'_, MyPrefabData>| { - loader.load("prefab/sphere.ron", RonFormat, (), ()) + loader.load("prefab/sphere.ron", RonFormat, ()) }); data.world.create_entity().with(handle).build(); } @@ -27,15 +41,84 @@ fn main() -> amethyst::Result<()> { let app_root = application_root_dir()?; - let display_config_path = app_root.join("examples/sphere/resources/display_config.ron"); - + let display_config_path = app_root.join("examples/separate_sphere/resources/display.ron"); let resources = app_root.join("examples/assets/"); - let game_data = GameDataBuilder::default() + .with_bundle(WindowBundle::from_config_path(display_config_path))? .with(PrefabLoaderSystem::::default(), "", &[]) .with_bundle(TransformBundle::new())? - .with_basic_renderer(display_config_path, DrawShaded::::new(), false)?; + .with_thread_local(RenderingSystem::::new( + ExampleGraph::default(), + )); let mut game = Application::new(resources, Example, game_data)?; game.run(); Ok(()) } + +#[derive(Default)] +struct ExampleGraph { + last_dimensions: Option, + surface_format: Option, + dirty: bool, +} + +impl GraphCreator for ExampleGraph { + fn rebuild(&mut self, res: &Resources) -> bool { + // Rebuild when dimensions change, but wait until at least two frames have the same. + let new_dimensions = res.try_fetch::(); + use std::ops::Deref; + if self.last_dimensions.as_ref() != new_dimensions.as_ref().map(|d| d.deref()) { + self.dirty = true; + self.last_dimensions = new_dimensions.map(|d| d.clone()); + return false; + } + return self.dirty; + } + + fn builder( + &mut self, + factory: &mut Factory, + res: &Resources, + ) -> GraphBuilder { + use amethyst::renderer::rendy::{ + graph::present::PresentNode, + hal::command::{ClearDepthStencil, ClearValue}, + }; + + self.dirty = false; + let window = >>::fetch(res); + let surface = factory.create_surface(window.clone()); + // cache surface format to speed things up + let surface_format = *self + .surface_format + .get_or_insert_with(|| factory.get_surface_format(&surface)); + + let mut graph_builder = GraphBuilder::new(); + let color = graph_builder.create_image( + surface.kind(), + 1, + surface_format, + Some(ClearValue::Color([0.34, 0.36, 0.52, 1.0].into())), + ); + + let depth = graph_builder.create_image( + surface.kind(), + 1, + Format::D32Float, + Some(ClearValue::DepthStencil(ClearDepthStencil(1.0, 0))), + ); + + let ui = graph_builder.add_node( + SubpassBuilder::new() + .with_group(DrawShadedDesc::default().builder()) + .with_color(color) + .with_depth_stencil(depth) + .into_pass(), + ); + + let _present = graph_builder + .add_node(PresentNode::builder(factory, surface, color).with_dependency(ui)); + + graph_builder + } +} diff --git a/examples/sphere_multisample/main.rs b/examples/sphere_multisample/main.rs index 246214e513..69c953b2bf 100644 --- a/examples/sphere_multisample/main.rs +++ b/examples/sphere_multisample/main.rs @@ -8,7 +8,7 @@ use amethyst::{ utils::{application_root_dir, scene::BasicScenePrefab}, }; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; struct Example; diff --git a/examples/spotlights/main.rs b/examples/spotlights/main.rs index b6b98ba2b1..1a750b78bb 100644 --- a/examples/spotlights/main.rs +++ b/examples/spotlights/main.rs @@ -6,7 +6,7 @@ use amethyst::{ utils::{application_root_dir, scene::BasicScenePrefab}, }; -type MyPrefabData = BasicScenePrefab, f32>; +type MyPrefabData = BasicScenePrefab>; struct Example; diff --git a/examples/ui/main.rs b/examples/ui/main.rs index 392363f2a6..65cda0f5e4 100644 --- a/examples/ui/main.rs +++ b/examples/ui/main.rs @@ -32,7 +32,7 @@ use amethyst::{ }; use log::info; -type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec), f32>; +type MyPrefabData = BasicScenePrefab<(Vec, Vec, Vec)>; #[derive(Default)] struct Example {