diff --git a/examples/custom_shader.rs b/examples/custom_shader.rs index 1ab877efd1..0e47b106a6 100644 --- a/examples/custom_shader.rs +++ b/examples/custom_shader.rs @@ -87,10 +87,10 @@ fn setup(world: &mut World) { world .build() // red cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle, translation: Translation::new(0.0, 0.0, 1.0), - ..NewMeshEntity::default() + ..MeshEntity::default() }) // camera .add_archetype(CameraEntity { diff --git a/examples/entity_builder_comparison.rs b/examples/entity_builder_comparison.rs index f58522868e..fd2f5e88fe 100644 --- a/examples/entity_builder_comparison.rs +++ b/examples/entity_builder_comparison.rs @@ -18,7 +18,10 @@ fn create_entities_insert_vec( (), vec![( plane_handle.clone(), - Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), + StandardMaterial { + albedo: math::vec4(0.1, 0.2, 0.1, 1.0), + everything_is_red: false, + }, LocalToWorld::identity(), Translation::new(0.0, 0.0, 0.0), )], @@ -29,7 +32,10 @@ fn create_entities_insert_vec( (), vec![( cube_handle, - Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, + }, LocalToWorld::identity(), Translation::new(0.0, 0.0, 1.0), )], @@ -39,17 +45,7 @@ fn create_entities_insert_vec( world.insert( (), vec![( - Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, + Light::default(), LocalToWorld::identity(), Translation::new(4.0, -4.0, 5.0), Rotation::from_euler_angles(0.0, 0.0, 0.0), @@ -87,28 +83,24 @@ fn create_entities_builder_add_component( // plane .build_entity() .add(plane_handle.clone()) - .add(Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0)))) + .add(StandardMaterial { + albedo: math::vec4(0.1, 0.2, 0.1, 1.0), + everything_is_red: false, + }) .add(LocalToWorld::identity()) .add(Translation::new(0.0, 0.0, 0.0)) // cube .build_entity() .add(cube_handle) - .add(Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0)))) + .add(StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, + }) .add(LocalToWorld::identity()) .add(Translation::new(0.0, 0.0, 1.0)) // light .build_entity() - .add(Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }) + .add(Light::default()) .add(LocalToWorld::identity()) .add(Translation::new(4.0, -4.0, 5.0)) .add(Rotation::from_euler_angles(0.0, 0.0, 0.0)) @@ -139,33 +131,25 @@ fn create_entities_builder_archetype( // plane .add_archetype(MeshEntity { mesh: plane_handle.clone(), - material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), - local_to_world: LocalToWorld::identity(), - translation: Translation::new(0.0, 0.0, 0.0), + material: StandardMaterial { + albedo: math::vec4(0.1, 0.2, 0.1, 1.0), + everything_is_red: false + }, + ..Default::default() }) // cube .add_archetype(MeshEntity { mesh: cube_handle, - material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), - local_to_world: LocalToWorld::identity(), - translation: Translation::new(0.0, 0.0, 1.0), + material: StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false + }, + ..Default::default() }) // light .add_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(4.0, -4.0, 5.0), - rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + ..Default::default() }) // camera .add_archetype(CameraEntity { diff --git a/examples/instancing.rs b/examples/instancing.rs index b4b9778f73..5d10b5f494 100644 --- a/examples/instancing.rs +++ b/examples/instancing.rs @@ -41,18 +41,7 @@ fn setup(world: &mut World) { vec![ // lights ( - Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + Light::default(), LocalToWorld::identity(), Translation::new(4.0, -4.0, 5.0), Rotation::from_euler_angles(0.0, 0.0, 0.0), @@ -204,9 +193,10 @@ fn create_person(world: &mut World, mesh_handle: Handle, translation: Tran value: math::vec3(0.0, 0.0, 0.0), }, Instanced, - Material::new(Albedo::Color( - math::vec4(0.5, 0.3, 0.3, 1.0) * random::(), - )), + StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0) * random::(), + everything_is_red: false, + }, mesh_handle, LocalToWorld::identity(), translation, diff --git a/examples/parenting.rs b/examples/parenting.rs index 6da5ab5b28..7b12e847d2 100644 --- a/examples/parenting.rs +++ b/examples/parenting.rs @@ -35,7 +35,10 @@ fn setup(world: &mut World) { (), vec![( plane_handle.clone(), - Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), + StandardMaterial { + albedo: math::vec4(0.1, 0.2, 0.1, 1.0), + everything_is_red: false, + }, LocalToWorld::identity(), Translation::new(0.0, 0.0, -5.0), )], @@ -47,7 +50,10 @@ fn setup(world: &mut World) { (), vec![( cube_handle.clone(), - Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, + }, LocalToWorld::identity(), Translation::new(0.0, 0.0, 1.0), Rotation::from_euler_angles(0.0, 0.0, 0.0), @@ -62,7 +68,10 @@ fn setup(world: &mut World) { (), vec![( cube_handle, - Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + StandardMaterial { + albedo: math::vec4(0.5, 0.3, 0.3, 1.0), + everything_is_red: false, + }, LocalToWorld::identity(), Translation::new(0.0, 0.0, 3.0), Parent(parent_cube), @@ -74,18 +83,7 @@ fn setup(world: &mut World) { world.insert( (), vec![( - Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), + Light::default(), LocalToWorld::identity(), Translation::new(4.0, -4.0, 5.0), Rotation::from_euler_angles(0.0, 0.0, 0.0), diff --git a/examples/plugin_loading/example_plugin/src/lib.rs b/examples/plugin_loading/example_plugin/src/lib.rs index ce5c5bb3c0..4df9d2d3f4 100644 --- a/examples/plugin_loading/example_plugin/src/lib.rs +++ b/examples/plugin_loading/example_plugin/src/lib.rs @@ -26,14 +26,14 @@ pub fn setup(world: &mut World) { world.build() // plane - .add_archetype(MeshEntity { + .add_archetype(NewMeshEntity { mesh: plane_handle.clone(), material: Material::new(Albedo::Color(math::vec4(0.1, 0.2, 0.1, 1.0))), local_to_world: LocalToWorld::identity(), translation: Translation::new(0.0, 0.0, 0.0), }) // cube - .add_archetype(MeshEntity { + .add_archetype(NewMeshEntity { mesh: cube_handle, material: Material::new(Albedo::Color(math::vec4(0.5, 0.3, 0.3, 1.0))), local_to_world: LocalToWorld::identity(), diff --git a/examples/simple.rs b/examples/simple.rs index 7ef4c5c72d..d02e184fdf 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -16,7 +16,7 @@ fn setup(world: &mut World) { world .build() // plane - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: plane_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0), @@ -25,7 +25,7 @@ fn setup(world: &mut World) { ..Default::default() }) // tan cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.4, 0.3, 1.0), @@ -35,7 +35,7 @@ fn setup(world: &mut World) { ..Default::default() }) // red cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.4, 0.3, 1.0), @@ -46,20 +46,9 @@ fn setup(world: &mut World) { }) // light .add_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.8, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(4.0, -4.0, 5.0), rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + ..Default::default() }) // camera .add_archetype(CameraEntity { diff --git a/examples/spawner.rs b/examples/spawner.rs index 66bfd0a604..93c3bfd7b7 100644 --- a/examples/spawner.rs +++ b/examples/spawner.rs @@ -70,7 +70,7 @@ fn setup(world: &mut World) { let mut builder = world .build() // plane - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: plane_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.1, 0.2, 0.1, 1.0), @@ -79,7 +79,7 @@ fn setup(world: &mut World) { ..Default::default() }) // cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(1.0, 1.0, 1.0, 1.0), @@ -88,7 +88,7 @@ fn setup(world: &mut World) { translation: Translation::new(0.0, 0.0, 1.0), ..Default::default() }) - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.0, 1.0, 0.0, 1.0), @@ -99,20 +99,8 @@ fn setup(world: &mut World) { }) // light .add_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(4.0, -4.0, 5.0), - rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + ..Default::default() }) // camera .add_archetype(CameraEntity { @@ -132,7 +120,7 @@ fn setup(world: &mut World) { let mut rng = StdRng::from_entropy(); for _ in 0..10000 { - builder = builder.add_archetype(NewMeshEntity { + builder = builder.add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4( diff --git a/examples/texture.rs b/examples/texture.rs index e32930f3aa..a2ea1e60cd 100644 --- a/examples/texture.rs +++ b/examples/texture.rs @@ -19,7 +19,7 @@ fn setup(world: &mut World) { world .build() // cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0), @@ -30,20 +30,8 @@ fn setup(world: &mut World) { }) // light .add_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(4.0, -4.0, 5.0), - rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + ..Default::default() }) // camera .add_archetype(CameraEntity { diff --git a/examples/ui.rs b/examples/ui.rs index 1ef8149d8a..69d175553c 100644 --- a/examples/ui.rs +++ b/examples/ui.rs @@ -14,7 +14,7 @@ fn setup(world: &mut World) { world .build() // cube - .add_archetype(NewMeshEntity { + .add_archetype(MeshEntity { mesh: cube_handle.clone(), material: StandardMaterial { albedo: math::vec4(0.5, 0.3, 0.3, 1.0), @@ -25,20 +25,8 @@ fn setup(world: &mut World) { }) // light .add_archetype(LightEntity { - light: Light { - color: wgpu::Color { - r: 0.8, - g: 0.8, - b: 0.5, - a: 1.0, - }, - fov: f32::to_radians(60.0), - depth: 0.1..50.0, - target_view: None, - }, - local_to_world: LocalToWorld::identity(), translation: Translation::new(4.0, -4.0, 5.0), - rotation: Rotation::from_euler_angles(0.0, 0.0, 0.0), + ..Default::default() }) // 3d camera .add_archetype(CameraEntity { diff --git a/src/ecs/default_archetypes.rs b/src/ecs/default_archetypes.rs index 2f64b26a63..22e6aaa3b7 100644 --- a/src/ecs/default_archetypes.rs +++ b/src/ecs/default_archetypes.rs @@ -1,28 +1,19 @@ use crate::{ prelude::*, - render::render_graph::{Renderable, ShaderUniforms, StandardMaterial}, + render::render_graph::{Renderable, StandardMaterial}, }; use bevy_derive::EntityArchetype; -#[derive(EntityArchetype)] +#[derive(EntityArchetype, Default)] pub struct MeshEntity { pub mesh: Handle, - pub material: Material, + pub material: StandardMaterial, + pub renderable: Renderable, pub local_to_world: LocalToWorld, pub translation: Translation, } #[derive(EntityArchetype, Default)] -pub struct NewMeshEntity { - pub mesh: Handle, - pub material: StandardMaterial, - pub renderable: Renderable, - pub shader_uniforms: ShaderUniforms, - pub local_to_world: LocalToWorld, - pub translation: Translation, -} - -#[derive(EntityArchetype)] pub struct LightEntity { pub light: Light, pub local_to_world: LocalToWorld, diff --git a/src/prelude.rs b/src/prelude.rs index ee959f06a7..7742bf1f69 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,7 +5,7 @@ pub use crate::{ ecs, ecs::{default_archetypes::*, EntityArchetype, WorldBuilder, WorldBuilderSource}, render::{ - ActiveCamera, ActiveCamera2d, Albedo, Camera, CameraType, Instanced, Light, Material, + ActiveCamera, ActiveCamera2d, Camera, CameraType, Instanced, Light, render_graph::StandardMaterial, }, ui::{Anchors, Margins, Node}, diff --git a/src/render/instancing.rs b/src/render/instancing.rs deleted file mode 100644 index f9222bb496..0000000000 --- a/src/render/instancing.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub struct InstanceBufferInfo { - pub buffer: wgpu::Buffer, - pub instance_count: usize, - pub mesh_id: usize, -} diff --git a/src/render/light.rs b/src/render/light.rs index 421a7ace95..b7a9d4b058 100644 --- a/src/render/light.rs +++ b/src/render/light.rs @@ -1,12 +1,21 @@ -use crate::{math, prelude::Translation, render::camera}; +use crate::{math, math::Vec4, prelude::Translation, render::camera}; use std::ops::Range; use zerocopy::{AsBytes, FromBytes}; pub struct Light { - pub color: wgpu::Color, + pub color: Vec4, pub fov: f32, pub depth: Range, - pub target_view: Option, +} + +impl Default for Light { + fn default() -> Self { + Light { + color: Vec4::new(1.0, 1.0, 1.0, 1.0), + depth: 0.1..50.0, + fov: f32::to_radians(60.0), + } + } } #[repr(C)] @@ -29,12 +38,7 @@ impl LightRaw { LightRaw { proj: proj.to_cols_array_2d(), pos: [x, y, z, 1.0], - color: [ - light.color.r as f32, - light.color.g as f32, - light.color.b as f32, - 1.0, - ], + color: light.color.into(), } } } diff --git a/src/render/material.rs b/src/render/material.rs deleted file mode 100644 index 61bf639da6..0000000000 --- a/src/render/material.rs +++ /dev/null @@ -1,49 +0,0 @@ -use crate::{ - asset::{Handle, Texture}, - math, -}; -use zerocopy::{AsBytes, FromBytes}; - -pub enum Albedo { - Color(math::Vec4), - Texture(Handle), -} - -pub struct Material { - pub albedo: Albedo, - pub bind_group: Option, - pub uniform_buf: Option, -} - -pub struct Instanced; - -impl Material { - pub fn new(albedo: Albedo) -> Self { - Material { - albedo, - bind_group: None, - uniform_buf: None, - } - } - - pub fn get_color(&self) -> math::Vec4 { - match self.albedo { - Albedo::Color(color) => color, - _ => math::vec4(1.0, 0.0, 1.0, 1.0), - } - } -} - -#[repr(C)] -#[derive(Clone, Copy, AsBytes, FromBytes)] -pub struct MaterialUniforms { - pub model: [[f32; 4]; 4], - pub color: [f32; 4], -} - -#[repr(C)] -#[derive(Clone, Copy, AsBytes, FromBytes)] -pub struct SimpleMaterialUniforms { - pub position: [f32; 3], - pub color: [f32; 4], -} diff --git a/src/render/mod.rs b/src/render/mod.rs index 4eecfd1173..eea4cf3242 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1,56 +1,15 @@ pub mod camera; -pub mod instancing; pub mod render_graph; pub mod shader; pub mod shader_reflect; mod light; -mod material; mod vertex; pub use camera::*; pub use light::*; -pub use material::*; pub use shader::*; -use std::mem; pub use vertex::Vertex; -pub struct UniformBuffer { - pub buffer: wgpu::Buffer, - pub size: u64, -} - -impl UniformBuffer { - pub fn get_binding_resource<'a>(&'a self) -> wgpu::BindingResource<'a> { - wgpu::BindingResource::Buffer { - buffer: &self.buffer, - range: 0..self.size, - } - } -} - -pub fn get_vertex_buffer_descriptor<'a>() -> wgpu::VertexBufferDescriptor<'a> { - let vertex_size = mem::size_of::(); - wgpu::VertexBufferDescriptor { - stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, - attributes: &[ - wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Float4, - offset: 0, - shader_location: 0, - }, - wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Float4, - offset: 4 * 4, - shader_location: 1, - }, - wgpu::VertexAttributeDescriptor { - format: wgpu::VertexFormat::Float2, - offset: 8 * 4, - shader_location: 2, - }, - ], - } -} +pub struct Instanced; \ No newline at end of file diff --git a/src/render/render_graph/draw_targets/meshes_draw_target.rs b/src/render/render_graph/draw_targets/meshes_draw_target.rs index 174882d70c..9e53c5c7ce 100644 --- a/src/render/render_graph/draw_targets/meshes_draw_target.rs +++ b/src/render/render_graph/draw_targets/meshes_draw_target.rs @@ -2,7 +2,7 @@ use crate::{ asset::{AssetStorage, Handle, Mesh}, legion::prelude::*, render::{ - render_graph::{resource_name, RenderPass, Renderable, ShaderUniforms, PipelineDescriptor}, + render_graph::{resource_name, RenderPass, Renderable, PipelineDescriptor}, Instanced, }, }; @@ -13,9 +13,9 @@ pub fn meshes_draw_target(world: &World, render_pass: &mut dyn RenderPass, _pipe let mesh_storage = world.resources.get_mut::>().unwrap(); let mut current_mesh_id = None; let mut current_mesh_index_length = 0; - let mesh_query = <(Read, Read>, Read)>::query() + let mesh_query = <(Read>, Read)>::query() .filter(!component::()); - for (entity, (_shader_uniforms, mesh, renderable)) in mesh_query.iter_entities(world) { + for (entity, (mesh, renderable)) in mesh_query.iter_entities(world) { if !renderable.is_visible { continue; } diff --git a/src/render/render_graph/renderer.rs b/src/render/render_graph/renderer.rs index c884ff1501..cb9cf4b445 100644 --- a/src/render/render_graph/renderer.rs +++ b/src/render/render_graph/renderer.rs @@ -1,7 +1,7 @@ use crate::{ legion::prelude::*, render::render_graph::{ - resource::DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo, + DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo, TextureDescriptor, }, }; diff --git a/src/render/render_graph/resource.rs b/src/render/render_graph/resource.rs index ee09b348d1..2bf29d673e 100644 --- a/src/render/render_graph/resource.rs +++ b/src/render/render_graph/resource.rs @@ -1,6 +1,3 @@ -use legion::prelude::Entity; -use std::collections::HashMap; - pub enum ResourceInfo { BufferMapped { size: u64, @@ -18,24 +15,4 @@ pub enum ResourceInfo { mesh_id: usize, // pub layout: Option< }, -} - -pub struct DynamicUniformBufferInfo { - pub indices: HashMap, - pub offsets: HashMap, - pub capacity: u64, - pub count: u64, - pub size: u64, -} - -impl DynamicUniformBufferInfo { - pub fn new() -> Self { - DynamicUniformBufferInfo { - capacity: 0, - count: 0, - indices: HashMap::new(), - offsets: HashMap::new(), - size: 0, - } - } -} +} \ No newline at end of file diff --git a/src/render/render_graph/resource_providers/uniform_resource_provider.rs b/src/render/render_graph/resource_providers/uniform_resource_provider.rs index b7dafd6192..6efdf0d31b 100644 --- a/src/render/render_graph/resource_providers/uniform_resource_provider.rs +++ b/src/render/render_graph/resource_providers/uniform_resource_provider.rs @@ -1,6 +1,6 @@ use crate::{ render::render_graph::{ - resource::DynamicUniformBufferInfo, AsUniforms, Renderable, Renderer, ResourceProvider, + DynamicUniformBufferInfo, AsUniforms, Renderable, Renderer, ResourceProvider, }, }; use legion::prelude::*; @@ -36,7 +36,6 @@ where fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) { let query = <(Read, Read)>::query(); - // retrieve all uniforms buffers that aren't aleady set. these are "dynamic" uniforms, which are set by the user in ShaderUniforms // TODO: this breaks down in multiple ways: // (SOLVED 1) resource_info will be set after the first run so this won't update. // (2) if we create new buffers, the old bind groups will be invalid diff --git a/src/render/render_graph/uniform.rs b/src/render/render_graph/uniform.rs index 3755b8fdad..78539065c3 100644 --- a/src/render/render_graph/uniform.rs +++ b/src/render/render_graph/uniform.rs @@ -1,12 +1,9 @@ use crate::{ - legion::{ - borrow::RefMap, - prelude::{Entity, World}, - }, math::Vec4, render::render_graph::{BindType, UniformPropertyType}, }; -use legion::storage::Component; +use legion::prelude::Entity; +use std::collections::HashMap; use zerocopy::AsBytes; pub trait GetBytes { @@ -70,79 +67,22 @@ pub struct UniformInfo<'a> { pub bind_type: BindType, } -pub fn uniform_selector(entity: Entity, world: &World) -> Option> -where - T: AsUniforms + Component, -{ - world - .get_component::(entity) - .map(|c| c.map_into(|s| s as &dyn AsUniforms)) +pub struct DynamicUniformBufferInfo { + pub indices: HashMap, + pub offsets: HashMap, + pub capacity: u64, + pub count: u64, + pub size: u64, } -// TODO: Remove these - -pub type ShaderUniformSelector = fn(Entity, &World) -> Option>; - -#[derive(Default)] -pub struct ShaderUniforms { - // used for distinguishing - pub uniform_selectors: Vec, -} - -impl ShaderUniforms { +impl DynamicUniformBufferInfo { pub fn new() -> Self { - ShaderUniforms { - uniform_selectors: Vec::new(), + DynamicUniformBufferInfo { + capacity: 0, + count: 0, + indices: HashMap::new(), + offsets: HashMap::new(), + size: 0, } } - - pub fn add(&mut self, selector: ShaderUniformSelector) { - self.uniform_selectors.push(selector); - } - - pub fn get_uniform_info<'a>( - &'a self, - world: &'a World, - entity: Entity, - uniform_name: &str, - ) -> Option<&'a UniformInfo> { - for uniform_selector in self.uniform_selectors.iter().rev() { - let uniforms = uniform_selector(entity, world).unwrap_or_else(|| { - panic!( - "ShaderUniform selector points to a missing component. Uniform: {}", - uniform_name - ) - }); - - let info = uniforms.get_uniform_info(uniform_name); - if let Some(_) = info { - return info; - } - } - - None - } - - pub fn get_uniform_bytes<'a>( - &'a self, - world: &'a World, - entity: Entity, - uniform_name: &str, - ) -> Option> { - for uniform_selector in self.uniform_selectors.iter().rev() { - let uniforms = uniform_selector(entity, world).unwrap_or_else(|| { - panic!( - "ShaderUniform selector points to a missing component. Uniform: {}", - uniform_name - ) - }); - - let bytes = uniforms.get_uniform_bytes(uniform_name); - if let Some(_) = bytes { - return bytes; - } - } - - None - } }