mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
cargo fmt
This commit is contained in:
parent
800c4342ed
commit
c5ca59dc4d
43 changed files with 176 additions and 187 deletions
12
Cargo.toml
12
Cargo.toml
|
@ -23,6 +23,12 @@ wgpu = ["bevy_wgpu"]
|
|||
winit = ["bevy_winit"]
|
||||
more-system-fns = ["legion/more-system-fns"]
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/*",
|
||||
"examples/app/dynamic_plugin_loading/example_plugin"
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
# bevy
|
||||
bevy_app = { path = "crates/bevy_app" }
|
||||
|
@ -45,12 +51,6 @@ glam = { path = "crates/bevy_glam" }
|
|||
# other
|
||||
log = { version = "0.4", features = ["release_max_level_info"] }
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"crates/*",
|
||||
"examples/app/dynamic_plugin_loading/example_plugin"
|
||||
]
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.7.2"
|
||||
serde = { version = "1", features = ["derive"]}
|
||||
|
|
|
@ -151,10 +151,7 @@ impl AppBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn init_startup_system<T>(
|
||||
&mut self,
|
||||
build: impl FnMut(&mut Resources) -> T,
|
||||
) -> &mut Self
|
||||
pub fn init_startup_system<T>(&mut self, build: impl FnMut(&mut Resources) -> T) -> &mut Self
|
||||
where
|
||||
T: Into<System>,
|
||||
{
|
||||
|
|
|
@ -28,7 +28,9 @@ impl ScheduleRunnerPlugin {
|
|||
|
||||
pub fn run_loop(wait_duration: Duration) -> Self {
|
||||
ScheduleRunnerPlugin {
|
||||
run_mode: RunMode::Loop { wait: Some(wait_duration) },
|
||||
run_mode: RunMode::Loop {
|
||||
wait: Some(wait_duration),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ use uuid::Uuid;
|
|||
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||
pub struct HandleId(pub Uuid);
|
||||
pub const DEFAULT_HANDLE_ID: HandleId = HandleId(Uuid::from_u128(240940089166493627844978703213080810552));
|
||||
pub const DEFAULT_HANDLE_ID: HandleId =
|
||||
HandleId(Uuid::from_u128(240940089166493627844978703213080810552));
|
||||
|
||||
impl HandleId {
|
||||
pub fn new() -> HandleId {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use glam::{Mat4, Vec4, Vec3, Vec2};
|
||||
use glam::{Mat4, Vec2, Vec3, Vec4};
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub trait GetBytes {
|
||||
|
@ -64,7 +64,6 @@ impl GetBytes for Vec2 {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl GetBytes for Vec4 {
|
||||
fn get_bytes(&self) -> Vec<u8> {
|
||||
let vec4_array: [f32; 4] = (*self).into();
|
||||
|
|
|
@ -2,9 +2,9 @@ extern crate proc_macro;
|
|||
|
||||
mod modules;
|
||||
|
||||
use modules::{get_modules, get_path};
|
||||
use darling::FromMeta;
|
||||
use inflector::Inflector;
|
||||
use modules::{get_modules, get_path};
|
||||
use proc_macro::TokenStream;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Field, Fields, Ident, Path, Type};
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
mod diagnostic;
|
||||
mod print_diagnostics_plugin;
|
||||
mod frame_time_diagnostics_plugin;
|
||||
pub use diagnostic::*;
|
||||
mod print_diagnostics_plugin;
|
||||
pub use diagnostic::*;
|
||||
pub use frame_time_diagnostics_plugin::FrameTimeDiagnosticsPlugin;
|
||||
pub use print_diagnostics_plugin::PrintDiagnosticsPlugin;
|
||||
|
|
|
@ -46,32 +46,32 @@ fn vec3_into_tuple(v: Vec3) -> (f32, f32, f32) {
|
|||
}
|
||||
|
||||
bench_func!(
|
||||
vec3_to_rgb,
|
||||
"vec3 to rgb",
|
||||
op => vec3_to_rgb_op,
|
||||
from => random_vec3
|
||||
);
|
||||
vec3_to_rgb,
|
||||
"vec3 to rgb",
|
||||
op => vec3_to_rgb_op,
|
||||
from => random_vec3
|
||||
);
|
||||
|
||||
bench_func!(
|
||||
vec3_to_array_accessors,
|
||||
"vec3 into array slow",
|
||||
op => vec3_accessors,
|
||||
from => random_vec3
|
||||
);
|
||||
vec3_to_array_accessors,
|
||||
"vec3 into array slow",
|
||||
op => vec3_accessors,
|
||||
from => random_vec3
|
||||
);
|
||||
|
||||
bench_func!(
|
||||
vec3_to_array_into,
|
||||
"vec3 into array fast",
|
||||
op => vec3_into_array,
|
||||
from => random_vec3
|
||||
);
|
||||
vec3_to_array_into,
|
||||
"vec3 into array fast",
|
||||
op => vec3_into_array,
|
||||
from => random_vec3
|
||||
);
|
||||
|
||||
bench_func!(
|
||||
vec3_to_tuple_into,
|
||||
"vec3 into tuple fast",
|
||||
op => vec3_into_tuple,
|
||||
from => random_vec3
|
||||
);
|
||||
vec3_to_tuple_into,
|
||||
"vec3 into tuple fast",
|
||||
op => vec3_into_tuple,
|
||||
from => random_vec3
|
||||
);
|
||||
|
||||
euler!(vec3_euler, "vec3 euler", ty => Vec3, storage => Vec3, zero => Vec3::zero(), rand => random_vec3);
|
||||
|
||||
|
|
|
@ -1,100 +1,114 @@
|
|||
use zerocopy::{FromBytes, AsBytes};
|
||||
use crate::{Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, Quat};
|
||||
use crate::{Mat2, Mat3, Mat4, Quat, Vec2, Vec3, Vec4};
|
||||
use zerocopy::{AsBytes, FromBytes};
|
||||
|
||||
unsafe impl AsBytes for Vec2 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Vec2 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Vec3 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Vec3 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Vec4 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Vec4 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Mat2 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Mat2 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Mat3 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Mat3 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Mat4 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Mat4 {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl AsBytes for Quat {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl FromBytes for Quat {
|
||||
fn only_derive_is_allowed_to_implement_this_trait()
|
||||
where
|
||||
Self: Sized {}
|
||||
|
||||
}
|
||||
Self: Sized,
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -345,9 +345,10 @@ fn test_vec2mask_eq() {
|
|||
|
||||
#[test]
|
||||
fn test_vec2mask_hash() {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
let a = Vec2Mask::new(true, false);
|
||||
let b = Vec2Mask::new(true, false);
|
||||
|
|
|
@ -449,9 +449,10 @@ fn test_vec3mask_eq() {
|
|||
|
||||
#[test]
|
||||
fn test_vec3mask_hash() {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
let a = Vec3Mask::new(true, false, true);
|
||||
let b = Vec3Mask::new(true, false, true);
|
||||
|
|
|
@ -494,9 +494,10 @@ fn test_vec4mask_eq() {
|
|||
|
||||
#[test]
|
||||
fn test_vec4mask_hash() {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::Hash;
|
||||
use std::hash::Hasher;
|
||||
use std::{
|
||||
collections::hash_map::DefaultHasher,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
|
||||
let a = Vec4Mask::new(true, false, true, false);
|
||||
let b = Vec4Mask::new(true, false, true, false);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use bevy_render::{
|
||||
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
||||
render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments},
|
||||
renderer::{RenderResources, RenderContext},
|
||||
renderer::{RenderContext, RenderResources},
|
||||
};
|
||||
|
||||
use crate::light::{Light, LightRaw};
|
||||
|
|
|
@ -4,10 +4,7 @@ use crate::{
|
|||
RenderPassDepthStencilAttachmentDescriptor, StoreOp, TextureAttachment,
|
||||
},
|
||||
render_graph::{
|
||||
nodes::{
|
||||
Camera2dNode, CameraNode, PassNode, WindowSwapChainNode,
|
||||
WindowTextureNode,
|
||||
},
|
||||
nodes::{Camera2dNode, CameraNode, PassNode, WindowSwapChainNode, WindowTextureNode},
|
||||
RenderGraph,
|
||||
},
|
||||
texture::{Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsage},
|
||||
|
@ -18,10 +15,10 @@ use bevy_window::{WindowCreated, WindowReference, WindowResized};
|
|||
use legion::prelude::Resources;
|
||||
|
||||
pub struct BaseRenderGraphConfig {
|
||||
add_2d_camera: bool,
|
||||
add_3d_camera: bool,
|
||||
add_main_pass: bool,
|
||||
connect_main_pass_to_swapchain: bool,
|
||||
pub add_2d_camera: bool,
|
||||
pub add_3d_camera: bool,
|
||||
pub add_main_pass: bool,
|
||||
pub connect_main_pass_to_swapchain: bool,
|
||||
}
|
||||
|
||||
pub mod node {
|
||||
|
@ -123,13 +120,12 @@ impl BaseRenderGraphBuilder for RenderGraph {
|
|||
if config.add_3d_camera {
|
||||
self.add_node_edge(node::CAMERA, node::MAIN_PASS).unwrap();
|
||||
}
|
||||
|
||||
|
||||
if config.add_2d_camera {
|
||||
self.add_node_edge(node::CAMERA2D, node::MAIN_PASS).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
self.add_node_named(
|
||||
node::PRIMARY_SWAP_CHAIN,
|
||||
WindowSwapChainNode::new(
|
||||
|
|
|
@ -154,7 +154,7 @@ where
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Batch, BatchKey, Batcher};
|
||||
use bevy_asset::{Handle, HandleUntyped, HandleId};
|
||||
use bevy_asset::{Handle, HandleId, HandleUntyped};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
struct A;
|
||||
|
|
|
@ -6,4 +6,4 @@ mod batcher;
|
|||
// pub use asset_batcher::*;
|
||||
// pub use asset_batcher2::*;
|
||||
pub use batch::*;
|
||||
pub use batcher::*;
|
||||
pub use batcher::*;
|
||||
|
|
|
@ -137,4 +137,4 @@ impl GetBytes for ColorSource {
|
|||
ColorSource::Texture(ref texture) => texture.get_bytes_ref(), // Texture is not a uniform
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,9 @@ impl DrawTarget for AssignedMeshesDrawTarget {
|
|||
pipeline_assignments.assignments.get(&pipeline_handle);
|
||||
let global_render_resource_assignments =
|
||||
resources.get::<RenderResourceAssignments>().unwrap();
|
||||
render_context.resources().setup_bind_groups(pipeline_descriptor, &global_render_resource_assignments);
|
||||
render_context
|
||||
.resources()
|
||||
.setup_bind_groups(pipeline_descriptor, &global_render_resource_assignments);
|
||||
if let Some(assigned_render_resource_assignments) = assigned_render_resource_assignments {
|
||||
for assignment_id in assigned_render_resource_assignments.iter() {
|
||||
let entity = entity_render_resource_assignments
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
VertexBufferDescriptor, VertexBufferDescriptors, VertexFormat,
|
||||
},
|
||||
render_resource::{BufferInfo, BufferUsage, RenderResourceAssignments},
|
||||
renderer::{RenderResources, RenderResourceContext},
|
||||
renderer::{RenderResourceContext, RenderResources},
|
||||
shader::AsUniforms,
|
||||
Renderable, Vertex,
|
||||
};
|
||||
|
@ -384,7 +384,7 @@ pub fn mesh_resource_provider_system(resources: &mut Resources) -> Box<dyn Sched
|
|||
.read_resource::<AssetStorage<Mesh>>()
|
||||
.with_query(<(Read<Handle<Mesh>>, Write<Renderable>)>::query())
|
||||
.build(
|
||||
move |_, world, (render_resource_context, meshes,/* asset_batchers*/), query| {
|
||||
move |_, world, (render_resource_context, meshes /* asset_batchers*/), query| {
|
||||
let render_resources = &*render_resource_context.context;
|
||||
// TODO: remove this once batches are pipeline specific and deprecate assigned_meshes draw target
|
||||
for (handle, mut renderable) in query.iter_mut(world) {
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
render_resource::{
|
||||
BufferInfo, RenderResourceAssignments, RenderResourceAssignmentsId, ResourceInfo,
|
||||
},
|
||||
renderer::{RenderResources, RenderResourceContext},
|
||||
renderer::{RenderResourceContext, RenderResources},
|
||||
shader::{Shader, ShaderSource},
|
||||
Renderable,
|
||||
};
|
||||
|
@ -289,8 +289,7 @@ pub fn update_shader_assignments(world: &mut World, resources: &Resources) {
|
|||
let mut pipeline_compiler = resources.get_mut::<PipelineCompiler>().unwrap();
|
||||
let mut shader_storage = resources.get_mut::<AssetStorage<Shader>>().unwrap();
|
||||
let vertex_buffer_descriptors = resources.get::<VertexBufferDescriptors>().unwrap();
|
||||
let render_resources =
|
||||
resources.get::<RenderResources>().unwrap();
|
||||
let render_resources = resources.get::<RenderResources>().unwrap();
|
||||
let mut pipeline_descriptor_storage = resources
|
||||
.get_mut::<AssetStorage<PipelineDescriptor>>()
|
||||
.unwrap();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{render_resource::RenderResource, renderer::RenderContext, texture::Extent3d};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Command {
|
||||
CopyBufferToBuffer {
|
||||
source_buffer: RenderResource,
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
camera::{ActiveCamera2d, Camera},
|
||||
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
||||
render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments},
|
||||
renderer::{RenderResources, RenderContext},
|
||||
renderer::{RenderContext, RenderResources},
|
||||
};
|
||||
|
||||
use legion::prelude::*;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
||||
render_resource::{resource_name, BufferInfo, BufferUsage, RenderResourceAssignments},
|
||||
renderer::{RenderResources, RenderContext},
|
||||
renderer::{RenderContext, RenderResources},
|
||||
ActiveCamera, Camera,
|
||||
};
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl SystemNode for CameraNode {
|
|||
let mut camera_buffer = None;
|
||||
let mut window_resized_event_reader = resources.get_event_reader::<WindowResized>();
|
||||
let mut command_queue = self.command_queue.clone();
|
||||
|
||||
|
||||
SystemBuilder::new("camera_resource_provider")
|
||||
.read_resource::<RenderResources>()
|
||||
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
BufferArrayInfo, BufferInfo, BufferUsage, RenderResource, RenderResourceAssignments,
|
||||
RenderResourceAssignmentsId, ResourceInfo,
|
||||
},
|
||||
renderer::{RenderResources, RenderContext, RenderResourceContext},
|
||||
renderer::{RenderContext, RenderResourceContext, RenderResources},
|
||||
shader::{AsUniforms, FieldBindType},
|
||||
texture, Renderable,
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
mod headless_render_resource_context;
|
||||
mod render_context;
|
||||
mod render_resource_context;
|
||||
mod headless_render_resource_context;
|
||||
|
||||
pub use headless_render_resource_context::*;
|
||||
pub use render_context::*;
|
||||
pub use render_resource_context::*;
|
||||
pub use headless_render_resource_context::*;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use crate::{
|
||||
render_resource::{BufferInfo, RenderResource, ResourceInfo, RenderResourceAssignments, RenderResourceSetId},
|
||||
pipeline::{BindGroupDescriptor, PipelineDescriptor},
|
||||
render_resource::{
|
||||
BufferInfo, RenderResource, RenderResourceAssignments, RenderResourceSetId, ResourceInfo,
|
||||
},
|
||||
shader::Shader,
|
||||
texture::{SamplerDescriptor, TextureDescriptor}, pipeline::{BindGroupDescriptor, PipelineDescriptor},
|
||||
texture::{SamplerDescriptor, TextureDescriptor},
|
||||
};
|
||||
use bevy_asset::{AssetStorage, Handle, HandleUntyped};
|
||||
use bevy_window::{Window, WindowId};
|
||||
|
@ -103,4 +106,4 @@ impl dyn RenderResourceContext {
|
|||
}
|
||||
}
|
||||
|
||||
impl_downcast!(RenderResourceContext);
|
||||
impl_downcast!(RenderResourceContext);
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use super::ShaderLayout;
|
||||
use bevy_asset::Handle;
|
||||
use std::marker::Copy;
|
||||
use glsl_to_spirv::compile;
|
||||
use std::io::Read;
|
||||
use std::{io::Read, marker::Copy};
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ShaderStage {
|
||||
Vertex,
|
||||
|
@ -31,7 +30,9 @@ pub fn glsl_to_spirv(
|
|||
|
||||
let mut spv_words = Vec::new();
|
||||
for bytes4 in spv_bytes.chunks(4) {
|
||||
spv_words.push(u32::from_le_bytes([bytes4[0], bytes4[1], bytes4[2], bytes4[3]]));
|
||||
spv_words.push(u32::from_le_bytes([
|
||||
bytes4[0], bytes4[1], bytes4[2], bytes4[3],
|
||||
]));
|
||||
}
|
||||
spv_words
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct Texture {
|
|||
impl Texture {
|
||||
pub fn aspect(&self) -> f32 {
|
||||
self.height as f32 / self.width as f32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Asset<TextureType> for Texture {
|
||||
|
|
|
@ -52,4 +52,4 @@ impl From<Handle<Texture>> for ColorMaterial {
|
|||
fn from(texture: Handle<Texture>) -> Self {
|
||||
ColorMaterial::texture(texture)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::Node;
|
||||
use crate::{render::UI_PIPELINE_HANDLE, ColorMaterial, Rect, QUAD_HANDLE, sprite::Sprite};
|
||||
use crate::{render::UI_PIPELINE_HANDLE, sprite::Sprite, ColorMaterial, Rect, QUAD_HANDLE};
|
||||
use bevy_asset::Handle;
|
||||
use bevy_derive::EntityArchetype;
|
||||
use bevy_render::{mesh::Mesh, Renderable};
|
||||
|
@ -9,7 +9,7 @@ use bevy_render::{mesh::Mesh, Renderable};
|
|||
pub struct UiEntity {
|
||||
pub node: Node,
|
||||
pub rect: Rect,
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub material: Handle<ColorMaterial>,
|
||||
pub renderable: Renderable,
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ impl Default for UiEntity {
|
|||
pub struct SpriteEntity {
|
||||
pub sprite: Sprite,
|
||||
pub rect: Rect,
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub mesh: Handle<Mesh>, // TODO: maybe abstract this out
|
||||
pub material: Handle<ColorMaterial>,
|
||||
pub renderable: Renderable,
|
||||
}
|
||||
|
@ -52,4 +52,4 @@ impl Default for SpriteEntity {
|
|||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,13 @@ impl Node {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, rect: &mut Rect, parent_dimensions: Vec2, parent_position: Vec2, z_index: f32) {
|
||||
pub fn update(
|
||||
&mut self,
|
||||
rect: &mut Rect,
|
||||
parent_dimensions: Vec2,
|
||||
parent_position: Vec2,
|
||||
z_index: f32,
|
||||
) {
|
||||
let (rect_x, rect_width) = Self::compute_dimension_properties(
|
||||
self.position.x(),
|
||||
self.margins.left,
|
||||
|
|
|
@ -12,6 +12,10 @@ pub struct Rect {
|
|||
}
|
||||
|
||||
impl GetBytes for Rect {
|
||||
fn get_bytes(&self) -> Vec<u8> { self.as_bytes().to_vec() }
|
||||
fn get_bytes_ref(&self) -> Option<&[u8]> { Some(self.as_bytes()) }
|
||||
fn get_bytes(&self) -> Vec<u8> {
|
||||
self.as_bytes().to_vec()
|
||||
}
|
||||
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
||||
Some(self.as_bytes())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ pub struct Sprite {
|
|||
|
||||
impl Default for Sprite {
|
||||
fn default() -> Self {
|
||||
Sprite {
|
||||
scale: 1.0
|
||||
}
|
||||
Sprite { scale: 1.0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
mod wgpu_resource_diagnostics_plugin;
|
||||
pub use wgpu_resource_diagnostics_plugin::WgpuResourceDiagnosticsPlugin;
|
||||
pub use wgpu_resource_diagnostics_plugin::WgpuResourceDiagnosticsPlugin;
|
||||
|
|
|
@ -55,11 +55,7 @@ impl WgpuResourceDiagnosticsPlugin {
|
|||
10,
|
||||
));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::SWAP_CHAINS,
|
||||
"swap_chains",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::SWAP_CHAINS, "swap_chains", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::SWAP_CHAIN_OUTPUTS,
|
||||
|
@ -67,35 +63,15 @@ impl WgpuResourceDiagnosticsPlugin {
|
|||
10,
|
||||
));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::BUFFERS,
|
||||
"buffers",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::BUFFERS, "buffers", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::TEXTURES,
|
||||
"textures",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::TEXTURES, "textures", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::TEXTURE_VIEWS,
|
||||
"texture_views",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::TEXTURE_VIEWS, "texture_views", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::SAMPLERS,
|
||||
"samplers",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::SAMPLERS, "samplers", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::BIND_GROUPS,
|
||||
"bind_groups",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::BIND_GROUPS, "bind_groups", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::BIND_GROUP_LAYOUTS,
|
||||
|
@ -103,11 +79,7 @@ impl WgpuResourceDiagnosticsPlugin {
|
|||
10,
|
||||
));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::SHADER_MODULES,
|
||||
"shader_modules",
|
||||
10,
|
||||
));
|
||||
diagnostics.add(Diagnostic::new(Self::SHADER_MODULES, "shader_modules", 10));
|
||||
|
||||
diagnostics.add(Diagnostic::new(
|
||||
Self::RENDER_PIPELINES,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
pub mod renderer;
|
||||
pub mod diagnostic;
|
||||
pub mod renderer;
|
||||
mod wgpu_render_pass;
|
||||
mod wgpu_renderer;
|
||||
mod wgpu_resources;
|
||||
|
@ -34,9 +34,9 @@ pub fn wgpu_render_system(resources: &mut Resources) -> impl FnMut(&mut World, &
|
|||
window_created_event.get_reader(),
|
||||
))
|
||||
};
|
||||
resources.insert(RenderResources::new(
|
||||
WgpuRenderResourceContext::new(wgpu_renderer.device.clone()),
|
||||
));
|
||||
resources.insert(RenderResources::new(WgpuRenderResourceContext::new(
|
||||
wgpu_renderer.device.clone(),
|
||||
)));
|
||||
move |world, resources| {
|
||||
wgpu_renderer.update(world, resources);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
extern crate cmake;
|
||||
extern crate sha2;
|
||||
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use std::{env, fs, path::Path, process::Command};
|
||||
|
||||
use sha2::{Sha256, Digest};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=build/glslangValidator.exe");
|
||||
|
@ -15,7 +12,7 @@ fn main() {
|
|||
let out_file = Path::new(&env::var("OUT_DIR").unwrap()).join("glslang_validator");
|
||||
|
||||
let path = if target.contains("windows") {
|
||||
const SHA256SUM: &'static str =
|
||||
const SHA256SUM: &'static str =
|
||||
"90b377479fb137f4ac69460d5f5cdc54cd23bace5eb6e6812516fdfa693b25cf";
|
||||
let path = Path::new("build/glslangValidator.exe").to_owned();
|
||||
let content = fs::read(&path).expect("failed to open executable");
|
||||
|
@ -25,7 +22,6 @@ fn main() {
|
|||
let sha256sum = format!("{:x}", result);
|
||||
assert_eq!(sha256sum, SHA256SUM, "glslangValidator.exe checksum failed");
|
||||
path
|
||||
|
||||
} else {
|
||||
// Try to initialize submodules. Don't care if it fails, since this code also runs for
|
||||
// the crates.io package.
|
||||
|
|
|
@ -9,20 +9,23 @@
|
|||
|
||||
extern crate tempfile;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::process::Command;
|
||||
use std::{fs::File, io::Write, process::Command};
|
||||
|
||||
pub type SpirvOutput = File;
|
||||
|
||||
pub fn compile(code: &str, ty: ShaderType, shader_defs: Option<&[String]>) -> Result<SpirvOutput, String> {
|
||||
pub fn compile(
|
||||
code: &str,
|
||||
ty: ShaderType,
|
||||
shader_defs: Option<&[String]>,
|
||||
) -> Result<SpirvOutput, String> {
|
||||
compile_inner(Some((code, ty)), shader_defs)
|
||||
}
|
||||
|
||||
// Eventually the API will look like this, with an iterator for multiple shader stages.
|
||||
// However for the moment GLSLang doesn't like that, so we only pass one shader at a time.
|
||||
fn compile_inner<'a, I>(shaders: I, shader_defs: Option<&[String]>) -> Result<SpirvOutput, String>
|
||||
where I: IntoIterator<Item = (&'a str, ShaderType)>
|
||||
where
|
||||
I: IntoIterator<Item = (&'a str, ShaderType)>,
|
||||
{
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let output_file = temp_dir.path().join("compilation_output.spv");
|
||||
|
|
|
@ -9,10 +9,7 @@ fn main() {
|
|||
|
||||
fn setup(world: &mut World, resources: &mut Resources) {
|
||||
let mut texture_storage = resources.get_mut::<AssetStorage<Texture>>().unwrap();
|
||||
let texture_path = concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/branding/icon.png"
|
||||
);
|
||||
let texture_path = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/branding/icon.png");
|
||||
let texture = Texture::load(TextureType::Png(texture_path.to_string()));
|
||||
let texture_handle = texture_storage.add(texture);
|
||||
let mut color_materials = resources.get_mut::<AssetStorage<ColorMaterial>>().unwrap();
|
||||
|
|
|
@ -329,7 +329,7 @@ fn main() {
|
|||
// However we can manually specify the stage if we want to. The following is equivalent to add_system(score_system.system())
|
||||
.add_system_to_stage(stage::UPDATE, score_system.system())
|
||||
// We can also create new stages. Here is what our games stage order will look like:
|
||||
// "before_round": new_player_system, new_round_system
|
||||
// "before_round": new_player_system, new_round_system
|
||||
// "update": print_message_system, score_system
|
||||
// "after_round": score_check_system, game_over_system
|
||||
.add_stage_before(stage::UPDATE, "before_round")
|
||||
|
@ -341,7 +341,6 @@ fn main() {
|
|||
// score_check_system will run before game_over_system because score_check_system modifies GameState and game_over_system
|
||||
// reads GameState. This works, but it's a bit confusing. In practice, it would be clearer to create a new stage that runs
|
||||
// before "after_round"
|
||||
|
||||
// This call to run() starts the app we just built!
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use bevy::{
|
||||
app::schedule_runner::ScheduleRunnerPlugin,
|
||||
prelude::*,
|
||||
};
|
||||
use bevy::{app::schedule_runner::ScheduleRunnerPlugin, prelude::*};
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
|
|
|
@ -8,7 +8,7 @@ impl AddDefaultPlugins for AppBuilder {
|
|||
fn add_default_plugins(&mut self) -> &mut Self {
|
||||
#[cfg(feature = "core")]
|
||||
self.add_plugin(bevy_core::CorePlugin::default());
|
||||
|
||||
|
||||
#[cfg(feature = "diagnostic")]
|
||||
self.add_plugin(bevy_diagnostic::DiagnosticsPlugin::default());
|
||||
|
||||
|
|
|
@ -32,13 +32,13 @@ pub use crate::render::{
|
|||
#[cfg(feature = "transform")]
|
||||
pub use crate::transform::prelude::*;
|
||||
#[cfg(feature = "ui")]
|
||||
pub use crate::ui::{entity::*, Anchors, Rect, Sprite, Margins, Node, ColorMaterial};
|
||||
pub use crate::ui::{entity::*, Anchors, ColorMaterial, Margins, Node, Rect, Sprite};
|
||||
#[cfg(feature = "window")]
|
||||
pub use crate::window::{Window, WindowDescriptor, WindowPlugin, Windows};
|
||||
pub use crate::{
|
||||
app::{
|
||||
stage, App, AppBuilder, AppPlugin, EntityArchetype, EventReader, Events, GetEventReader,
|
||||
System, schedule_runner::ScheduleRunnerPlugin
|
||||
schedule_runner::ScheduleRunnerPlugin, stage, App, AppBuilder, AppPlugin, EntityArchetype,
|
||||
EventReader, Events, GetEventReader, System,
|
||||
},
|
||||
math::{self, Mat3, Mat4, Quat, Vec2, Vec3, Vec4},
|
||||
AddDefaultPlugins,
|
||||
|
|
Loading…
Reference in a new issue