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