cargo fmt

This commit is contained in:
Carter Anderson 2020-03-20 12:47:33 -07:00
parent faaf307edb
commit 9881f64715
28 changed files with 98 additions and 110 deletions

View File

@ -72,7 +72,9 @@ fn setup(world: &mut World, resources: &mut Resources) {
let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap(); let mut mesh_storage = resources.get_mut::<AssetStorage<Mesh>>().unwrap();
let cube_handle = mesh_storage.add(Mesh::load(MeshType::Cube)); let cube_handle = mesh_storage.add(Mesh::load(MeshType::Cube));
let mut pipeline_storage = resources.get_mut::<AssetStorage<PipelineDescriptor>>().unwrap(); let mut pipeline_storage = resources
.get_mut::<AssetStorage<PipelineDescriptor>>()
.unwrap();
let material_handle = pipeline_storage.get_named("MyMaterial").unwrap(); let material_handle = pipeline_storage.get_named("MyMaterial").unwrap();
world world

View File

@ -20,7 +20,7 @@ fn build_move_system() -> Box<dyn Schedulable> {
let material = material_storage.get_mut(&material_handle).unwrap(); let material = material_storage.get_mut(&material_handle).unwrap();
translation.0 += math::vec3(1.0, 0.0, 0.0) * time.delta_seconds; translation.0 += math::vec3(1.0, 0.0, 0.0) * time.delta_seconds;
material.albedo = material.albedo material.albedo = material.albedo
+ Color::rgb(-time.delta_seconds, -time.delta_seconds, time.delta_seconds); + Color::rgb(-time.delta_seconds, -time.delta_seconds, time.delta_seconds);
} }
}) })
} }

View File

