StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | //! Render pass management |
| 2 | //! |
| 3 | //! BLOCCO 6: Render Pass |
| 4 | //! Handles render pass setup and execution |
| 5 | |
| 6 | use wgpu::{ |
| 7 | CommandEncoder, LoadOp, Operations, RenderPass, RenderPassColorAttachment, |
| 8 | RenderPassDescriptor, StoreOp, TextureView, |
| 9 | }; |
| 10 | |
| 11 | /// Manages render pass configuration |
| 12 | pub struct RenderPassManager { |
| 13 | clear_color: wgpu::Color, |
| 14 | } |
| 15 | |
| 16 | impl RenderPassManager { |
| 17 | /// Create new render pass manager |
| 18 | pub fn new() -> Self { |
| 19 | Self { |
| 20 | clear_color: wgpu::Color { |
| 21 | r: 0.23, |
| 22 | g: 0.23, |
| 23 | b: 0.23, |
| 24 | a: 1.0, |
| 25 | }, |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /// Set clear color |
| 30 | pub fn set_clear_color(&mut self, color: wgpu::Color) { |
| 31 | self.clear_color = color; |
| 32 | } |
| 33 | |
| 34 | /// Begin render pass |
| 35 | /// |
| 36 | /// # Arguments |
| 37 | /// * `encoder` - Command encoder |
| 38 | /// * `view` - Target texture view |
| 39 | pub fn begin<'a>( |
| 40 | &self, |
| 41 | encoder: &'a mut CommandEncoder, |
| 42 | view: &'a TextureView, |
| 43 | ) -> RenderPass<'a> { |
| 44 | // TODO: Create render pass descriptor |
| 45 | // - Color attachment with clear color |
| 46 | // - LoadOp::Clear, StoreOp::Store |
| 47 | // - No depth/stencil |
| 48 | |
| 49 | encoder.begin_render_pass(&RenderPassDescriptor { |
| 50 | label: Some("Main Render Pass"), |
| 51 | color_attachments: &[Some(RenderPassColorAttachment { |
| 52 | view, |
| 53 | resolve_target: None, |
| 54 | ops: Operations { |
| 55 | load: LoadOp::Clear(self.clear_color), |
| 56 | store: StoreOp::Store, |
| 57 | }, |
| 58 | })], |
| 59 | depth_stencil_attachment: None, |
| 60 | timestamp_writes: None, |
| 61 | occlusion_query_set: None, |
| 62 | }) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | impl Default for RenderPassManager { |
| 67 | fn default() -> Self { |
| 68 | Self::new() |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #[cfg(test)] |
| 73 | mod tests { |
| 74 | use super::*; |
| 75 | |
| 76 | #[test] |
| 77 | fn test_default_clear_color() { |
| 78 | let render_pass_mgr = RenderPassManager::new(); |
| 79 | |
| 80 | // Default dark gray |
| 81 | assert_eq!(render_pass_mgr.clear_color.r, 0.23); |
| 82 | assert_eq!(render_pass_mgr.clear_color.g, 0.23); |
| 83 | assert_eq!(render_pass_mgr.clear_color.b, 0.23); |
| 84 | assert_eq!(render_pass_mgr.clear_color.a, 1.0); |
| 85 | } |
| 86 | |
| 87 | #[test] |
| 88 | fn test_set_clear_color() { |
| 89 | let mut render_pass_mgr = RenderPassManager::new(); |
| 90 | |
| 91 | let new_color = wgpu::Color { |
| 92 | r: 1.0, |
| 93 | g: 0.0, |
| 94 | b: 0.0, |
| 95 | a: 1.0, |
| 96 | }; |
| 97 | |
| 98 | render_pass_mgr.set_clear_color(new_color); |
| 99 | |
| 100 | assert_eq!(render_pass_mgr.clear_color.r, 1.0); |
| 101 | assert_eq!(render_pass_mgr.clear_color.g, 0.0); |
| 102 | } |
| 103 | } |
| 104 |