mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
Crate-ify (almost) everything
This commit is contained in:
parent
0202dcb009
commit
686e1422db
124 changed files with 1023 additions and 857 deletions
33
Cargo.toml
33
Cargo.toml
|
@ -5,42 +5,37 @@ authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
|||
edition = "2018"
|
||||
|
||||
[features]
|
||||
default = ["wgpu", "winit"]
|
||||
default = ["bevy_wgpu", "bevy_winit"]
|
||||
|
||||
[dependencies]
|
||||
# bevy
|
||||
bevy_app = { path = "bevy_app" }
|
||||
bevy_asset = { path = "bevy_asset" }
|
||||
bevy_core = { path = "bevy_core" }
|
||||
bevy_derive = { path = "bevy_derive" }
|
||||
bevy_input = { path = "bevy_input" }
|
||||
bevy_render = { path = "bevy_render" }
|
||||
bevy_transform = { path = "bevy_transform" }
|
||||
|
||||
# rendering
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "d08f83762426c2c42eda74c7ca9c43d8d950fc0a", optional = true }
|
||||
winit = { version = "0.22.0", optional = true }
|
||||
spirv-reflect = "0.2.3"
|
||||
shaderc = "0.6"
|
||||
png = "0.16.0"
|
||||
gltf = "0.14.0"
|
||||
|
||||
# ecs
|
||||
bevy_window = { path = "bevy_window" }
|
||||
bevy_wgpu = { path = "bevy_wgpu", optional = true }
|
||||
bevy_winit = { path = "bevy_winit", optional = true }
|
||||
legion = { path = "bevy_legion", features = ["serialize"] }
|
||||
|
||||
# logging
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
|
||||
# misc
|
||||
bitflags = "1.0"
|
||||
glam = "0.8.6"
|
||||
zerocopy = "0.3"
|
||||
env_logger = "0.7"
|
||||
rand = "0.7.2"
|
||||
serde = { version = "1", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||
erased-serde = "0.3"
|
||||
type-uuid = "0.1"
|
||||
libloading = "0.5.2"
|
||||
# TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788
|
||||
once_cell = "1.3.1"
|
||||
futures = "0.3"
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.7.2"
|
||||
serde_json = "1.0"
|
||||
|
||||
[profile.release]
|
||||
debug = true
|
||||
|
|
13
bevy_app/Cargo.toml
Normal file
13
bevy_app/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "bevy_app"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
legion = { path = "../bevy_legion", features = ["serialize"] }
|
||||
libloading = "0.5.2"
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
env_logger = "0.7"
|
44
bevy_app/src/app.rs
Normal file
44
bevy_app/src/app.rs
Normal file
|
@ -0,0 +1,44 @@
|
|||
use super::AppBuilder;
|
||||
use legion::prelude::*;
|
||||
|
||||
pub struct App {
|
||||
pub universe: Universe,
|
||||
pub world: World,
|
||||
pub resources: Resources,
|
||||
pub runner: Option<Box<dyn Fn(App)>>,
|
||||
pub schedule: Option<Schedule>,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
let universe = Universe::new();
|
||||
let world = universe.create_world();
|
||||
let resources = Resources::default();
|
||||
App {
|
||||
universe,
|
||||
world,
|
||||
resources,
|
||||
runner: None,
|
||||
schedule: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn build() -> AppBuilder {
|
||||
env_logger::init();
|
||||
AppBuilder::new()
|
||||
}
|
||||
|
||||
pub fn update(&mut self) {
|
||||
if let Some(ref mut schedule) = self.schedule {
|
||||
schedule.execute(&mut self.world, &mut self.resources);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(mut self) {
|
||||
if let Some(run) = self.runner.take() {
|
||||
run(self)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +1,15 @@
|
|||
use crate::{
|
||||
app::{
|
||||
plugin::{load_plugin, AppPlugin},
|
||||
system_stage, App,
|
||||
},
|
||||
core::{CorePlugin, Events},
|
||||
legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World},
|
||||
render::RenderPlugin,
|
||||
ui::UiPlugin,
|
||||
window::WindowPlugin, input::InputPlugin,
|
||||
plugin::{load_plugin, AppPlugin},
|
||||
system_stage, App, Events,
|
||||
};
|
||||
|
||||
use legion::prelude::{Resources, Runnable, Schedulable, Schedule, Universe, World};
|
||||
use std::collections::HashMap;
|
||||
|
||||
static APP_MISSING_MESSAGE: &str = "This AppBuilder no longer has an App. Check to see if you already called run(). A call to app_builder.run() consumes the AppBuilder's App.";
|
||||
|
||||
pub struct AppBuilder {
|
||||
pub world: World,
|
||||
pub resources: Resources,
|
||||
pub universe: Universe,
|
||||
pub run: Option<Box<dyn Fn(App)>>,
|
||||
pub schedule: Option<Schedule>,
|
||||
app: Option<App>,
|
||||
pub setup_systems: Vec<Box<dyn Schedulable>>,
|
||||
// TODO: these separate lists will produce incorrect ordering
|
||||
pub system_stages: HashMap<String, Vec<Box<dyn Schedulable>>>,
|
||||
|
@ -28,15 +20,8 @@ pub struct AppBuilder {
|
|||
|
||||
impl AppBuilder {
|
||||
pub fn new() -> Self {
|
||||
let universe = Universe::new();
|
||||
let world = universe.create_world();
|
||||
let resources = Resources::default();
|
||||
AppBuilder {
|
||||
universe,
|
||||
world,
|
||||
resources,
|
||||
run: None,
|
||||
schedule: None,
|
||||
app: Some(App::default()),
|
||||
setup_systems: Vec::new(),
|
||||
system_stages: HashMap::new(),
|
||||
runnable_stages: HashMap::new(),
|
||||
|
@ -45,14 +30,47 @@ impl AppBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn build_schedule(mut self) -> Self {
|
||||
pub fn app(&self) -> &App {
|
||||
self.app.as_ref().expect(APP_MISSING_MESSAGE)
|
||||
}
|
||||
|
||||
pub fn app_mut(&mut self) -> &mut App {
|
||||
self.app.as_mut().expect(APP_MISSING_MESSAGE)
|
||||
}
|
||||
|
||||
pub fn world(&self) -> &World {
|
||||
&self.app().world
|
||||
}
|
||||
|
||||
pub fn world_mut(&mut self) -> &mut World {
|
||||
&mut self.app_mut().world
|
||||
}
|
||||
|
||||
pub fn universe(&self) -> &Universe {
|
||||
&self.app().universe
|
||||
}
|
||||
|
||||
pub fn universe_mut(&mut self) -> &mut Universe {
|
||||
&mut self.app_mut().universe
|
||||
}
|
||||
|
||||
pub fn resources(&self) -> &Resources {
|
||||
&self.app().resources
|
||||
}
|
||||
|
||||
pub fn resources_mut(&mut self) -> &mut Resources {
|
||||
&mut self.app_mut().resources
|
||||
}
|
||||
|
||||
pub fn build_schedule(&mut self) -> &mut Self {
|
||||
let mut setup_schedule_builder = Schedule::builder();
|
||||
for setup_system in self.setup_systems.drain(..) {
|
||||
setup_schedule_builder = setup_schedule_builder.add_system(setup_system);
|
||||
}
|
||||
|
||||
let mut setup_schedule = setup_schedule_builder.build();
|
||||
setup_schedule.execute(&mut self.world, &mut self.resources);
|
||||
let app = self.app_mut();
|
||||
setup_schedule.execute(&mut app.world, &mut app.resources);
|
||||
|
||||
let mut schedule_builder = Schedule::builder();
|
||||
for stage_name in self.stage_order.iter() {
|
||||
|
@ -83,55 +101,50 @@ impl AppBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
self.schedule = Some(schedule_builder.build());
|
||||
let app = self.app_mut();
|
||||
app.schedule = Some(schedule_builder.build());
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(mut self) -> App {
|
||||
self = self.build_schedule();
|
||||
|
||||
App::new(
|
||||
self.universe,
|
||||
self.world,
|
||||
self.resources,
|
||||
self.schedule.take().unwrap(),
|
||||
self.run.take(),
|
||||
)
|
||||
pub fn run(&mut self) {
|
||||
self.build_schedule();
|
||||
self.app.take().unwrap().run();
|
||||
}
|
||||
|
||||
pub fn run(self) {
|
||||
self.build().run();
|
||||
}
|
||||
|
||||
pub fn with_world(mut self, world: World) -> Self {
|
||||
self.world = world;
|
||||
pub fn set_world(&mut self, world: World) -> &mut Self {
|
||||
self.app_mut().world = world;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn setup(mut self, setup: impl Fn(&mut World, &mut Resources)) -> Self {
|
||||
setup(&mut self.world, &mut self.resources);
|
||||
pub fn setup(&mut self, setup: impl Fn(&mut World, &mut Resources)) -> &mut Self {
|
||||
let app = self.app_mut();
|
||||
setup(&mut app.world, &mut app.resources);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_system(self, system: Box<dyn Schedulable>) -> Self {
|
||||
pub fn add_system(&mut self, system: Box<dyn Schedulable>) -> &mut Self {
|
||||
self.add_system_to_stage(system_stage::UPDATE, system)
|
||||
}
|
||||
|
||||
pub fn add_setup_system(mut self, system: Box<dyn Schedulable>) -> Self {
|
||||
pub fn add_setup_system(&mut self, system: Box<dyn Schedulable>) -> &mut Self {
|
||||
self.setup_systems.push(system);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build_system<F>(mut self, build: F) -> Self
|
||||
pub fn build_system<F>(&mut self, build: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&mut Resources) -> Box<dyn Schedulable>,
|
||||
{
|
||||
let system = build(&mut self.resources);
|
||||
let system = build(self.resources_mut());
|
||||
self.add_system(system)
|
||||
}
|
||||
|
||||
pub fn add_system_to_stage(mut self, stage_name: &str, system: Box<dyn Schedulable>) -> Self {
|
||||
pub fn add_system_to_stage(
|
||||
&mut self,
|
||||
stage_name: &str,
|
||||
system: Box<dyn Schedulable>,
|
||||
) -> &mut Self {
|
||||
if let None = self.system_stages.get(stage_name) {
|
||||
self.system_stages
|
||||
.insert(stage_name.to_string(), Vec::new());
|
||||
|
@ -144,7 +157,11 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_runnable_to_stage(mut self, stage_name: &str, system: Box<dyn Runnable>) -> Self {
|
||||
pub fn add_runnable_to_stage(
|
||||
&mut self,
|
||||
stage_name: &str,
|
||||
system: Box<dyn Runnable>,
|
||||
) -> &mut Self {
|
||||
if let None = self.runnable_stages.get(stage_name) {
|
||||
self.runnable_stages
|
||||
.insert(stage_name.to_string(), Vec::new());
|
||||
|
@ -158,10 +175,10 @@ impl AppBuilder {
|
|||
}
|
||||
|
||||
pub fn add_thread_local_to_stage(
|
||||
mut self,
|
||||
&mut self,
|
||||
stage_name: &str,
|
||||
f: impl FnMut(&mut World, &mut Resources) + 'static,
|
||||
) -> Self {
|
||||
) -> &mut Self {
|
||||
if let None = self.thread_local_stages.get(stage_name) {
|
||||
self.thread_local_stages
|
||||
.insert(stage_name.to_string(), Vec::new());
|
||||
|
@ -174,7 +191,7 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_event<T>(self) -> Self
|
||||
pub fn add_event<T>(&mut self) -> &mut Self
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
|
@ -185,56 +202,32 @@ impl AppBuilder {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn add_resource<T>(mut self, resource: T) -> Self
|
||||
pub fn add_resource<T>(&mut self, resource: T) -> &mut Self
|
||||
where
|
||||
T: Send + Sync + 'static,
|
||||
{
|
||||
self.resources.insert(resource);
|
||||
self.resources_mut().insert(resource);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_runner(mut self, run_fn: impl Fn(App) + 'static) -> Self {
|
||||
self.run = Some(Box::new(run_fn));
|
||||
pub fn set_runner(&mut self, run_fn: impl Fn(App) + 'static) -> &mut Self {
|
||||
self.app_mut().runner = Some(Box::new(run_fn));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_default_plugins(mut self) -> Self {
|
||||
self = self
|
||||
.add_plugin(CorePlugin::default())
|
||||
.add_plugin(InputPlugin::default())
|
||||
.add_plugin(WindowPlugin::default())
|
||||
.add_plugin(RenderPlugin::default())
|
||||
.add_plugin(UiPlugin::default());
|
||||
|
||||
#[cfg(feature = "winit")]
|
||||
{
|
||||
self = self.add_plugin(crate::window::winit::WinitPlugin::default())
|
||||
}
|
||||
#[cfg(not(feature = "winit"))]
|
||||
{
|
||||
self = self.add_plugin(crate::app::schedule_run::ScheduleRunner::default());
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgpu")]
|
||||
{
|
||||
self = self.add_plugin(
|
||||
crate::render::renderer::renderers::wgpu_renderer::WgpuRendererPlugin::default(),
|
||||
);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn load_plugin(self, path: &str) -> Self {
|
||||
pub fn load_plugin(&mut self, path: &str) -> &mut Self {
|
||||
let (_lib, plugin) = load_plugin(path);
|
||||
log::debug!("loaded plugin: {}", plugin.name());
|
||||
plugin.build(self)
|
||||
plugin.build(self);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_plugin<T>(self, plugin: T) -> Self
|
||||
pub fn add_plugin<T>(&mut self, plugin: T) -> &mut Self
|
||||
where
|
||||
T: AppPlugin,
|
||||
{
|
||||
log::debug!("added plugin: {}", plugin.name());
|
||||
plugin.build(self)
|
||||
plugin.build(self);
|
||||
self
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
use crate::prelude::Resources;
|
||||
use legion::prelude::{Schedulable, SystemBuilder};
|
||||
use legion::prelude::{Schedulable, SystemBuilder, Resources};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
struct EventInstance<T> {
|
11
bevy_app/src/lib.rs
Normal file
11
bevy_app/src/lib.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
mod app;
|
||||
mod app_builder;
|
||||
mod event;
|
||||
mod plugin;
|
||||
pub mod schedule_runner;
|
||||
pub mod system_stage;
|
||||
|
||||
pub use app::*;
|
||||
pub use app_builder::*;
|
||||
pub use plugin::*;
|
||||
pub use event::*;
|
|
@ -1,9 +1,9 @@
|
|||
use crate::app::AppBuilder;
|
||||
use super::AppBuilder;
|
||||
use libloading::{Library, Symbol};
|
||||
use std::any::Any;
|
||||
|
||||
pub trait AppPlugin: Any + Send + Sync {
|
||||
fn build(&self, app: AppBuilder) -> AppBuilder;
|
||||
fn build(&self, app: &mut AppBuilder);
|
||||
fn name(&self) -> &str {
|
||||
type_name_of_val(self)
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
use crate::{
|
||||
app::{App, AppBuilder},
|
||||
prelude::AppPlugin,
|
||||
};
|
||||
use super::{App, AppBuilder, AppPlugin};
|
||||
use std::{thread, time::Duration};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -22,18 +19,22 @@ pub struct ScheduleRunnerPlugin {
|
|||
}
|
||||
|
||||
impl AppPlugin for ScheduleRunnerPlugin {
|
||||
fn build(&self, app: AppBuilder) -> AppBuilder {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
let run_mode = self.run_mode;
|
||||
app.set_runner(move |mut app: App| match run_mode {
|
||||
RunMode::Once => {
|
||||
app.schedule.execute(&mut app.world, &mut app.resources);
|
||||
if let Some(ref mut schedule) = app.schedule {
|
||||
schedule.execute(&mut app.world, &mut app.resources);
|
||||
}
|
||||
}
|
||||
RunMode::Loop { wait } => loop {
|
||||
app.schedule.execute(&mut app.world, &mut app.resources);
|
||||
if let Some(ref mut schedule) = app.schedule {
|
||||
schedule.execute(&mut app.world, &mut app.resources);
|
||||
}
|
||||
if let Some(wait) = wait {
|
||||
thread::sleep(wait);
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// TODO: move me
|
||||
|
||||
pub const FIRST: &str = "first";
|
||||
pub const EVENT_UPDATE: &str = "event_update";
|
||||
pub const UPDATE: &str = "update";
|
11
bevy_asset/Cargo.toml
Normal file
11
bevy_asset/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "bevy_asset"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy_core = { path = "../bevy_core" }
|
||||
gltf = "0.14.0"
|
|
@ -1,6 +1,7 @@
|
|||
mod gltf;
|
||||
|
||||
pub use self::gltf::load_gltf;
|
||||
use bevy_core::bytes::GetBytes;
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
hash::{Hash, Hasher},
|
||||
|
@ -8,6 +9,7 @@ use std::{
|
|||
|
||||
use std::{any::TypeId, collections::HashMap, marker::PhantomData};
|
||||
|
||||
// TODO: move these types to their own files
|
||||
pub type HandleId = usize;
|
||||
|
||||
pub struct Handle<T> {
|
||||
|
@ -157,3 +159,13 @@ impl<T> AssetStorage<T> {
|
|||
self.assets.get_mut(&handle.id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> GetBytes for Handle<T> {
|
||||
fn get_bytes(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||
None
|
||||
}
|
||||
}
|
14
bevy_core/Cargo.toml
Normal file
14
bevy_core/Cargo.toml
Normal file
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "bevy_core"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy_app = { path = "../bevy_app" }
|
||||
bevy_transform = { path = "../bevy_transform" }
|
||||
legion = { path = "../bevy_legion" }
|
||||
glam = "0.8.6"
|
||||
zerocopy = "0.3"
|
|
@ -1,8 +1,4 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
math::{Mat4, Vec4},
|
||||
render::texture::Texture,
|
||||
};
|
||||
use glam::{Mat4, Vec4};
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub trait GetBytes {
|
||||
|
@ -71,12 +67,16 @@ impl GetBytes for Mat4 {
|
|||
}
|
||||
}
|
||||
|
||||
impl GetBytes for Handle<Texture> {
|
||||
impl<T> GetBytes for Option<T>
|
||||
where
|
||||
T: GetBytes,
|
||||
{
|
||||
fn get_bytes(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||
None
|
||||
self.as_ref()
|
||||
.and_then(|get_bytes| get_bytes.get_bytes_ref())
|
||||
}
|
||||
}
|
21
bevy_core/src/lib.rs
Normal file
21
bevy_core/src/lib.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
pub mod bytes;
|
||||
pub mod time;
|
||||
|
||||
use bevy_app::{system_stage, AppBuilder, AppPlugin};
|
||||
use bevy_transform::transform_system_bundle;
|
||||
use time::{start_timer_system, stop_timer_system};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CorePlugin;
|
||||
|
||||
impl AppPlugin for CorePlugin {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
for transform_system in transform_system_bundle::build(app.world_mut()).drain(..) {
|
||||
app.add_system(transform_system);
|
||||
}
|
||||
|
||||
app.add_resource(time::Time::new())
|
||||
.add_system_to_stage(system_stage::FIRST, start_timer_system())
|
||||
.add_system_to_stage(system_stage::LAST, stop_timer_system());
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
use legion::prelude::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub struct Time {
|
||||
|
@ -28,3 +29,20 @@ impl Time {
|
|||
self.delta_seconds = self.delta_seconds_f64 as f32;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_timer_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("start_timer")
|
||||
.write_resource::<Time>()
|
||||
.build(|_, _, time, _| {
|
||||
time.start();
|
||||
})
|
||||
}
|
||||
|
||||
pub fn stop_timer_system() -> Box<dyn Schedulable> {
|
||||
SystemBuilder::new("stop_timer")
|
||||
.write_resource::<Time>()
|
||||
.build(|_, _, time, _| {
|
||||
time.stop();
|
||||
})
|
||||
}
|
||||
|
|
@ -3,9 +3,8 @@ extern crate proc_macro;
|
|||
use darling::FromMeta;
|
||||
use inflector::Inflector;
|
||||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Ident, Type};
|
||||
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Ident, Type, Path};
|
||||
|
||||
#[derive(FromMeta, Debug, Default)]
|
||||
struct EntityArchetypeAttributeArgs {
|
||||
|
@ -84,14 +83,20 @@ struct UniformAttributeArgs {
|
|||
#[darling(default)]
|
||||
pub vertex: Option<bool>,
|
||||
#[darling(default)]
|
||||
pub bevy_path: Option<String>,
|
||||
pub bevy_render_path: Option<String>,
|
||||
#[darling(default)]
|
||||
pub bevy_asset_path: Option<String>,
|
||||
#[darling(default)]
|
||||
pub bevy_core_path: Option<String>,
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Uniforms, attributes(uniform))]
|
||||
pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
||||
static UNIFORM_ATTRIBUTE_NAME: &'static str = "uniform";
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
let mut bevy_path_name = "bevy".to_string();
|
||||
let mut bevy_render_path_name = "bevy::render".to_string();
|
||||
let mut bevy_core_path_name = "bevy::core".to_string();
|
||||
let mut bevy_asset_path_name = "bevy::asset".to_string();
|
||||
let struct_attribute_args = ast
|
||||
.attrs
|
||||
.iter()
|
||||
|
@ -102,12 +107,22 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
});
|
||||
|
||||
if let Some(struct_attribute_args) = struct_attribute_args {
|
||||
if let Some(attribute_bevy_path) = struct_attribute_args.bevy_path {
|
||||
bevy_path_name = attribute_bevy_path.to_string();
|
||||
if let Some(value) = struct_attribute_args.bevy_render_path {
|
||||
bevy_render_path_name = value.to_string();
|
||||
}
|
||||
if let Some(value) = struct_attribute_args.bevy_core_path {
|
||||
bevy_core_path_name = value.to_string();
|
||||
}
|
||||
if let Some(value) = struct_attribute_args.bevy_asset_path {
|
||||
bevy_asset_path_name = value.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
let bevy_path = Ident::new(&bevy_path_name, Span::call_site());
|
||||
// let bevy_render_path = Ident::new(&bevy_render_path_name, Span::call_site());
|
||||
// let bevy_render_path = Path::parse(&bevy_render_path_name).unwrap();
|
||||
let bevy_render_path: Path = syn::parse(bevy_render_path_name.parse::<TokenStream>().unwrap()).unwrap();
|
||||
let bevy_core_path: Path = syn::parse(bevy_core_path_name.parse::<TokenStream>().unwrap()).unwrap();
|
||||
let bevy_asset_path: Path = syn::parse(bevy_asset_path_name.parse::<TokenStream>().unwrap()).unwrap();
|
||||
|
||||
let fields = match &ast.data {
|
||||
Data::Struct(DataStruct {
|
||||
|
@ -253,7 +268,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
},
|
||||
None => false,
|
||||
};
|
||||
quote!(#bevy_path::render::shader::FieldInfo {
|
||||
quote!(#bevy_render_path::shader::FieldInfo {
|
||||
name: #field_name,
|
||||
uniform_name: #uniform,
|
||||
texture_name: #texture,
|
||||
|
@ -263,13 +278,13 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
});
|
||||
|
||||
TokenStream::from(quote! {
|
||||
static #field_infos_ident: &[#bevy_path::render::shader::FieldInfo] = &[
|
||||
static #field_infos_ident: &[#bevy_render_path::shader::FieldInfo] = &[
|
||||
#(#field_infos,)*
|
||||
];
|
||||
|
||||
static #vertex_buffer_descriptor_ident: #bevy_path::once_cell::sync::Lazy<#bevy_path::render::pipeline::VertexBufferDescriptor> =
|
||||
#bevy_path::once_cell::sync::Lazy::new(|| {
|
||||
use #bevy_path::render::pipeline::{VertexFormat, AsVertexFormats, VertexAttributeDescriptor};
|
||||
static #vertex_buffer_descriptor_ident: #bevy_render_path::once_cell::sync::Lazy<#bevy_render_path::pipeline::VertexBufferDescriptor> =
|
||||
#bevy_render_path::once_cell::sync::Lazy::new(|| {
|
||||
use #bevy_render_path::pipeline::{VertexFormat, AsVertexFormats, VertexAttributeDescriptor};
|
||||
|
||||
let mut vertex_formats: Vec<(&str,&[VertexFormat])> = vec![
|
||||
#((#vertex_buffer_field_names_pascal, <#vertex_buffer_field_types>::as_vertex_formats()),)*
|
||||
|
@ -297,21 +312,21 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
}).collect::<Vec<VertexAttributeDescriptor>>()
|
||||
}).flatten().collect::<Vec<VertexAttributeDescriptor>>();
|
||||
|
||||
#bevy_path::render::pipeline::VertexBufferDescriptor {
|
||||
#bevy_render_path::pipeline::VertexBufferDescriptor {
|
||||
attributes: vertex_attribute_descriptors,
|
||||
name: #struct_name_string.to_string(),
|
||||
step_mode: #bevy_path::render::pipeline::InputStepMode::Instance,
|
||||
step_mode: #bevy_render_path::pipeline::InputStepMode::Instance,
|
||||
stride: offset,
|
||||
}
|
||||
});
|
||||
|
||||
impl #bevy_path::render::shader::AsUniforms for #struct_name {
|
||||
fn get_field_infos() -> &'static [#bevy_path::render::shader::FieldInfo] {
|
||||
impl #bevy_render_path::shader::AsUniforms for #struct_name {
|
||||
fn get_field_infos() -> &'static [#bevy_render_path::shader::FieldInfo] {
|
||||
#field_infos_ident
|
||||
}
|
||||
|
||||
fn get_field_bind_type(&self, name: &str) -> Option<#bevy_path::render::shader::FieldBindType> {
|
||||
use #bevy_path::render::shader::AsFieldBindType;
|
||||
fn get_field_bind_type(&self, name: &str) -> Option<#bevy_render_path::shader::FieldBindType> {
|
||||
use #bevy_render_path::shader::AsFieldBindType;
|
||||
match name {
|
||||
#(#active_uniform_field_name_strings => self.#active_uniform_field_names.get_field_bind_type(),)*
|
||||
_ => None,
|
||||
|
@ -319,7 +334,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
fn get_uniform_bytes(&self, name: &str) -> Option<Vec<u8>> {
|
||||
use #bevy_path::core::bytes::GetBytes;
|
||||
use #bevy_core_path::bytes::GetBytes;
|
||||
match name {
|
||||
#(#uniform_name_strings => Some(self.#active_uniform_field_names.get_bytes()),)*
|
||||
_ => None,
|
||||
|
@ -327,15 +342,15 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
fn get_uniform_bytes_ref(&self, name: &str) -> Option<&[u8]> {
|
||||
use #bevy_path::core::bytes::GetBytes;
|
||||
use #bevy_core_path::bytes::GetBytes;
|
||||
match name {
|
||||
#(#uniform_name_strings => self.#active_uniform_field_names.get_bytes_ref(),)*
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_uniform_texture(&self, name: &str) -> Option<#bevy_path::asset::Handle<#bevy_path::render::texture::Texture>> {
|
||||
use #bevy_path::render::shader::GetTexture;
|
||||
fn get_uniform_texture(&self, name: &str) -> Option<#bevy_asset_path::Handle<#bevy_render_path::texture::Texture>> {
|
||||
use #bevy_render_path::shader::GetTexture;
|
||||
match name {
|
||||
#(#texture_and_sampler_name_strings => self.#texture_and_sampler_name_idents.get_texture(),)*
|
||||
_ => None,
|
||||
|
@ -346,7 +361,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
// TODO: this will be very allocation heavy. find a way to either make this allocation free
|
||||
// or alternatively only run it when the shader_defs have changed
|
||||
fn get_shader_defs(&self) -> Option<Vec<String>> {
|
||||
use #bevy_path::render::shader::ShaderDefSuffixProvider;
|
||||
use #bevy_render_path::shader::ShaderDefSuffixProvider;
|
||||
let mut potential_shader_defs: Vec<(&'static str, Option<&'static str>)> = vec![
|
||||
#((#shader_def_field_names_screaming_snake, self.#shader_def_field_names.get_shader_def()),)*
|
||||
];
|
||||
|
@ -357,7 +372,7 @@ pub fn derive_uniforms(input: TokenStream) -> TokenStream {
|
|||
.collect::<Vec<String>>())
|
||||
}
|
||||
|
||||
fn get_vertex_buffer_descriptor() -> Option<&'static #bevy_path::render::pipeline::VertexBufferDescriptor> {
|
||||
fn get_vertex_buffer_descriptor() -> Option<&'static #bevy_render_path::pipeline::VertexBufferDescriptor> {
|
||||
if #vertex_buffer_descriptor_ident.attributes.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
|
|
11
bevy_input/Cargo.toml
Normal file
11
bevy_input/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "bevy_input"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
bevy_app = { path = "../bevy_app" }
|
|
@ -1,7 +1,7 @@
|
|||
pub mod keyboard;
|
||||
pub mod mouse;
|
||||
|
||||
use crate::{app::AppBuilder, prelude::AppPlugin};
|
||||
use bevy_app::{AppBuilder, AppPlugin};
|
||||
use keyboard::KeyboardInput;
|
||||
use mouse::{MouseButtonInput, MouseMotion};
|
||||
|
||||
|
@ -9,9 +9,9 @@ use mouse::{MouseButtonInput, MouseMotion};
|
|||
pub struct InputPlugin;
|
||||
|
||||
impl AppPlugin for InputPlugin {
|
||||
fn build(&self, app: AppBuilder) -> AppBuilder {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
app.add_event::<KeyboardInput>()
|
||||
.add_event::<MouseButtonInput>()
|
||||
.add_event::<MouseMotion>()
|
||||
.add_event::<MouseMotion>();
|
||||
}
|
||||
}
|
32
bevy_render/Cargo.toml
Normal file
32
bevy_render/Cargo.toml
Normal file
|
@ -0,0 +1,32 @@
|
|||
[package]
|
||||
name = "bevy_render"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
# bevy
|
||||
bevy_app = { path = "../bevy_app" }
|
||||
bevy_core = { path = "../bevy_core" }
|
||||
bevy_transform = { path = "../bevy_transform" }
|
||||
bevy_asset = { path = "../bevy_asset" }
|
||||
bevy_derive = { path = "../bevy_derive" }
|
||||
bevy_window = { path = "../bevy_window" }
|
||||
legion = { path = "../bevy_legion" }
|
||||
|
||||
# rendering
|
||||
spirv-reflect = "0.2.3"
|
||||
shaderc = "0.6"
|
||||
png = "0.16.0"
|
||||
|
||||
# misc
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
uuid = { version = "0.8", features = ["v4", "serde"] }
|
||||
glam = "0.8.6"
|
||||
zerocopy = "0.3"
|
||||
bitflags = "1.0"
|
||||
# TODO: replace once_cell with std equivalent if/when this lands: https://github.com/rust-lang/rfcs/pull/2788
|
||||
once_cell = "1.3.1"
|
|
@ -1,4 +1,4 @@
|
|||
use crate::math::Mat4;
|
||||
use glam::Mat4;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ActiveCamera;
|
|
@ -1,5 +1,8 @@
|
|||
use super::texture::Texture;
|
||||
use crate::{asset::Handle, core::GetBytes, math::Vec4, render::shader::ShaderDefSuffixProvider};
|
||||
use crate::shader::ShaderDefSuffixProvider;
|
||||
use bevy_asset::Handle;
|
||||
use bevy_core::bytes::GetBytes;
|
||||
use glam::Vec4;
|
||||
use std::ops::Add;
|
||||
use zerocopy::AsBytes;
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
render::{
|
||||
pipeline::PipelineDescriptor,
|
||||
renderer::{RenderPass, Renderer},
|
||||
},
|
||||
pipeline::PipelineDescriptor,
|
||||
renderer::{RenderPass, Renderer},
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use legion::prelude::{Resources, World};
|
||||
|
||||
// A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
|
|
@ -1,14 +1,12 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
legion::prelude::*,
|
||||
prelude::Renderable,
|
||||
render::{
|
||||
draw_target::DrawTarget,
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{resource_name, AssetBatchers, RenderResourceAssignments},
|
||||
renderer::{RenderPass, Renderer},
|
||||
},
|
||||
draw_target::DrawTarget,
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{resource_name, AssetBatchers, RenderResourceAssignments},
|
||||
renderer::{RenderPass, Renderer},
|
||||
Renderable,
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use legion::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AssignedBatchesDrawTarget;
|
|
@ -1,16 +1,15 @@
|
|||
use bevy_asset::Handle;
|
||||
use legion::prelude::*;
|
||||
|
||||
use crate::{
|
||||
asset::Handle,
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
draw_target::DrawTarget,
|
||||
mesh::Mesh,
|
||||
pipeline::{PipelineDescriptor, ShaderPipelineAssignments},
|
||||
render_resource::{
|
||||
resource_name, EntityRenderResourceAssignments, RenderResourceAssignments, ResourceInfo,
|
||||
},
|
||||
renderer::{RenderPass, Renderer},
|
||||
Renderable,
|
||||
draw_target::DrawTarget,
|
||||
mesh::Mesh,
|
||||
pipeline::{PipelineDescriptor, ShaderPipelineAssignments},
|
||||
render_resource::{
|
||||
resource_name, EntityRenderResourceAssignments, RenderResourceAssignments, ResourceInfo,
|
||||
},
|
||||
renderer::{RenderPass, Renderer},
|
||||
Renderable,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
|
@ -1,15 +1,13 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
draw_target::DrawTarget,
|
||||
mesh::Mesh,
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{resource_name, ResourceInfo},
|
||||
renderer::RenderPass,
|
||||
Renderable,
|
||||
},
|
||||
draw_target::DrawTarget,
|
||||
mesh::Mesh,
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{resource_name, ResourceInfo},
|
||||
renderer::RenderPass,
|
||||
Renderable,
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use legion::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MeshesDrawTarget;
|
|
@ -1,19 +1,15 @@
|
|||
use crate::{
|
||||
asset::{Asset, Handle},
|
||||
legion::prelude::*,
|
||||
math,
|
||||
prelude::MeshType,
|
||||
render::{
|
||||
draw_target::DrawTarget,
|
||||
mesh::Mesh,
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceInfo,
|
||||
},
|
||||
renderer::{RenderPass, Renderer},
|
||||
draw_target::DrawTarget,
|
||||
mesh::{Mesh, MeshType},
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceInfo,
|
||||
},
|
||||
renderer::{RenderPass, Renderer},
|
||||
};
|
||||
use bevy_asset::{Asset, Handle};
|
||||
use legion::prelude::*;
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
|
@ -81,7 +77,7 @@ impl DrawTarget for UiDrawTarget {
|
|||
}
|
||||
|
||||
let quad = Mesh::load(MeshType::Quad {
|
||||
size: math::vec2(1.0, 1.0),
|
||||
size: glam::vec2(1.0, 1.0),
|
||||
});
|
||||
self.mesh_vertex_buffer = Some(renderer.create_buffer_with_data(
|
||||
BufferInfo {
|
|
@ -1,3 +1,4 @@
|
|||
#![feature(specialization)]
|
||||
mod camera;
|
||||
pub mod mesh;
|
||||
pub mod render_graph;
|
||||
|
@ -22,6 +23,8 @@ mod renderable;
|
|||
pub mod renderer;
|
||||
pub mod texture;
|
||||
|
||||
pub use once_cell;
|
||||
|
||||
use self::{
|
||||
draw_target::draw_targets::{
|
||||
AssignedBatchesDrawTarget, AssignedMeshesDrawTarget, MeshesDrawTarget, UiDrawTarget,
|
||||
|
@ -29,32 +32,39 @@ use self::{
|
|||
pass::passes::ForwardPassBuilder,
|
||||
pipeline::{
|
||||
pipelines::ForwardPipelineBuilder, PipelineCompiler, ShaderPipelineAssignments,
|
||||
VertexBufferDescriptors,
|
||||
VertexBufferDescriptors, PipelineDescriptor
|
||||
},
|
||||
shader::{Shader, uniforms::StandardMaterial},
|
||||
texture::Texture,
|
||||
mesh::Mesh,
|
||||
render_graph::RenderGraph,
|
||||
render_resource::{
|
||||
build_entity_render_resource_assignments_system,
|
||||
resource_providers::{
|
||||
Camera2dResourceProvider, CameraResourceProvider, LightResourceProvider,
|
||||
MeshResourceProvider, UiResourceProvider,
|
||||
MeshResourceProvider, UniformResourceProvider,
|
||||
},
|
||||
AssetBatchers, EntityRenderResourceAssignments, RenderResourceAssignments,
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{prelude::*, window::WindowResized};
|
||||
use bevy_app::{AppBuilder, AppPlugin, GetEventReader};
|
||||
use bevy_transform::prelude::LocalToWorld;
|
||||
use bevy_asset::AssetStorage;
|
||||
use bevy_window::WindowResized;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RenderPlugin;
|
||||
|
||||
impl RenderPlugin {
|
||||
pub fn setup_render_graph_defaults(app: &mut AppBuilder) {
|
||||
let resources = app.resources();
|
||||
let mut pipelines = app
|
||||
.resources
|
||||
.resources()
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
let mut shaders = app.resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut render_graph = app.resources.get_mut::<RenderGraph>().unwrap();
|
||||
let mut shaders = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let mut render_graph = resources.get_mut::<RenderGraph>().unwrap();
|
||||
render_graph
|
||||
.build(&mut pipelines, &mut shaders)
|
||||
.add_draw_target(MeshesDrawTarget::default())
|
||||
|
@ -62,13 +72,14 @@ impl RenderPlugin {
|
|||
.add_draw_target(AssignedMeshesDrawTarget::default())
|
||||
.add_draw_target(UiDrawTarget::default())
|
||||
.add_resource_provider(CameraResourceProvider::new(
|
||||
app.resources.get_event_reader::<WindowResized>(),
|
||||
app.resources().get_event_reader::<WindowResized>(),
|
||||
))
|
||||
.add_resource_provider(Camera2dResourceProvider::new(
|
||||
app.resources.get_event_reader::<WindowResized>(),
|
||||
resources.get_event_reader::<WindowResized>(),
|
||||
))
|
||||
.add_resource_provider(LightResourceProvider::new(10))
|
||||
.add_resource_provider(UiResourceProvider::new())
|
||||
// TODO: move me to ui crate
|
||||
// .add_resource_provider(UiResourceProvider::new())
|
||||
.add_resource_provider(MeshResourceProvider::new())
|
||||
.add_resource_provider(UniformResourceProvider::<StandardMaterial>::new(true))
|
||||
.add_resource_provider(UniformResourceProvider::<LocalToWorld>::new(true))
|
||||
|
@ -78,10 +89,10 @@ impl RenderPlugin {
|
|||
}
|
||||
|
||||
impl AppPlugin for RenderPlugin {
|
||||
fn build(&self, mut app: AppBuilder) -> AppBuilder {
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
let mut asset_batchers = AssetBatchers::default();
|
||||
asset_batchers.batch_types2::<Mesh, StandardMaterial>();
|
||||
app = app
|
||||
app
|
||||
.add_system(build_entity_render_resource_assignments_system())
|
||||
.add_resource(RenderGraph::default())
|
||||
.add_resource(AssetStorage::<Mesh>::new())
|
||||
|
@ -95,7 +106,6 @@ impl AppPlugin for RenderPlugin {
|
|||
.add_resource(RenderResourceAssignments::default())
|
||||
.add_resource(EntityRenderResourceAssignments::default())
|
||||
.add_resource(asset_batchers);
|
||||
RenderPlugin::setup_render_graph_defaults(&mut app);
|
||||
app
|
||||
RenderPlugin::setup_render_graph_defaults(app);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,8 @@
|
|||
use super::{Color, PerspectiveCamera};
|
||||
use crate::{math, prelude::Translation};
|
||||
use std::ops::Range;
|
||||
use zerocopy::{AsBytes, FromBytes};
|
||||
use glam::Mat4;
|
||||
use bevy_transform::components::Translation;
|
||||
|
||||
pub struct Light {
|
||||
pub color: Color,
|
||||
|
@ -28,7 +29,7 @@ pub struct LightRaw {
|
|||
}
|
||||
|
||||
impl LightRaw {
|
||||
pub fn from(light: &Light, transform: &math::Mat4, translation: &Translation) -> LightRaw {
|
||||
pub fn from(light: &Light, transform: &Mat4, translation: &Translation) -> LightRaw {
|
||||
let perspective = PerspectiveCamera {
|
||||
fov: light.fov,
|
||||
aspect_ratio: 1.0,
|
|
@ -1,4 +1,6 @@
|
|||
use crate::{asset::Asset, math::*, render::Vertex};
|
||||
use crate::{Vertex};
|
||||
use bevy_asset::Asset;
|
||||
use glam::*;
|
||||
|
||||
pub enum MeshType {
|
||||
Cube,
|
|
@ -1,5 +1,5 @@
|
|||
use super::{LoadOp, StoreOp};
|
||||
use crate::prelude::Color;
|
||||
use crate::Color;
|
||||
|
||||
pub struct RenderPassColorAttachmentDescriptor {
|
||||
/// The actual color attachment.
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
pass::{
|
||||
LoadOp, PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, StoreOp,
|
|
@ -1,5 +1,5 @@
|
|||
use super::UniformProperty;
|
||||
use crate::render::texture::{TextureComponentType, TextureFormat, TextureViewDimension};
|
||||
use crate::texture::{TextureComponentType, TextureFormat, TextureViewDimension};
|
||||
|
||||
#[derive(Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct BindingDescriptor {
|
|
@ -7,14 +7,13 @@ use super::{
|
|||
BindGroupDescriptor, PipelineLayout, VertexBufferDescriptor,
|
||||
};
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
render::{
|
||||
render_resource::resource_name,
|
||||
shader::{Shader, ShaderStages},
|
||||
texture::TextureFormat,
|
||||
},
|
||||
render_resource::resource_name,
|
||||
shader::{Shader, ShaderStages},
|
||||
texture::TextureFormat,
|
||||
};
|
||||
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum PipelineLayoutType {
|
||||
Manual(PipelineLayout),
|
|
@ -1,14 +1,12 @@
|
|||
use super::{BindType, PipelineDescriptor, PipelineLayout, PipelineLayoutType, VertexBufferDescriptors};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
prelude::{Renderable, Resources, Shader, World},
|
||||
render::{
|
||||
render_resource::{
|
||||
BufferInfo, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::ShaderSource,
|
||||
render_resource::{
|
||||
BufferInfo, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
Renderable,
|
||||
shader::{Shader, ShaderSource},
|
||||
};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{BindGroupDescriptor, VertexBufferDescriptor, VertexBufferDescriptors};
|
||||
use crate::render::shader::ShaderLayout;
|
||||
use crate::shader::ShaderLayout;
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
pipeline::state_descriptors::{
|
||||
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
pipeline::state_descriptors::{
|
||||
BlendDescriptor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode,
|
||||
DepthStencilStateDescriptor, FrontFace, RasterizationStateDescriptor,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
pipeline::state_descriptors::{
|
||||
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::texture::TextureFormat;
|
||||
use crate::texture::TextureFormat;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DepthStencilStateDescriptor {
|
|
@ -1,8 +1,5 @@
|
|||
use crate::{
|
||||
math::{Mat4, Vec2, Vec3, Vec4},
|
||||
render::Color,
|
||||
};
|
||||
|
||||
use crate::Color;
|
||||
use glam::{Mat4, Vec2, Vec3, Vec4};
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum VertexFormat {
|
||||
Uchar2 = 1,
|
|
@ -1,16 +1,17 @@
|
|||
use super::RenderGraphBuilder;
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
prelude::{Resources, Shader, World},
|
||||
render::{
|
||||
{
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineCompiler, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
renderer::Renderer,
|
||||
texture::TextureDescriptor,
|
||||
shader::Shader,
|
||||
},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
#[derive(Default)]
|
|
@ -1,16 +1,17 @@
|
|||
use super::RenderGraph;
|
||||
use crate::{
|
||||
asset::AssetStorage,
|
||||
prelude::Shader,
|
||||
render::{
|
||||
{
|
||||
draw_target::DrawTarget,
|
||||
pass::PassDescriptor,
|
||||
pipeline::{PipelineBuilder, PipelineDescriptor},
|
||||
render_resource::ResourceProvider,
|
||||
texture::TextureDescriptor,
|
||||
shader::Shader,
|
||||
},
|
||||
};
|
||||
|
||||
use bevy_asset::AssetStorage;
|
||||
|
||||
pub struct RenderGraphBuilder<'a, 'b, 'c> {
|
||||
pub pipelines: &'a mut AssetStorage<PipelineDescriptor>,
|
||||
pub shaders: &'b mut AssetStorage<Shader>,
|
|
@ -1,5 +1,5 @@
|
|||
use super::{AssetSetBatcher2, AssetSetBatcherKey2, Batch, BatchKey2};
|
||||
use crate::asset::{Handle, HandleId};
|
||||
use bevy_asset::{Handle, HandleId};
|
||||
use legion::prelude::Entity;
|
||||
use std::{any::TypeId, collections::HashMap};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{AssetBatcher, Batch};
|
||||
use crate::asset::{HandleId, HandleUntyped};
|
||||
use bevy_asset::{HandleId, HandleUntyped};
|
||||
use legion::prelude::Entity;
|
||||
use std::{any::TypeId, collections::HashMap, hash::Hash};
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
use crate::{
|
||||
asset::{Handle, HandleUntyped},
|
||||
render::render_resource::RenderResourceAssignments,
|
||||
};
|
||||
use bevy_asset::{Handle, HandleUntyped};
|
||||
use crate::render_resource::RenderResourceAssignments;
|
||||
use legion::prelude::Entity;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use super::RenderResourceAssignmentsId;
|
||||
use crate::prelude::Renderable;
|
||||
use crate::Renderable;
|
||||
use legion::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
render::{mesh::Mesh, texture::Texture},
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use crate::{mesh::Mesh, texture::Texture};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Copy, Clone, Hash, Debug, Eq, PartialEq)]
|
|
@ -1,5 +1,5 @@
|
|||
use super::RenderResource;
|
||||
use crate::render::pipeline::{BindGroupDescriptor, BindGroupDescriptorId};
|
||||
use crate::pipeline::{BindGroupDescriptor, BindGroupDescriptorId};
|
||||
use std::{
|
||||
collections::{hash_map::DefaultHasher, HashMap, HashSet},
|
||||
hash::{Hash, Hasher},
|
|
@ -1,5 +1,5 @@
|
|||
use super::RenderResourceAssignmentsId;
|
||||
use crate::render::render_resource::BufferUsage;
|
||||
use crate::render_resource::BufferUsage;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Default, Debug)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::renderer::Renderer;
|
||||
use crate::renderer::Renderer;
|
||||
use legion::prelude::*;
|
||||
|
||||
pub trait ResourceProvider {
|
|
@ -1,13 +1,16 @@
|
|||
use bevy_app::{EventReader, Events};
|
||||
use bevy_window::WindowResized;
|
||||
|
||||
use crate::{
|
||||
prelude::*,
|
||||
render::{
|
||||
render_resource::{
|
||||
BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments, ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
camera::{ActiveCamera2d, Camera},
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceProvider,
|
||||
},
|
||||
window::WindowResized,
|
||||
renderer::Renderer,
|
||||
};
|
||||
|
||||
use legion::prelude::*;
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub struct Camera2dResourceProvider {
|
|
@ -1,15 +1,17 @@
|
|||
use bevy_window::WindowResized;
|
||||
|
||||
use crate::{
|
||||
prelude::*,
|
||||
render::{
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
ActiveCamera, Camera,
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceProvider,
|
||||
},
|
||||
window::WindowResized,
|
||||
renderer::Renderer,
|
||||
ActiveCamera, Camera,
|
||||
};
|
||||
|
||||
use bevy_app::{Events, EventReader};
|
||||
use legion::prelude::*;
|
||||
use bevy_transform::prelude::*;
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub struct CameraResourceProvider {
|
|
@ -1,13 +1,10 @@
|
|||
use bevy_window::Windows;
|
||||
use crate::{
|
||||
prelude::World,
|
||||
render::{
|
||||
render_resource::{RenderResourceAssignments, ResourceProvider},
|
||||
renderer::Renderer,
|
||||
texture::TextureDescriptor,
|
||||
},
|
||||
window::Windows,
|
||||
render_resource::{RenderResourceAssignments, ResourceProvider},
|
||||
renderer::Renderer,
|
||||
texture::TextureDescriptor,
|
||||
};
|
||||
use legion::prelude::Resources;
|
||||
use legion::prelude::*;
|
||||
|
||||
pub struct FrameTextureResourceProvider {
|
||||
pub name: String,
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
ResourceProvider,
|
|
@ -1,17 +1,15 @@
|
|||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
prelude::Renderable,
|
||||
render::{
|
||||
mesh::Mesh,
|
||||
pipeline::VertexBufferDescriptors,
|
||||
render_resource::{
|
||||
AssetBatchers, BufferInfo, BufferUsage, RenderResourceAssignments, ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::AsUniforms,
|
||||
Vertex,
|
||||
mesh::Mesh,
|
||||
pipeline::VertexBufferDescriptors,
|
||||
render_resource::{
|
||||
AssetBatchers, BufferInfo, BufferUsage, RenderResourceAssignments, ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::AsUniforms,
|
||||
Renderable,
|
||||
Vertex,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::{filter::*, prelude::*};
|
||||
use zerocopy::AsBytes;
|
||||
|
|
@ -3,7 +3,6 @@ mod camera_resource_provider;
|
|||
mod frame_texture_resource_provider;
|
||||
mod light_resource_provider;
|
||||
mod mesh_resource_provider;
|
||||
mod ui_resource_provider;
|
||||
mod uniform_resource_provider;
|
||||
|
||||
pub use camera2d_resource_provider::*;
|
||||
|
@ -11,5 +10,4 @@ pub use camera_resource_provider::*;
|
|||
pub use frame_texture_resource_provider::*;
|
||||
pub use light_resource_provider::*;
|
||||
pub use mesh_resource_provider::*;
|
||||
pub use ui_resource_provider::*;
|
||||
pub use uniform_resource_provider::*;
|
|
@ -1,17 +1,15 @@
|
|||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
render::{
|
||||
pipeline::VertexBufferDescriptors,
|
||||
render_resource::{
|
||||
AssetBatchers, BufferArrayInfo, BufferInfo, BufferUsage, RenderResource,
|
||||
RenderResourceAssignments, ResourceInfo, ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::{AsUniforms, FieldBindType},
|
||||
texture::{SamplerDescriptor, Texture, TextureDescriptor},
|
||||
Renderable,
|
||||
pipeline::VertexBufferDescriptors,
|
||||
render_resource::{
|
||||
AssetBatchers, BufferArrayInfo, BufferInfo, BufferUsage, RenderResource,
|
||||
RenderResourceAssignments, ResourceInfo, ResourceProvider,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::{AsUniforms, FieldBindType},
|
||||
texture::{SamplerDescriptor, Texture, TextureDescriptor},
|
||||
Renderable,
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::{filter::*, prelude::*};
|
||||
use std::marker::PhantomData;
|
||||
pub const BIND_BUFFER_ALIGNMENT: usize = 256;
|
|
@ -1,5 +1,5 @@
|
|||
use super::render_resource::RenderResourceAssignments;
|
||||
use crate::{asset::Handle, prelude::PipelineDescriptor};
|
||||
use crate::{pipeline::PipelineDescriptor, render_resource::RenderResourceAssignments};
|
||||
use bevy_asset::Handle;
|
||||
|
||||
pub struct Renderable {
|
||||
pub is_visible: bool,
|
|
@ -1,14 +1,12 @@
|
|||
use bevy_asset::{AssetStorage, Handle};
|
||||
use legion::prelude::*;
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
BufferInfo, RenderResource, RenderResourceAssignments, RenderResources, ResourceInfo,
|
||||
},
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
BufferInfo, RenderResource, RenderResourceAssignments, RenderResources, ResourceInfo,
|
||||
},
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use std::ops::Range;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use super::ShaderLayout;
|
||||
use crate::asset::Handle;
|
||||
use bevy_asset::Handle;
|
||||
use std::marker::Copy;
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)]
|
|
@ -1,4 +1,4 @@
|
|||
use crate::render::{
|
||||
use crate::{
|
||||
pipeline::{
|
||||
BindGroupDescriptor, BindType, BindingDescriptor, InputStepMode, UniformProperty,
|
||||
UniformPropertyType, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat,
|
|
@ -1,13 +1,12 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
core::GetBytes,
|
||||
render::{
|
||||
color::ColorSource,
|
||||
pipeline::{BindType, VertexBufferDescriptor},
|
||||
texture::Texture,
|
||||
},
|
||||
color::ColorSource,
|
||||
pipeline::{BindType, VertexBufferDescriptor},
|
||||
texture::Texture,
|
||||
};
|
||||
|
||||
use bevy_asset::Handle;
|
||||
use bevy_core::bytes::GetBytes;
|
||||
|
||||
pub trait AsUniforms {
|
||||
fn get_field_infos() -> &'static [FieldInfo];
|
||||
fn get_uniform_bytes(&self, name: &str) -> Option<Vec<u8>>;
|
|
@ -1,14 +1,10 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
core::GetBytes,
|
||||
render::{
|
||||
pipeline::{
|
||||
InputStepMode, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat,
|
||||
},
|
||||
shader::{AsFieldBindType, AsUniforms, FieldBindType, FieldInfo},
|
||||
texture::Texture,
|
||||
},
|
||||
pipeline::{InputStepMode, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat},
|
||||
shader::{AsFieldBindType, AsUniforms, FieldBindType, FieldInfo},
|
||||
texture::Texture,
|
||||
};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_core::bytes::GetBytes;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
static LOCAL_TO_WORLD_FIELD_INFOS: &[FieldInfo] = &[FieldInfo {
|
|
@ -1,12 +1,12 @@
|
|||
use crate::{
|
||||
asset::Handle,
|
||||
render::{texture::Texture, Color},
|
||||
};
|
||||
|
||||
use crate::{texture::Texture, Color};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_derive::Uniforms;
|
||||
|
||||
use bevy_core;
|
||||
use bevy_asset;
|
||||
|
||||
#[derive(Uniforms)]
|
||||
#[uniform(bevy_path = "crate")]
|
||||
#[uniform(bevy_render_path = "crate", bevy_core_path = "bevy_core", bevy_asset_path = "bevy_asset")]
|
||||
pub struct StandardMaterial {
|
||||
#[uniform(instance)]
|
||||
pub albedo: Color,
|
|
@ -1,5 +1,5 @@
|
|||
use super::Texture;
|
||||
use crate::render::pipeline::state_descriptors::CompareFunction;
|
||||
use crate::pipeline::state_descriptors::CompareFunction;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct SamplerDescriptor {
|
|
@ -1,9 +1,6 @@
|
|||
use crate::{
|
||||
asset::{Asset, Handle},
|
||||
core::GetBytes,
|
||||
render::shader::ShaderDefSuffixProvider,
|
||||
};
|
||||
use bevy_asset::{Asset, Handle};
|
||||
use std::fs::File;
|
||||
use crate::shader::ShaderDefSuffixProvider;
|
||||
|
||||
pub enum TextureType {
|
||||
Data(Vec<u8>, usize, usize),
|
||||
|
@ -67,14 +64,4 @@ impl ShaderDefSuffixProvider for Option<Handle<Texture>> {
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GetBytes for Option<Handle<Texture>> {
|
||||
fn get_bytes(&self) -> Vec<u8> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
use super::{Extent3d, Texture, TextureDimension, TextureFormat};
|
||||
use crate::render::texture::TextureUsage;
|
||||
use super::{Extent3d, Texture, TextureDimension, TextureFormat, TextureUsage};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TextureDescriptor {
|
|
@ -2,10 +2,12 @@ use std::convert::From;
|
|||
use zerocopy::{AsBytes, FromBytes};
|
||||
|
||||
use bevy_derive::Uniforms;
|
||||
use bevy_core;
|
||||
use bevy_asset;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, AsBytes, FromBytes, Uniforms)]
|
||||
#[uniform(bevy_path = "crate")]
|
||||
#[uniform(bevy_render_path = "crate", bevy_asset_path = "bevy_asset", bevy_core_path = "bevy_core")]
|
||||
pub struct Vertex {
|
||||
#[uniform(vertex)]
|
||||
pub position: [f32; 4],
|
25
bevy_wgpu/Cargo.toml
Normal file
25
bevy_wgpu/Cargo.toml
Normal file
|
@ -0,0 +1,25 @@
|
|||
[package]
|
||||
name = "bevy_wgpu"
|
||||
version = "0.1.0"
|
||||
authors = ["Carter Anderson <mcanders1@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
default = ["bevy_winit"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
# bevy
|
||||
bevy_app = { path = "../bevy_app", version = "0.1.0" }
|
||||
bevy_asset = { path = "../bevy_asset", version = "0.1.0" }
|
||||
bevy_core = { path = "../bevy_core", version = "0.1.0" }
|
||||
bevy_render = { path = "../bevy_render", version = "0.1.0" }
|
||||
bevy_window = { path = "../bevy_window", version = "0.1.0" }
|
||||
bevy_winit = { path = "../bevy_winit", version = "0.1.0", optional = true }
|
||||
legion = { path = "../bevy_legion" }
|
||||
|
||||
# render
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "d08f83762426c2c42eda74c7ca9c43d8d950fc0a" }
|
||||
|
||||
futures = "0.3"
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
|
@ -7,22 +7,18 @@ pub use wgpu_render_pass::*;
|
|||
pub use wgpu_renderer::*;
|
||||
pub use wgpu_resources::*;
|
||||
|
||||
use crate::{
|
||||
app::{plugin::AppPlugin, system_stage, AppBuilder},
|
||||
core::Events,
|
||||
render::renderer::Renderer,
|
||||
window::{WindowCreated, WindowResized},
|
||||
};
|
||||
|
||||
use bevy_app::{AppPlugin, system_stage, AppBuilder, Events};
|
||||
use bevy_render::renderer::Renderer;
|
||||
use bevy_window::{WindowCreated, WindowResized};
|
||||
use legion::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct WgpuRendererPlugin;
|
||||
|
||||
impl AppPlugin for WgpuRendererPlugin {
|
||||
fn build(&self, app: AppBuilder) -> AppBuilder {
|
||||
let render_system = wgpu_render_system(&app.resources);
|
||||
app.add_thread_local_to_stage(system_stage::RENDER, render_system)
|
||||
fn build(&self, app: &mut AppBuilder) {
|
||||
let render_system = wgpu_render_system(app.resources());
|
||||
app.add_thread_local_to_stage(system_stage::RENDER, render_system);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use super::{WgpuRenderer, WgpuResources};
|
||||
use crate::render::{
|
||||
use bevy_render::{
|
||||
pipeline::PipelineDescriptor,
|
||||
render_resource::{
|
||||
RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
|
|
@ -1,25 +1,23 @@
|
|||
use super::{wgpu_type_converter::OwnedWgpuVertexBufferDescriptor, WgpuRenderPass, WgpuResources};
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
core::{EventReader, Events},
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
pass::{
|
||||
PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor,
|
||||
},
|
||||
pipeline::{update_shader_assignments, PipelineCompiler, PipelineDescriptor},
|
||||
render_graph::RenderGraph,
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, RenderResource, RenderResourceAssignments, RenderResources,
|
||||
ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
use super::{wgpu_type_converter::{OwnedWgpuVertexBufferDescriptor, WgpuInto}, WgpuRenderPass, WgpuResources};
|
||||
use bevy_app::{EventReader, Events};
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_render::{
|
||||
pass::{
|
||||
PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor,
|
||||
},
|
||||
window::{winit::WinitWindows, Window, WindowCreated, WindowResized, Windows},
|
||||
pipeline::{update_shader_assignments, PipelineCompiler, PipelineDescriptor},
|
||||
render_graph::RenderGraph,
|
||||
render_resource::{
|
||||
resource_name, BufferInfo, RenderResource, RenderResourceAssignments, RenderResources,
|
||||
ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_window::{Window, WindowCreated, WindowResized, Windows};
|
||||
use legion::prelude::*;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::{HashMap, HashSet},
|
||||
|
@ -176,9 +174,9 @@ impl WgpuRenderer {
|
|||
});
|
||||
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
store_op: color_attachment_descriptor.store_op.into(),
|
||||
load_op: color_attachment_descriptor.load_op.into(),
|
||||
clear_color: color_attachment_descriptor.clear_color.into(),
|
||||
store_op: color_attachment_descriptor.store_op.wgpu_into(),
|
||||
load_op: color_attachment_descriptor.load_op.wgpu_into(),
|
||||
clear_color: color_attachment_descriptor.clear_color.wgpu_into(),
|
||||
attachment,
|
||||
resolve_target,
|
||||
}
|
||||
|
@ -203,10 +201,10 @@ impl WgpuRenderer {
|
|||
attachment,
|
||||
clear_depth: depth_stencil_attachment_descriptor.clear_depth,
|
||||
clear_stencil: depth_stencil_attachment_descriptor.clear_stencil,
|
||||
depth_load_op: depth_stencil_attachment_descriptor.depth_load_op.into(),
|
||||
depth_store_op: depth_stencil_attachment_descriptor.depth_store_op.into(),
|
||||
stencil_load_op: depth_stencil_attachment_descriptor.stencil_load_op.into(),
|
||||
stencil_store_op: depth_stencil_attachment_descriptor.stencil_store_op.into(),
|
||||
depth_load_op: depth_stencil_attachment_descriptor.depth_load_op.wgpu_into(),
|
||||
depth_store_op: depth_stencil_attachment_descriptor.depth_store_op.wgpu_into(),
|
||||
stencil_load_op: depth_stencil_attachment_descriptor.stencil_load_op.wgpu_into(),
|
||||
stencil_store_op: depth_stencil_attachment_descriptor.stencil_store_op.wgpu_into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,7 +272,6 @@ impl WgpuRenderer {
|
|||
|
||||
pub fn handle_window_created_events(&mut self, resources: &mut Resources) {
|
||||
let windows = resources.get::<Windows>().unwrap();
|
||||
let winit_windows = resources.get::<WinitWindows>().unwrap();
|
||||
let window_created_events = resources.get::<Events<WindowCreated>>().unwrap();
|
||||
for window_created_event in
|
||||
window_created_events.iter(&mut self.window_created_event_reader)
|
||||
|
@ -282,8 +279,9 @@ impl WgpuRenderer {
|
|||
let window = windows
|
||||
.get(window_created_event.id)
|
||||
.expect("Received window created event for non-existent window");
|
||||
#[cfg(feature = "winit")]
|
||||
#[cfg(feature = "bevy_winit")]
|
||||
{
|
||||
let winit_windows = resources.get::<bevy_winit::WinitWindows>().unwrap();
|
||||
let primary_winit_window = winit_windows.get_window(window.id).unwrap();
|
||||
let surface = wgpu::Surface::create(primary_winit_window.deref());
|
||||
self.wgpu_resources
|
||||
|
@ -301,7 +299,7 @@ impl WgpuRenderer {
|
|||
.get(&window.id)
|
||||
.expect("Received window resized event for window without a wgpu surface");
|
||||
|
||||
let swap_chain_descriptor: wgpu::SwapChainDescriptor = window.into();
|
||||
let swap_chain_descriptor: wgpu::SwapChainDescriptor = window.wgpu_into();
|
||||
let swap_chain = self
|
||||
.device
|
||||
.borrow()
|
||||
|
@ -555,7 +553,7 @@ impl Renderer for WgpuRenderer {
|
|||
.map(|binding| wgpu::BindGroupLayoutEntry {
|
||||
binding: binding.index,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: (&binding.bind_type).into(),
|
||||
ty: (&binding.bind_type).wgpu_into(),
|
||||
})
|
||||
.collect::<Vec<wgpu::BindGroupLayoutEntry>>();
|
||||
let wgpu_bind_group_layout =
|
||||
|
@ -588,13 +586,13 @@ impl Renderer for WgpuRenderer {
|
|||
let owned_vertex_buffer_descriptors = layout
|
||||
.vertex_buffer_descriptors
|
||||
.iter()
|
||||
.map(|v| v.into())
|
||||
.map(|v| v.wgpu_into())
|
||||
.collect::<Vec<OwnedWgpuVertexBufferDescriptor>>();
|
||||
|
||||
let color_states = pipeline_descriptor
|
||||
.color_states
|
||||
.iter()
|
||||
.map(|c| c.into())
|
||||
.map(|c| c.wgpu_into())
|
||||
.collect::<Vec<wgpu::ColorStateDescriptor>>();
|
||||
|
||||
if let None = self
|
||||
|
@ -648,15 +646,15 @@ impl Renderer for WgpuRenderer {
|
|||
rasterization_state: pipeline_descriptor
|
||||
.rasterization_state
|
||||
.as_ref()
|
||||
.map(|r| r.into()),
|
||||
primitive_topology: pipeline_descriptor.primitive_topology.into(),
|
||||
.map(|r| r.wgpu_into()),
|
||||
primitive_topology: pipeline_descriptor.primitive_topology.wgpu_into(),
|
||||
color_states: &color_states,
|
||||
depth_stencil_state: pipeline_descriptor
|
||||
.depth_stencil_state
|
||||
.as_ref()
|
||||
.map(|d| d.into()),
|
||||
.map(|d| d.wgpu_into()),
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: pipeline_descriptor.index_format.into(),
|
||||
index_format: pipeline_descriptor.index_format.wgpu_into(),
|
||||
vertex_buffers: &owned_vertex_buffer_descriptors
|
||||
.iter()
|
||||
.map(|v| v.into())
|
|
@ -1,18 +1,17 @@
|
|||
use super::WgpuRenderer;
|
||||
use crate::{
|
||||
asset::{AssetStorage, Handle},
|
||||
prelude::Shader,
|
||||
render::{
|
||||
pipeline::{BindGroupDescriptor, BindGroupDescriptorId, BindType},
|
||||
render_resource::{
|
||||
BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId,
|
||||
RenderResources, ResourceInfo,
|
||||
},
|
||||
renderer::Renderer,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
use crate::wgpu_type_converter::WgpuInto;
|
||||
use bevy_asset::{AssetStorage, Handle};
|
||||
use bevy_render::{
|
||||
pipeline::{BindGroupDescriptor, BindGroupDescriptorId, BindType},
|
||||
render_resource::{
|
||||
BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId,
|
||||
RenderResources, ResourceInfo,
|
||||
},
|
||||
window::WindowId,
|
||||
renderer::Renderer,
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_window::WindowId;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -150,7 +149,7 @@ impl WgpuResources {
|
|||
) -> RenderResource {
|
||||
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size: buffer_info.size as u64,
|
||||
usage: buffer_info.buffer_usage.into(),
|
||||
usage: buffer_info.buffer_usage.wgpu_into(),
|
||||
});
|
||||
|
||||
let resource = self.render_resources.get_next_resource();
|
||||
|
@ -167,7 +166,7 @@ impl WgpuResources {
|
|||
data: &[u8],
|
||||
) -> RenderResource {
|
||||
buffer_info.size = data.len();
|
||||
let buffer = device.create_buffer_with_data(data, buffer_info.buffer_usage.into());
|
||||
let buffer = device.create_buffer_with_data(data, buffer_info.buffer_usage.wgpu_into());
|
||||
self.assign_buffer(buffer, buffer_info)
|
||||
}
|
||||
|
||||
|
@ -200,7 +199,7 @@ impl WgpuResources {
|
|||
let device = device_rc.borrow();
|
||||
|
||||
let mut mapped =
|
||||
device.create_buffer_mapped(buffer_info.size as usize, buffer_info.buffer_usage.into());
|
||||
device.create_buffer_mapped(buffer_info.size as usize, buffer_info.buffer_usage.wgpu_into());
|
||||
setup_data(&mut mapped.data, renderer);
|
||||
mapped.finish()
|
||||
}
|
||||
|
@ -236,7 +235,7 @@ impl WgpuResources {
|
|||
device: &wgpu::Device,
|
||||
sampler_descriptor: &SamplerDescriptor,
|
||||
) -> RenderResource {
|
||||
let descriptor: wgpu::SamplerDescriptor = (*sampler_descriptor).into();
|
||||
let descriptor: wgpu::SamplerDescriptor = (*sampler_descriptor).wgpu_into();
|
||||
let sampler = device.create_sampler(&descriptor);
|
||||
let resource = self.render_resources.get_next_resource();
|
||||
self.samplers.insert(resource, sampler);
|
||||
|
@ -251,7 +250,7 @@ impl WgpuResources {
|
|||
texture_descriptor: &TextureDescriptor,
|
||||
bytes: Option<&[u8]>,
|
||||
) -> RenderResource {
|
||||
let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).into();
|
||||
let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).wgpu_into();
|
||||
let texture = device.create_texture(&descriptor);
|
||||
let texture_view = texture.create_default_view();
|
||||
if let Some(bytes) = bytes {
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue