From c4f60e2634cab4616d4a7ab347ab3cd2d22f8912 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 7 May 2024 00:13:14 +0200 Subject: [PATCH] separate clear_bg pass --- kubi/src/rendering.rs | 30 ++++-------------------------- kubi/src/rendering/background.rs | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 kubi/src/rendering/background.rs diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index a7caa31..5593aae 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,4 +1,4 @@ -use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, SystemModificator, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator}; +use shipyard::{AllStoragesViewMut, IntoIter, IntoWorkload, Unique, UniqueView, UniqueViewMut, View, Workload, WorkloadModificator}; use winit::dpi::PhysicalSize; use glam::Vec3; use crate::{events::WindowResizedEvent, state::is_ingame}; @@ -6,8 +6,7 @@ use crate::{events::WindowResizedEvent, state::is_ingame}; mod renderer; pub use renderer::Renderer; -use self::{camera::CameraUniformBuffer, world::WorldRenderState}; - +pub mod background; pub mod world; pub mod camera; pub mod depth; @@ -58,39 +57,18 @@ pub fn render_master(storages: AllStoragesViewMut) { let surface_texture = renderer.surface().get_current_texture().unwrap(); let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default()); - { - let bg = storages.borrow::>().unwrap().0; - let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("rpass_background"), - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &surface_view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color { - r: bg.x as f64, - g: bg.y as f64, - b: bg.z as f64, - a: 1.0, - }), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - ..Default::default() - }); - } - let mut data = RenderCtx { renderer: &renderer, encoder: &mut encoder, surface_view: &surface_view, }; + storages.run_with_data(background::clear_bg, &mut data); if storages.run(is_ingame) { storages.run_with_data(world::draw_world, &mut data); } - renderer.queue().submit(std::iter::once(encoder.finish())); + renderer.queue().submit([encoder.finish()]); surface_texture.present(); } diff --git a/kubi/src/rendering/background.rs b/kubi/src/rendering/background.rs new file mode 100644 index 0000000..29240d2 --- /dev/null +++ b/kubi/src/rendering/background.rs @@ -0,0 +1,25 @@ +use shipyard::UniqueView; +use super::{BackgroundColor, RenderCtx}; + +pub fn clear_bg( + ctx: &mut RenderCtx, + bg: UniqueView, +) { + let _rpass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("clear_bg"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: ctx.surface_view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: bg.0.x as f64, + g: bg.0.y as f64, + b: bg.0.z as f64, + a: 1.0, + }), + store: wgpu::StoreOp::Store, + }, + })], + ..Default::default() + }); +}