@ -15,9 +15,9 @@ use crate::{
use bevy_transform::{prelude::LocalToWorld, transform_system_bundle}; use bevy_transform::{prelude::LocalToWorld, transform_system_bundle};
use pipeline::PipelineDescriptor; use pipeline::PipelineDescriptor;
use render_graph::RenderGraphBuilder; use render_graph::RenderGraphBuilder;
use render_resource::AssetBatchers;
use shader::Shader; use shader::Shader;
use std::collections::HashMap; use std::collections::HashMap;
use render_resource::AssetBatchers;
pub struct AppBuilder { pub struct AppBuilder {
pub world: World, pub world: World,

View File

@ -2,15 +2,15 @@
pub mod app; pub mod app;
pub mod asset; pub mod asset;
pub mod core; pub mod core;
pub mod diagnostics;
pub mod ecs; pub mod ecs;
pub mod plugin; pub mod plugin;
pub mod prelude; pub mod prelude;
pub mod render; pub mod render;
pub mod serialization; pub mod serialization;
pub mod ui; pub mod ui;
pub mod diagnostics;
pub use bevy_transform as transform; pub use bevy_transform as transform;
pub use glam as math; pub use glam as math;
pub use legion; pub use legion;
pub use once_cell; pub use once_cell;

View File

@ -24,8 +24,7 @@ impl DrawTarget for MeshesDrawTarget {
) { ) {
let mut current_mesh_handle = None; let mut current_mesh_handle = None;
let mut current_mesh_index_len = 0; let mut current_mesh_index_len = 0;
let mesh_query = let mesh_query = <(Read<Handle<Mesh>>, Read<Renderable>)>::query();
<(Read<Handle<Mesh>>, Read<Renderable>)>::query();
for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) { for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) {
if !renderable.is_visible { if !renderable.is_visible {

View File

@ -1,9 +1,9 @@
mod assigned_batches_draw_target;
mod assigned_meshes_draw_target; mod assigned_meshes_draw_target;
mod meshes_draw_target; mod meshes_draw_target;
mod ui_draw_target; mod ui_draw_target;
mod assigned_batches_draw_target;
pub use assigned_batches_draw_target::*;
pub use assigned_meshes_draw_target::*; pub use assigned_meshes_draw_target::*;
pub use meshes_draw_target::*; pub use meshes_draw_target::*;
pub use ui_draw_target::*; pub use ui_draw_target::*;
pub use assigned_batches_draw_target::*;

View File

@ -20,4 +20,4 @@ pub mod pipeline;
pub mod render_resource; pub mod render_resource;
mod renderable; mod renderable;
pub mod renderer; pub mod renderer;
pub mod texture; pub mod texture;

View File

@ -3,13 +3,13 @@ mod binding;
mod pipeline; mod pipeline;
mod pipeline_layout; mod pipeline_layout;
pub mod pipelines; pub mod pipelines;
pub mod state_descriptors;
mod vertex_buffer_descriptor; mod vertex_buffer_descriptor;
mod vertex_format; mod vertex_format;
pub mod state_descriptors;
pub use bind_group::*; pub use bind_group::*;
pub use binding::*; pub use binding::*;
pub use pipeline::*; pub use pipeline::*;
pub use pipeline_layout::*; pub use pipeline_layout::*;
pub use vertex_buffer_descriptor::*; pub use vertex_buffer_descriptor::*;
pub use vertex_format::*; pub use vertex_format::*;

View File

@ -1,8 +1,8 @@
use super::{ use super::{
state_descriptors::{ state_descriptors::{
BlendDescriptor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode, BlendDescriptor, ColorStateDescriptor, ColorWrite, CompareFunction, CullMode,
DepthStencilStateDescriptor, FrontFace, PrimitiveTopology, RasterizationStateDescriptor, DepthStencilStateDescriptor, FrontFace, IndexFormat, PrimitiveTopology,
StencilStateFaceDescriptor, IndexFormat, RasterizationStateDescriptor, StencilStateFaceDescriptor,
}, },
BindGroup, PipelineLayout, VertexBufferDescriptor, BindGroup, PipelineLayout, VertexBufferDescriptor,
}; };

View File

@ -6,10 +6,11 @@ use crate::{
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite, BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace,
RasterizationStateDescriptor, StencilStateFaceDescriptor, RasterizationStateDescriptor, StencilStateFaceDescriptor,
}, PipelineDescriptor, },
PipelineDescriptor,
}, },
render_graph::RenderGraphBuilder, render_graph::RenderGraphBuilder,
render_resource::{resource_name}, render_resource::resource_name,
shader::{Shader, ShaderStage}, shader::{Shader, ShaderStage},
texture::TextureFormat, texture::TextureFormat,
}, },

View File

@ -171,4 +171,4 @@ impl Default for BlendOperation {
pub enum IndexFormat { pub enum IndexFormat {
Uint16 = 0, Uint16 = 0,
Uint32 = 1, Uint32 = 1,
} }

View File

@ -20,4 +20,4 @@ pub struct VertexAttributeDescriptor {
pub offset: u64, pub offset: u64,
pub format: VertexFormat, pub format: VertexFormat,
pub shader_location: u32, pub shader_location: u32,
} }

View File

@ -1,4 +1,4 @@
use crate::math::{Vec2, Vec3, Vec4, Mat4}; use crate::math::{Mat4, Vec2, Vec3, Vec4};
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum VertexFormat { pub enum VertexFormat {
@ -108,4 +108,4 @@ impl AsVertexFormats for Mat4 {
VertexFormat::Float4, VertexFormat::Float4,
] ]
} }
} }

View File

