feo_oop_engine/graphics/
lighting_pass_manager.rs1use std::{sync::{Arc, RwLock}};
2use vulkano::{device::Queue, framebuffer::{RenderPassAbstract, Subpass}};
3use crate::scene::game_object::light::{Light, ambient_light::AmbientLight, directional_light::DirectionalLight, point_light::PointLight};
4use super::{graphics_system::GraphicsSystem, pass_builder::PassBuilder};
5use crate::graphics::graphics_system::GraphicsSystemTrait;
6
7#[derive(Clone)]
9pub struct LightingPassManager{
10 pub(crate) lights: Vec<Arc<RwLock<dyn Light>>>,
11 light_systems: Vec<GraphicsSystem>,
12}
13
14impl LightingPassManager {
15 pub fn new<R>(gfx_queue: Arc<Queue>, subpass: Subpass<R>) -> LightingPassManager
17 where R: RenderPassAbstract + Send + Sync + Clone + 'static {
18 let light_systems = vec![
19 AmbientLight::new_system(gfx_queue.clone(), subpass.clone()),
20 DirectionalLight::new_system(gfx_queue.clone(), subpass.clone()),
21 PointLight::new_system(gfx_queue, subpass),
22 ];
23 LightingPassManager {
24 lights: Vec::new(),
25 light_systems,
26 }
27 }
28
29 #[inline]
31 pub fn clear(&mut self){
32 self.lights = Vec::new();
35 }
36
37 pub fn draw<'b>(&self, pass_manager: &'b mut PassBuilder) {
39 self.lights.clone().into_iter().for_each(|light| {
40 let light = light.read().unwrap();
41 light.pass(pass_manager, self.light_systems[light.get_system_num()].clone())
42 });
43 }
44}