mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
reorganize
This commit is contained in:
parent
88ecc9ed43
commit
f68909ac00
12 changed files with 97 additions and 81 deletions
|
@ -4,7 +4,7 @@ use crate::{
|
|||
core::Time,
|
||||
legion::prelude::{Runnable, Schedulable, Schedule, Universe, World},
|
||||
render::render_graph_2,
|
||||
render::render_graph_2::{pipelines::*, passes::*, wgpu_renderer::WgpuRenderer, resource_providers::*, UniformResourceProvider, StandardMaterial},
|
||||
render::render_graph_2::{pipelines::*, passes::*, renderers::wgpu_renderer::WgpuRenderer, resource_providers::*, UniformResourceProvider, StandardMaterial},
|
||||
render::{passes::*, *},
|
||||
plugin::load_plugin,
|
||||
ui,
|
||||
|
|
|
@ -2,13 +2,11 @@ use crate::{
|
|||
asset::{AssetStorage, Handle, Mesh},
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
render_graph_2::{RenderPass, ShaderUniforms},
|
||||
render_graph_2::{RenderPass, ShaderUniforms, resource_name},
|
||||
Instanced,
|
||||
},
|
||||
};
|
||||
|
||||
use super::resource_name;
|
||||
use super::ResourceInfo;
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
// A set of draw calls. ex: get + draw meshes, get + draw instanced meshes, draw ui meshes, etc
|
||||
|
@ -16,8 +14,6 @@ use zerocopy::AsBytes;
|
|||
// TODO: consider swapping out dyn RenderPass for explicit WgpuRenderPass type to avoid dynamic dispatch
|
||||
pub type DrawTarget = fn(world: &World, render_pass: &mut dyn RenderPass);
|
||||
|
||||
const MESH_VERTEX_BUFFER_NAME: &str = "TempMeshVertexBuffer";
|
||||
const MESH_INDEX_BUFFER_NAME: &str = "TempMeshIndexBuffer";
|
||||
pub fn mesh_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
|
||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
let mut current_mesh_id = None;
|
||||
|
@ -34,19 +30,19 @@ pub fn mesh_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
|
|||
if let Some(mesh_asset) = mesh_storage.get(mesh.id) {
|
||||
let renderer = render_pass.get_renderer();
|
||||
renderer.create_buffer_with_data(
|
||||
MESH_VERTEX_BUFFER_NAME,
|
||||
resource_name::buffer::TEMP_MESH_VERTEX_BUFFER_NAME,
|
||||
mesh_asset.vertices.as_bytes(),
|
||||
wgpu::BufferUsage::VERTEX,
|
||||
);
|
||||
renderer.create_buffer_with_data(
|
||||
MESH_INDEX_BUFFER_NAME,
|
||||
resource_name::buffer::TEMP_MESH_INDEX_BUFFER_NAME,
|
||||
mesh_asset.indices.as_bytes(),
|
||||
wgpu::BufferUsage::INDEX,
|
||||
);
|
||||
|
||||
// TODO: Verify buffer format matches render pass
|
||||
render_pass.set_index_buffer(MESH_INDEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(0, MESH_VERTEX_BUFFER_NAME, 0);
|
||||
render_pass.set_index_buffer(resource_name::buffer::TEMP_MESH_INDEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(0, resource_name::buffer::TEMP_MESH_VERTEX_BUFFER_NAME, 0);
|
||||
current_mesh_id = Some(mesh.id);
|
||||
current_mesh_index_length = mesh_asset.indices.len() as u32;
|
||||
};
|
||||
|
@ -59,49 +55,6 @@ pub fn mesh_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
|
|||
|
||||
// cleanup buffers
|
||||
let renderer = render_pass.get_renderer();
|
||||
renderer.remove_buffer(MESH_VERTEX_BUFFER_NAME);
|
||||
renderer.remove_buffer(MESH_INDEX_BUFFER_NAME);
|
||||
}
|
||||
|
||||
pub fn ui_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
|
||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
// NOTE: this is ugly and borrowing is stupid
|
||||
let result = {
|
||||
let renderer = render_pass.get_renderer();
|
||||
let result = if let Some(ResourceInfo::InstanceBuffer { count, mesh_id, .. }) =
|
||||
renderer.get_resource_info(resource_name::buffer::UI_INSTANCES)
|
||||
{
|
||||
Some((*count, *mesh_id))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some((instance_count, mesh_id)) = result {
|
||||
if let Some(mesh_asset) = mesh_storage.get(mesh_id) {
|
||||
renderer.create_buffer_with_data(
|
||||
MESH_VERTEX_BUFFER_NAME,
|
||||
mesh_asset.vertices.as_bytes(),
|
||||
wgpu::BufferUsage::VERTEX,
|
||||
);
|
||||
renderer.create_buffer_with_data(
|
||||
MESH_INDEX_BUFFER_NAME,
|
||||
mesh_asset.indices.as_bytes(),
|
||||
wgpu::BufferUsage::INDEX,
|
||||
);
|
||||
Some((instance_count, mesh_asset.indices.len()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
};
|
||||
if let Some((instance_count, indices_length)) = result {
|
||||
render_pass.setup_bind_groups(None);
|
||||
render_pass.set_index_buffer(MESH_INDEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(0, MESH_VERTEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(1, resource_name::buffer::UI_INSTANCES, 0);
|
||||
render_pass.draw_indexed(0..indices_length as u32, 0, 0..(instance_count as u32));
|
||||
}
|
||||
}
|
||||
renderer.remove_buffer(resource_name::buffer::TEMP_MESH_VERTEX_BUFFER_NAME);
|
||||
renderer.remove_buffer(resource_name::buffer::TEMP_MESH_INDEX_BUFFER_NAME);
|
||||
}
|
3
src/render/render_graph_2/draw_targets/mod.rs
Normal file
3
src/render/render_graph_2/draw_targets/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod ui_draw_target;
|
||||
|
||||
pub use ui_draw_target::*;
|
52
src/render/render_graph_2/draw_targets/ui_draw_target.rs
Normal file
52
src/render/render_graph_2/draw_targets/ui_draw_target.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
use crate::{
|
||||
asset::{AssetStorage, Mesh},
|
||||
legion::prelude::*,
|
||||
render::{
|
||||
render_graph_2::{RenderPass, resource_name, ResourceInfo},
|
||||
},
|
||||
};
|
||||
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
pub fn ui_draw_target(world: &World, render_pass: &mut dyn RenderPass) {
|
||||
let mut mesh_storage = world.resources.get_mut::<AssetStorage<Mesh>>().unwrap();
|
||||
// NOTE: this is ugly and borrowing is stupid
|
||||
let result = {
|
||||
let renderer = render_pass.get_renderer();
|
||||
let result = if let Some(ResourceInfo::InstanceBuffer { count, mesh_id, .. }) =
|
||||
renderer.get_resource_info(resource_name::buffer::UI_INSTANCES)
|
||||
{
|
||||
Some((*count, *mesh_id))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some((instance_count, mesh_id)) = result {
|
||||
if let Some(mesh_asset) = mesh_storage.get(mesh_id) {
|
||||
renderer.create_buffer_with_data(
|
||||
resource_name::buffer::TEMP_MESH_VERTEX_BUFFER_NAME,
|
||||
mesh_asset.vertices.as_bytes(),
|
||||
wgpu::BufferUsage::VERTEX,
|
||||
);
|
||||
renderer.create_buffer_with_data(
|
||||
resource_name::buffer::TEMP_MESH_INDEX_BUFFER_NAME,
|
||||
mesh_asset.indices.as_bytes(),
|
||||
wgpu::BufferUsage::INDEX,
|
||||
);
|
||||
Some((instance_count, mesh_asset.indices.len()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
};
|
||||
if let Some((instance_count, indices_length)) = result {
|
||||
render_pass.setup_bind_groups(None);
|
||||
render_pass.set_index_buffer(resource_name::buffer::TEMP_MESH_INDEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(0, resource_name::buffer::TEMP_MESH_VERTEX_BUFFER_NAME, 0);
|
||||
render_pass.set_vertex_buffer(1, resource_name::buffer::UI_INSTANCES, 0);
|
||||
render_pass.draw_indexed(0..indices_length as u32, 0, 0..(instance_count as u32));
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
pub mod pipelines;
|
||||
pub mod resource_name;
|
||||
pub mod wgpu_renderer;
|
||||
pub mod resource_provider;
|
||||
pub mod resource_providers;
|
||||
pub mod passes;
|
||||
pub mod draw_targets;
|
||||
pub mod renderers;
|
||||
mod resource;
|
||||
mod pipeline;
|
||||
mod pipeline_layout;
|
||||
|
|
|
@ -2,8 +2,9 @@ use crate::render::{
|
|||
Vertex,
|
||||
{
|
||||
render_graph_2::{
|
||||
ui_draw_target, pipeline_layout::*, PipelineDescriptor,
|
||||
pipeline_layout::*, PipelineDescriptor,
|
||||
RenderGraphBuilder,
|
||||
draw_targets::ui_draw_target,
|
||||
},
|
||||
shader::{Shader, ShaderStage},
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
legion::prelude::*,
|
||||
render::render_graph_2::{
|
||||
wgpu_renderer::DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo,
|
||||
resource::DynamicUniformBufferInfo, PipelineDescriptor, RenderGraph, ResourceInfo,
|
||||
TextureDescriptor,
|
||||
},
|
||||
};
|
||||
|
|
1
src/render/render_graph_2/renderers/mod.rs
Normal file
1
src/render/render_graph_2/renderers/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod wgpu_renderer;
|
|
@ -4,31 +4,11 @@ use crate::{
|
|||
resource_name, BindGroup, BindType, PassDescriptor, PipelineDescriptor, RenderGraph,
|
||||
RenderPass, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, Renderer, ResourceInfo, ShaderUniforms,
|
||||
TextureDescriptor,
|
||||
TextureDescriptor, DynamicUniformBufferInfo,
|
||||
},
|
||||
};
|
||||
use std::{collections::HashMap, ops::Deref};
|
||||
|
||||
pub struct DynamicUniformBufferInfo {
|
||||
pub indices: HashMap<usize, Entity>,
|
||||
pub offsets: HashMap<Entity, u64>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WgpuRenderer {
|
||||
pub device: wgpu::Device,
|
||||
pub queue: wgpu::Queue,
|
|
@ -1,3 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
use legion::prelude::Entity;
|
||||
|
||||
pub enum ResourceInfo {
|
||||
BufferMapped {
|
||||
size: u64,
|
||||
|
@ -15,4 +18,24 @@ pub enum ResourceInfo {
|
|||
mesh_id: usize,
|
||||
// pub layout: Option<
|
||||
},
|
||||
}
|
||||
|
||||
pub struct DynamicUniformBufferInfo {
|
||||
pub indices: HashMap<usize, Entity>,
|
||||
pub offsets: HashMap<Entity, u64>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,4 +11,6 @@ pub mod uniform {
|
|||
|
||||
pub mod buffer {
|
||||
pub const UI_INSTANCES: &str = "UiInstances";
|
||||
pub const TEMP_MESH_VERTEX_BUFFER_NAME: &str = "TempMeshVertexBuffer";
|
||||
pub const TEMP_MESH_INDEX_BUFFER_NAME: &str = "TempMeshIndexBuffer";
|
||||
}
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
},
|
||||
math::Vec4,
|
||||
render::render_graph_2::{
|
||||
wgpu_renderer::DynamicUniformBufferInfo, BindType, ResourceProvider, UniformPropertyType,
|
||||
resource::DynamicUniformBufferInfo, BindType, ResourceProvider, UniformPropertyType,
|
||||
},
|
||||
};
|
||||
use legion::{prelude::*, storage::Component};
|
||||
|
|
Loading…
Reference in a new issue