Skip to content

Commit

Permalink
Merge branch 'rendy' of github.com:amethyst/amethyst into rendy
Browse files Browse the repository at this point in the history
  • Loading branch information
AnneKitsune committed May 17, 2019
2 parents 832235b + 08eb53c commit 16a102f
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 68 deletions.
2 changes: 1 addition & 1 deletion examples/animation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use amethyst_rendy::{
use serde::{Deserialize, Serialize};

type MyPrefabData = (
Option<BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<Tangent>, Vec<TexCoord>), f32>>,
Option<BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<Tangent>, Vec<TexCoord>)>>,
Option<AnimationSetPrefab<AnimationId, Transform>>,
);

Expand Down
2 changes: 1 addition & 1 deletion examples/arc_ball_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use amethyst::{
};
use std::hash::Hash;

type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

struct ExampleState;

Expand Down
2 changes: 1 addition & 1 deletion examples/custom_game_data/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use amethyst::{
mod example_system;
mod game_data;

type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

pub struct DemoState {
light_angle: f32,
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use amethyst::{

use serde::Deserialize;

type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>), f32>;
type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>)>;

#[derive(Clone, Deserialize)]
enum CustomUi {
Expand Down
2 changes: 1 addition & 1 deletion examples/fly_camera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use amethyst::{
Error,
};

type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

struct ExampleState;

Expand Down
2 changes: 1 addition & 1 deletion examples/prefab/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use amethyst::{
Error,
};

type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>), f32>;
type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>)>;

struct AssetsExample;

Expand Down
2 changes: 1 addition & 1 deletion examples/renderable/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use amethyst::{
Error,
};

type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

#[derive(Default)]
struct Loading {
Expand Down
40 changes: 0 additions & 40 deletions examples/separate_sphere/main.rs

This file was deleted.

10 changes: 0 additions & 10 deletions examples/separate_sphere/resources/display.ron

This file was deleted.

99 changes: 91 additions & 8 deletions examples/sphere/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>)>;

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();
}
Expand All @@ -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::<MyPrefabData>::default(), "", &[])
.with_bundle(TransformBundle::new())?
.with_basic_renderer(display_config_path, DrawShaded::<PosNormTex>::new(), false)?;
.with_thread_local(RenderingSystem::<DefaultBackend, _>::new(
ExampleGraph::default(),
));
let mut game = Application::new(resources, Example, game_data)?;
game.run();
Ok(())
}

#[derive(Default)]
struct ExampleGraph {
last_dimensions: Option<ScreenDimensions>,
surface_format: Option<Format>,
dirty: bool,
}

impl GraphCreator<DefaultBackend> 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::<ScreenDimensions>();
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<DefaultBackend>,
res: &Resources,
) -> GraphBuilder<DefaultBackend, Resources> {
use amethyst::renderer::rendy::{
graph::present::PresentNode,
hal::command::{ClearDepthStencil, ClearValue},
};

self.dirty = false;
let window = <ReadExpect<'_, std::sync::Arc<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
}
}
2 changes: 1 addition & 1 deletion examples/sphere_multisample/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use amethyst::{
utils::{application_root_dir, scene::BasicScenePrefab},
};

type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTex>>;

struct Example;

Expand Down
2 changes: 1 addition & 1 deletion examples/spotlights/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use amethyst::{
utils::{application_root_dir, scene::BasicScenePrefab},
};

type MyPrefabData = BasicScenePrefab<Vec<PosNormTangTex>, f32>;
type MyPrefabData = BasicScenePrefab<Vec<PosNormTangTex>>;

struct Example;

Expand Down
2 changes: 1 addition & 1 deletion examples/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use amethyst::{
};
use log::info;

type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>), f32>;
type MyPrefabData = BasicScenePrefab<(Vec<Position>, Vec<Normal>, Vec<TexCoord>)>;

#[derive(Default)]
struct Example {
Expand Down

0 comments on commit 16a102f

Please sign in to comment.