@ -36,7 +36,8 @@ impl RenderGraphBuilder {
if let Some(ref pass) = self.current_pass { if let Some(ref pass) = self.current_pass {
let name = pipeline.name.clone(); let name = pipeline.name.clone();
let pipeline_descriptor_handle = pipeline_descriptor_storage.add(pipeline); let pipeline_descriptor_handle = pipeline_descriptor_storage.add(pipeline);
pipeline_descriptor_storage.set_name(name.unwrap().as_str(), pipeline_descriptor_handle); pipeline_descriptor_storage
.set_name(name.unwrap().as_str(), pipeline_descriptor_handle);
self.render_graph self.render_graph
.add_pipeline(&pass, pipeline_descriptor_handle); .add_pipeline(&pass, pipeline_descriptor_handle);
} }

View File

@ -281,10 +281,7 @@ mod tests {
// entity[0] is added to batch when it has both Handle<A> and Handle<B> // entity[0] is added to batch when it has both Handle<A> and Handle<B>
let mut expected_batch = Batch::default(); let mut expected_batch = Batch::default();
expected_batch.add_entity(entities[0]); expected_batch.add_entity(entities[0]);
assert_eq!( assert_eq!(asset_batchers.get_batch2(a1, b1).unwrap(), &expected_batch);
asset_batchers.get_batch2(a1, b1).unwrap(),
&expected_batch
);
asset_batchers.set_entity_handle(entities[0], c1); asset_batchers.set_entity_handle(entities[0], c1);
asset_batchers.set_entity_handle(entities[1], a1); asset_batchers.set_entity_handle(entities[1], a1);
@ -294,10 +291,7 @@ mod tests {
let mut expected_batch = Batch::default(); let mut expected_batch = Batch::default();
expected_batch.add_entity(entities[0]); expected_batch.add_entity(entities[0]);
expected_batch.add_entity(entities[1]); expected_batch.add_entity(entities[1]);
assert_eq!( assert_eq!(asset_batchers.get_batch2(a1, b1).unwrap(), &expected_batch);
asset_batchers.get_batch2(a1, b1).unwrap(),
&expected_batch
);
// uncreated batches are empty // uncreated batches are empty
assert_eq!(asset_batchers.get_batch2(a1, c1), None); assert_eq!(asset_batchers.get_batch2(a1, c1), None);
@ -323,14 +317,14 @@ mod tests {
handle1: a1.id, handle1: a1.id,
handle2: b1.id, handle2: b1.id,
}, },
expected_batch1 expected_batch1,
), ),
( (
BatchKey2 { BatchKey2 {
handle1: a2.id, handle1: a2.id,
handle2: b2.id, handle2: b2.id,
}, },
expected_batch2 expected_batch2,
), ),
]; ];
expected_batches.sort_by(|a, b| a.0.cmp(&b.0)); expected_batches.sort_by(|a, b| a.0.cmp(&b.0));

View File

@ -1,13 +1,13 @@
mod asset_batcher;
mod buffer; mod buffer;
mod render_resource; mod render_resource;
mod resource_info; mod resource_info;
pub mod resource_name; pub mod resource_name;
mod resource_provider; mod resource_provider;
mod asset_batcher;
pub mod resource_providers; pub mod resource_providers;
pub use asset_batcher::*;
pub use buffer::*; pub use buffer::*;
pub use render_resource::*; pub use render_resource::*;
pub use resource_info::*; pub use resource_info::*;
pub use resource_provider::*; pub use resource_provider::*;
pub use asset_batcher::*;

View File

@ -30,4 +30,4 @@ pub mod pipeline {
pub const FORWARD: &str = "Forward"; pub const FORWARD: &str = "Forward";
pub const FORWARD_FLAT: &str = "ForwardFlat"; pub const FORWARD_FLAT: &str = "ForwardFlat";
pub const UI: &str = "Ui"; pub const UI: &str = "Ui";
} }

View File

@ -2,9 +2,9 @@ use crate::{
asset::{AssetStorage, Handle}, asset::{AssetStorage, Handle},
prelude::Renderable, prelude::Renderable,
render::{ render::{
render_resource::{BufferUsage, ResourceProvider, AssetBatchers},
renderer::Renderer,
mesh::Mesh, mesh::Mesh,
render_resource::{AssetBatchers, BufferUsage, ResourceProvider},
renderer::Renderer,
}, },
}; };
use legion::{filter::*, prelude::*}; use legion::{filter::*, prelude::*};

View File

