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 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();
world

View File

@ -20,7 +20,7 @@ fn build_move_system() -> Box<dyn Schedulable> {
let material = material_storage.get_mut(&material_handle).unwrap();
translation.0 += math::vec3(1.0, 0.0, 0.0) * time.delta_seconds;
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 pipeline::PipelineDescriptor;
use render_graph::RenderGraphBuilder;
use render_resource::AssetBatchers;
use shader::Shader;
use std::collections::HashMap;
use render_resource::AssetBatchers;
pub struct AppBuilder {
pub world: World,

View File

@ -2,15 +2,15 @@
pub mod app;
pub mod asset;
pub mod core;
pub mod diagnostics;
pub mod ecs;
pub mod plugin;
pub mod prelude;
pub mod render;
pub mod serialization;
pub mod ui;
pub mod diagnostics;
pub use bevy_transform as transform;
pub use glam as math;
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_index_len = 0;
let mesh_query =
<(Read<Handle<Mesh>>, Read<Renderable>)>::query();
let mesh_query = <(Read<Handle<Mesh>>, Read<Renderable>)>::query();
for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) {
if !renderable.is_visible {

View File

@ -1,9 +1,9 @@
mod assigned_batches_draw_target;
mod assigned_meshes_draw_target;
mod meshes_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 meshes_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;
mod renderable;
pub mod renderer;
pub mod texture;
pub mod texture;

View File

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

View File

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

View File

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

View File

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

View File

@ -20,4 +20,4 @@ pub struct VertexAttributeDescriptor {
pub offset: u64,
pub format: VertexFormat,
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)]
pub enum VertexFormat {
@ -108,4 +108,4 @@ impl AsVertexFormats for Mat4 {
VertexFormat::Float4,
]
}
}
}

View File

@ -36,7 +36,8 @@ impl RenderGraphBuilder {
if let Some(ref pass) = self.current_pass {
let name = pipeline.name.clone();
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
.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>
let mut expected_batch = Batch::default();
expected_batch.add_entity(entities[0]);
assert_eq!(
asset_batchers.get_batch2(a1, b1).unwrap(),
&expected_batch
);
assert_eq!(asset_batchers.get_batch2(a1, b1).unwrap(), &expected_batch);
asset_batchers.set_entity_handle(entities[0], c1);
asset_batchers.set_entity_handle(entities[1], a1);
@ -294,10 +291,7 @@ mod tests {
let mut expected_batch = Batch::default();
expected_batch.add_entity(entities[0]);
expected_batch.add_entity(entities[1]);
assert_eq!(
asset_batchers.get_batch2(a1, b1).unwrap(),
&expected_batch
);
assert_eq!(asset_batchers.get_batch2(a1, b1).unwrap(), &expected_batch);
// uncreated batches are empty
assert_eq!(asset_batchers.get_batch2(a1, c1), None);
@ -323,14 +317,14 @@ mod tests {
handle1: a1.id,
handle2: b1.id,
},
expected_batch1
expected_batch1,
),
(
BatchKey2 {
handle1: a2.id,
handle2: b2.id,
},
expected_batch2
expected_batch2,
),
];
expected_batches.sort_by(|a, b| a.0.cmp(&b.0));

View File

@ -1,13 +1,13 @@
mod asset_batcher;
mod buffer;
mod render_resource;
mod resource_info;
pub mod resource_name;
mod resource_provider;
mod asset_batcher;
pub mod resource_providers;
pub use asset_batcher::*;
pub use buffer::*;
pub use render_resource::*;
pub use resource_info::*;
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_FLAT: &str = "ForwardFlat";
pub const UI: &str = "Ui";
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -57,9 +57,7 @@ impl WgpuResources {
for binding in bind_group.bindings.iter() {
let resource = match self.render_resources.get_named_resource(&binding.name) {
resource @ Some(_) => resource,
None => {
return
}
None => return,
};
if let Some(resource) = resource {
@ -108,12 +106,8 @@ impl WgpuResources {
};
let bind_group = device.create_bind_group(&bind_group_descriptor);
self.bind_groups.insert(
bind_group_id,
BindGroupInfo {
bind_group,
},
);
self.bind_groups
.insert(bind_group_id, BindGroupInfo { bind_group });
}
}
pub fn get_entity_bind_group(
@ -187,12 +181,8 @@ impl WgpuResources {
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
self.entity_bind_groups.insert(
(entity, bind_group_id),
BindGroupInfo {
bind_group,
},
);
self.entity_bind_groups
.insert((entity, bind_group_id), BindGroupInfo { bind_group });
}
pub fn create_buffer(

View File

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

View File

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

View File

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

View File

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

View File

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