add resource providers to render_graph
This commit is contained in:
parent
2226292ce0
commit
7b89531268
@ -1,10 +1,11 @@
|
||||
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor};
|
||||
use crate::render::render_graph_2::{PassDescriptor, PipelineDescriptor, ResourceProvider};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct RenderGraph {
|
||||
pub pipeline_descriptors: HashMap<String, PipelineDescriptor>,
|
||||
pub pass_descriptors: HashMap<String, PassDescriptor>,
|
||||
pub pass_pipelines: HashMap<String, Vec<String>>,
|
||||
pub resource_providers: Vec<Box<dyn ResourceProvider>>,
|
||||
}
|
||||
|
||||
impl Default for RenderGraph {
|
||||
@ -13,6 +14,7 @@ impl Default for RenderGraph {
|
||||
pipeline_descriptors: HashMap::new(),
|
||||
pass_descriptors: HashMap::new(),
|
||||
pass_pipelines: HashMap::new(),
|
||||
resource_providers: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,6 +57,11 @@ impl RenderGraphBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_resource_provider(mut self, resource_provider: Box<dyn ResourceProvider>) -> Self {
|
||||
self.render_graph.resource_providers.push(resource_provider);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> RenderGraph {
|
||||
self.render_graph
|
||||
}
|
||||
|
@ -1,19 +1,19 @@
|
||||
use crate::render::{render_graph_2::Renderer, ActiveCamera, Camera};
|
||||
use bevy_transform::prelude::LocalToWorld;
|
||||
use legion::prelude::*;
|
||||
use zerocopy::AsBytes;
|
||||
use std::mem;
|
||||
use zerocopy::AsBytes;
|
||||
|
||||
trait ResourceProvider {
|
||||
fn update(renderer: &mut dyn Renderer, world: &mut World);
|
||||
fn resize(renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32);
|
||||
pub trait ResourceProvider {
|
||||
fn update(&self, renderer: &mut dyn Renderer, world: &mut World);
|
||||
fn resize(&self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32);
|
||||
}
|
||||
|
||||
pub struct CameraResourceProvider;
|
||||
|
||||
impl ResourceProvider for CameraResourceProvider {
|
||||
fn update(renderer: &mut dyn Renderer, world: &mut World) {}
|
||||
fn resize(renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) {
|
||||
fn update(&self, renderer: &mut dyn Renderer, world: &mut World) {}
|
||||
fn resize(&self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) {
|
||||
for (mut camera, local_to_world, _) in
|
||||
<(Write<Camera>, Read<LocalToWorld>, Read<ActiveCamera>)>::query().iter_mut(world)
|
||||
{
|
||||
@ -22,7 +22,8 @@ impl ResourceProvider for CameraResourceProvider {
|
||||
(camera.view_matrix * local_to_world.0).to_cols_array_2d();
|
||||
let matrix_size = mem::size_of::<[[f32; 4]; 4]>() as u64;
|
||||
// TODO: use staging buffer?
|
||||
let buffer = renderer.create_buffer_with_data(camera_matrix.as_bytes(), wgpu::BufferUsage::UNIFORM);
|
||||
let buffer = renderer
|
||||
.create_buffer_with_data(camera_matrix.as_bytes(), wgpu::BufferUsage::UNIFORM);
|
||||
// let temp_camera_buffer = render_graph
|
||||
// .device
|
||||
// .create_buffer_with_data(camera_matrix.as_bytes(), wgpu::BufferUsage::COPY_SRC);
|
||||
|
Loading…
Reference in New Issue
Block a user