@ -2,7 +2,7 @@ use crate::{
asset::{AssetStorage, Handle}, asset::{AssetStorage, Handle},
render::{ render::{
pipeline::BindType, pipeline::BindType,
render_resource::{BufferUsage, RenderResource, ResourceProvider, AssetBatchers}, render_resource::{AssetBatchers, BufferUsage, RenderResource, ResourceProvider},
renderer::Renderer, renderer::Renderer,
shader::{AsUniforms, DynamicUniformBufferInfo, UniformInfoIter}, shader::{AsUniforms, DynamicUniformBufferInfo, UniformInfoIter},
texture::{SamplerDescriptor, Texture, TextureDescriptor}, texture::{SamplerDescriptor, Texture, TextureDescriptor},

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
legion::prelude::*, legion::prelude::*,
render::{ render::{
pipeline::{VertexBufferDescriptor, PipelineDescriptor}, pipeline::{PipelineDescriptor, VertexBufferDescriptor},
render_graph::RenderGraph, render_graph::RenderGraph,
render_resource::{BufferUsage, RenderResource, RenderResources, ResourceInfo}, render_resource::{BufferUsage, RenderResource, RenderResources, ResourceInfo},
shader::DynamicUniformBufferInfo, shader::DynamicUniformBufferInfo,

View File

@ -7,7 +7,10 @@ use crate::{
PassDescriptor, RenderPassColorAttachmentDescriptor, PassDescriptor, RenderPassColorAttachmentDescriptor,
RenderPassDepthStencilAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
}, },
pipeline::{BindType, PipelineDescriptor, PipelineLayout, PipelineLayoutType, VertexBufferDescriptor}, pipeline::{
BindType, PipelineDescriptor, PipelineLayout, PipelineLayoutType,
VertexBufferDescriptor,
},
render_graph::RenderGraph, render_graph::RenderGraph,
render_resource::{ render_resource::{
resource_name, BufferUsage, RenderResource, RenderResources, ResourceInfo, resource_name, BufferUsage, RenderResource, RenderResources, ResourceInfo,
@ -712,16 +715,13 @@ impl Renderer for WgpuRenderer {
} }
} }
} }
fn set_vertex_buffer_descriptor( fn set_vertex_buffer_descriptor(&mut self, vertex_buffer_descriptor: VertexBufferDescriptor) {
&mut self, self.vertex_buffer_descriptors.insert(
vertex_buffer_descriptor: VertexBufferDescriptor, vertex_buffer_descriptor.name.to_string(),
) { vertex_buffer_descriptor,
self.vertex_buffer_descriptors.insert(vertex_buffer_descriptor.name.to_string(), vertex_buffer_descriptor); );
} }
fn get_vertex_buffer_descriptor( fn get_vertex_buffer_descriptor(&self, name: &str) -> Option<&VertexBufferDescriptor> {
&self,
name: &str
) -> Option<&VertexBufferDescriptor> {
self.vertex_buffer_descriptors.get(name) self.vertex_buffer_descriptors.get(name)
} }
} }

View File

@ -57,9 +57,7 @@ impl WgpuResources {
for binding in bind_group.bindings.iter() { for binding in bind_group.bindings.iter() {
let resource = match self.render_resources.get_named_resource(&binding.name) { let resource = match self.render_resources.get_named_resource(&binding.name) {
resource @ Some(_) => resource, resource @ Some(_) => resource,
None => { None => return,
return
}
}; };
if let Some(resource) = resource { if let Some(resource) = resource {
@ -108,12 +106,8 @@ impl WgpuResources {
}; };
let bind_group = device.create_bind_group(&bind_group_descriptor); let bind_group = device.create_bind_group(&bind_group_descriptor);
self.bind_groups.insert( self.bind_groups
bind_group_id, .insert(bind_group_id, BindGroupInfo { bind_group });
BindGroupInfo {
bind_group,
},
);
} }
} }
pub fn get_entity_bind_group( pub fn get_entity_bind_group(
@ -187,12 +181,8 @@ impl WgpuResources {
let bind_group = device.create_bind_group(&bind_group_descriptor); let bind_group = device.create_bind_group(&bind_group_descriptor);
// TODO: storing a large number entity bind groups might actually be really bad. make sure this is ok // TODO: storing a large number entity bind groups might actually be really bad. make sure this is ok
self.entity_bind_groups.insert( self.entity_bind_groups
(entity, bind_group_id), .insert((entity, bind_group_id), BindGroupInfo { bind_group });
BindGroupInfo {
bind_group,
},
);
} }
pub fn create_buffer( pub fn create_buffer(

View File

@ -14,8 +14,8 @@ use crate::{
}, },
render_resource::BufferUsage, render_resource::BufferUsage,
texture::{ texture::{
AddressMode, Extent3d, SamplerDescriptor, TextureDescriptor, TextureDimension, AddressMode, Extent3d, FilterMode, SamplerDescriptor, TextureDescriptor,
TextureFormat, TextureUsage, TextureViewDimension, FilterMode, TextureDimension, TextureFormat, TextureUsage, TextureViewDimension,
}, },
}, },
}; };
@ -472,4 +472,4 @@ impl From<FilterMode> for wgpu::FilterMode {
FilterMode::Linear => wgpu::FilterMode::Linear, FilterMode::Linear => wgpu::FilterMode::Linear,
} }
} }
} }

View File

