move plugin to app module

This commit is contained in:
Carter Anderson 2020-03-29 01:15:47 -07:00
parent e2393de97c
commit 3d261f72de
13 changed files with 14 additions and 124 deletions

View file

@ -364,7 +364,7 @@ pub fn derive_app_plugin(input: TokenStream) -> TokenStream {
TokenStream::from(quote! {
#[no_mangle]
pub extern "C" fn _create_plugin() -> *mut bevy::plugin::AppPlugin {
pub extern "C" fn _create_plugin() -> *mut bevy::app::plugin::AppPlugin {
// TODO: without this the assembly does nothing. why is that the case?
print!("");
// make sure the constructor is the correct type.

View file

@ -1,110 +0,0 @@
use bevy::prelude::*;
fn main() {
App::build().add_defaults().setup(setup).run();
}
#[derive(Uniforms, Default)]
struct MyMaterial {
pub color: Color,
#[uniform(ignore, shader_def)]
pub always_red: bool,
}
fn setup(world: &mut World, resources: &mut Resources) {
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
let mut pipelines = resources.get_mut::<AssetStorage<PipelineDescriptor>>().unwrap();
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
render_graph
.build(&mut pipelines, &mut shaders)
.add_resource_provider(UniformResourceProvider::<MyMaterial>::new(true))
.add_pipeline_to_pass(resource_name::pass::MAIN, "MyMaterial", |builder| {
builder
.with_vertex_shader(Shader::from_glsl(
ShaderStage::Vertex,
r#"
#version 450
layout(location = 0) in vec4 Vertex_Position;
layout(location = 0) out vec4 v_Position;
layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj;
};
layout(set = 1, binding = 0) uniform Object {
mat4 Model;
};
void main() {
v_Position = Model * Vertex_Position;
gl_Position = ViewProj * v_Position;
}
"#,
))
.with_fragment_shader(Shader::from_glsl(
ShaderStage::Fragment,
r#"
#version 450
layout(location = 0) in vec4 v_Position;
layout(location = 0) out vec4 o_Target;
layout(set = 1, binding = 1) uniform MyMaterial_color {
vec4 color;
};
void main() {
o_Target = color;
# ifdef MYMATERIAL_ALWAYS_RED
o_Target = vec4(0.8, 0.0, 0.0, 1.0);
# endif
}
"#,
))
.with_default_config();
});
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
let cube_handle = mesh_storage.add(Mesh::load(MeshType::Cube));
let mut pipeline_storage = resources
.get_mut::<AssetStorage<PipelineDescriptor>>()
.unwrap();
let material_handle = pipeline_storage.get_named("MyMaterial").unwrap();
world
.build()
// cube
.add_entity(MeshMaterialEntity::<MyMaterial> {
mesh: cube_handle,
renderable: Renderable {
pipelines: vec![material_handle],
..Default::default()
},
material: MyMaterial {
color: Color::rgb(0.0, 0.8, 0.0),
always_red: false,
},
translation: Translation::new(-2.0, 0.0, 0.0),
..Default::default()
})
// cube
.add_entity(MeshMaterialEntity::<MyMaterial> {
mesh: cube_handle,
renderable: Renderable {
pipelines: vec![material_handle],
..Default::default()
},
material: MyMaterial {
color: Color::rgb(0.0, 0.0, 0.0),
always_red: true,
},
translation: Translation::new(2.0, 0.0, 0.0),
..Default::default()
})
// camera
.add_entity(CameraEntity {
local_to_world: LocalToWorld(Mat4::look_at_rh(
Vec3::new(3.0, 8.0, 5.0),
Vec3::new(0.0, 0.0, 0.0),
Vec3::new(0.0, 0.0, 1.0),
)),
..Default::default()
})
.build();
}

View file

@ -1,6 +1,6 @@
use crate::{
app::{system_stage, App},
core::{plugin::{AppPlugin, load_plugin}, winit::WinitPlugin, CorePlugin},
app::{system_stage, App, plugin::{AppPlugin, load_plugin}},
core::{winit::WinitPlugin, CorePlugin},
legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World},
render::{renderer::Renderer, *},
ui,

View file

@ -1,6 +1,7 @@
mod app;
mod app_builder;
pub mod system_stage;
pub mod plugin;
pub use app::App;
pub use app_builder::AppBuilder;

View file

@ -1,5 +1,5 @@
use super::{Time, Window, plugin::AppPlugin};
use crate::{app::AppBuilder};
use super::{Time, Window};
use crate::{app::{AppBuilder, plugin::AppPlugin}};
#[derive(Default)]
pub struct CorePlugin;

View file

@ -1,7 +1,6 @@
pub mod bytes;
mod time;
pub mod window;
pub mod plugin;
mod core_plugin;
pub use bytes::*;

View file

@ -1,5 +1,5 @@
use crate::{
app::{App, AppBuilder}, core::plugin::AppPlugin,
app::{App, AppBuilder}, app::plugin::AppPlugin,
};
use super::Window;

View file

@ -2,7 +2,7 @@ use super::{
diagnostics::{frame_time_diagnostic_system, print_diagnostics_system},
Diagnostics,
};
use crate::{app::AppBuilder, core::plugin::AppPlugin};
use crate::{app::AppBuilder, app::plugin::AppPlugin};
use std::time::Duration;
pub struct DiagnosticsPlugin {

View file

@ -19,7 +19,7 @@ pub struct MeshEntity {
#[derive(EntityArchetype, Default)]
pub struct MeshMaterialEntity<T: Default + Send + Sync + 'static> {
pub mesh: Handle<Mesh>,
pub material: T,
pub material: Handle<T>,
pub renderable: Renderable,
pub local_to_world: LocalToWorld,
pub translation: Translation,

View file

@ -1,7 +1,7 @@
pub use crate::{
app::{App, AppBuilder},
app::{App, AppBuilder, plugin::AppPlugin},
asset::{Asset, AssetStorage, Handle},
core::{Time, Window, plugin::AppPlugin},
core::{Time, Window},
ecs,
ecs::{
default_archetypes::*, CommandBufferBuilderSource, EntityArchetype, WorldBuilder,
@ -10,7 +10,7 @@ pub use crate::{
render::{
mesh::{Mesh, MeshType},
pipeline::PipelineDescriptor,
render_resource::{resource_name, resource_providers::UniformResourceProvider},
render_resource::{resource_name, resource_providers::UniformResourceProvider, AssetBatchers},
render_graph::RenderGraph,
shader::{uniforms::StandardMaterial, Shader, ShaderDefSuffixProvider, ShaderStage},
texture::{Texture, TextureType},

View file

@ -16,7 +16,7 @@ use super::{
use crate::{
app::AppBuilder,
asset::AssetStorage,
core::plugin::AppPlugin,
app::plugin::AppPlugin,
prelude::{
LocalToWorld, Mesh, PipelineDescriptor, Shader, StandardMaterial, Texture,
UniformResourceProvider,

View file

@ -7,7 +7,7 @@ pub use wgpu_render_pass::*;
pub use wgpu_renderer::*;
pub use wgpu_resources::*;
use crate::{app::AppBuilder, core::plugin::AppPlugin};
use crate::{app::AppBuilder, app::plugin::AppPlugin};
pub struct WgpuRendererPlugin;