feo_oop_engine/graphics/
pass_builder.rs

1
2use std::sync::Arc;
3
4use vulkano::{command_buffer::{AutoCommandBufferBuilder, SubpassContents, pool::standard::StandardCommandPoolBuilder}, framebuffer::FramebufferAbstract, sync::GpuFuture};
5use feo_math::{linear_algebra::matrix4::Matrix4, utils::space::Space};
6use super::frame_system::FrameSystem;
7
8/// Represents the active process of rendering a frame.
9///
10/// This struct mutably borrows the `FrameSystem`.
11pub struct PassBuilder<'p> {
12    pub(crate) system: &'p mut FrameSystem,
13
14    // Future to wait upon before the main rendering.
15    pub(crate) before_main_cb_future: Option<Box<dyn GpuFuture>>,
16    // Framebuffer that was used when starting the render pass.
17    pub(crate) framebuffer: Arc<dyn FramebufferAbstract + Send + Sync>,
18    // The command buffer builder that will be built during the lifetime of this object.
19    pub(crate) command_buffer_builder: Option<AutoCommandBufferBuilder<StandardCommandPoolBuilder>>,
20    // Matrix that converts screen coordinates and depth buffer values to coordinates in camera space
21    pub(crate) screen_to_camera: Matrix4<f32>,
22    // Matrix that converts ident to camera space
23    pub(crate) to_camera_space: Space,
24}
25
26impl<'p> PassBuilder<'p>{
27    /// Returns an enumeration containing the next pass of the rendering.
28    pub fn build/*<'b>*/(&/*'b*/ mut self) -> Box<dyn GpuFuture> {
29        // passes
30    //     self.draw_pass();
31    //     self.lighting_pass();
32    //     self.render_pass()
33    // }
34
35    // #[inline]
36    // fn draw_pass<'b>(&'b mut self) {
37        let command_buffer = self.system.draw_pass_manager.draw();
38        self.command_buffer_builder.as_mut().unwrap()
39            .execute_commands(command_buffer).unwrap();
40    // }
41    
42    // #[inline]
43    // fn lighting_pass<'b>(&'b mut self) {
44        self.command_buffer_builder.as_mut().unwrap()
45            .next_subpass(SubpassContents::SecondaryCommandBuffers).unwrap();
46        
47        let lighting_pass_manager = self.system.lighting_pass_manager.clone();
48        lighting_pass_manager.draw(self);
49    // }
50    
51    // #[inline]
52    // fn render_pass<'b>(&'b mut self) -> Box<dyn GpuFuture> {
53        self.command_buffer_builder
54            .as_mut()
55            .unwrap()
56            .end_render_pass()
57            .unwrap();
58        let command_buffer = self.command_buffer_builder.take().unwrap().build().unwrap();
59        
60        // Extract `before_main_cb_future` and append the command buffer execution to it.
61        let after_main_cb = self
62            .before_main_cb_future.take().unwrap()
63            .then_execute(self.system.gfx_queue.clone(), command_buffer).unwrap();
64        // We obtain `after_main_cb`, which we give to the user.
65        Box::new(after_main_cb)
66    }
67}