@ -383,14 +383,12 @@ mod tests {
}, },
VertexBufferDescriptor { VertexBufferDescriptor {
name: "TestInstancing".to_string(), name: "TestInstancing".to_string(),
attributes: vec![ attributes: vec![VertexAttributeDescriptor {
VertexAttributeDescriptor { name: "I_TestInstancing_Property".to_string(),
name: "I_TestInstancing_Property".to_string(), format: VertexFormat::Uint4,
format: VertexFormat::Uint4, offset: 0,
offset: 0, shader_location: 2,
shader_location: 2, },],
},
],
step_mode: InputStepMode::Instance, step_mode: InputStepMode::Instance,
stride: 16, stride: 16,
} }

View File

@ -19,37 +19,38 @@ static LOCAL_TO_WORLD_FIELD_INFOS: &[FieldInfo] = &[FieldInfo {
is_instanceable: true, is_instanceable: true,
}]; }];
static VERTEX_BUFFER_DESCRIPTOR: Lazy<VertexBufferDescriptor> = Lazy::new(|| VertexBufferDescriptor { static VERTEX_BUFFER_DESCRIPTOR: Lazy<VertexBufferDescriptor> =
attributes: vec![ Lazy::new(|| VertexBufferDescriptor {
VertexAttributeDescriptor { attributes: vec![
name: "I_Object_Matrix_0".to_string(), VertexAttributeDescriptor {
format: VertexFormat::Float4, name: "I_Object_Matrix_0".to_string(),
offset: 0, format: VertexFormat::Float4,
shader_location: 0, offset: 0,
}, shader_location: 0,
VertexAttributeDescriptor { },
name: "I_Object_Matrix_1".to_string(), VertexAttributeDescriptor {
format: VertexFormat::Float4, name: "I_Object_Matrix_1".to_string(),
offset: 16, format: VertexFormat::Float4,
shader_location: 0, offset: 16,
}, shader_location: 0,
VertexAttributeDescriptor { },
name: "I_Object_Matrix_2".to_string(), VertexAttributeDescriptor {
format: VertexFormat::Float4, name: "I_Object_Matrix_2".to_string(),
offset: 32, format: VertexFormat::Float4,
shader_location: 0, offset: 32,
}, shader_location: 0,
VertexAttributeDescriptor { },
name: "I_Object_Matrix_3".to_string(), VertexAttributeDescriptor {
format: VertexFormat::Float4, name: "I_Object_Matrix_3".to_string(),
offset: 48, format: VertexFormat::Float4,
shader_location: 0, offset: 48,
}, shader_location: 0,
], },
name: "Object".to_string(), ],
step_mode: InputStepMode::Instance, name: "Object".to_string(),
stride: 64, step_mode: InputStepMode::Instance,
}); stride: 64,
});
impl AsUniforms for bevy_transform::prelude::LocalToWorld { impl AsUniforms for bevy_transform::prelude::LocalToWorld {
fn get_field_infos(&self) -> &[FieldInfo] { fn get_field_infos(&self) -> &[FieldInfo] {

View File

@ -1,4 +1,7 @@
use crate::{asset::Handle, render::{Color, texture::Texture}}; use crate::{
asset::Handle,
render::{texture::Texture, Color},
};
use crate as bevy; // for macro imports use crate as bevy; // for macro imports
use bevy_derive::Uniforms; use bevy_derive::Uniforms;

View File

@ -1,9 +1,9 @@
mod texture;
mod sampler_descriptor; mod sampler_descriptor;
mod texture;
mod texture_descriptor; mod texture_descriptor;
mod texture_dimension; mod texture_dimension;
pub use texture::*;
pub use sampler_descriptor::*; pub use sampler_descriptor::*;
pub use texture::*;
pub use texture_descriptor::*; pub use texture_descriptor::*;
pub use texture_dimension::*; pub use texture_dimension::*;

View File

@ -10,7 +10,6 @@ pub enum TextureViewDimension {
D3, D3,
} }
#[derive(Copy, Clone, Debug, Hash)] #[derive(Copy, Clone, Debug, Hash)]
pub enum TextureDimension { pub enum TextureDimension {
D1, D1,
@ -106,4 +105,4 @@ bitflags::bitflags! {
const ORDERED = Self::READ_ALL.bits | Self::OUTPUT_ATTACHMENT.bits; const ORDERED = Self::READ_ALL.bits | Self::OUTPUT_ATTACHMENT.bits;
const UNINITIALIZED = 0xFFFF; const UNINITIALIZED = 0xFFFF;
} }
} }