diff --git a/src/render/render_graph_2/passes/forward.rs b/src/render/render_graph_2/passes/forward.rs index 75a34af845..b57991ba95 100644 --- a/src/render/render_graph_2/passes/forward.rs +++ b/src/render/render_graph_2/passes/forward.rs @@ -1,6 +1,7 @@ use crate::render::render_graph_2::{ resource_name, PassDescriptor, RenderGraphBuilder, RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor, TextureDescriptor, TextureDimension, + FrameTexture, }; pub trait ForwardPassBuilder { @@ -9,22 +10,19 @@ pub trait ForwardPassBuilder { impl ForwardPassBuilder for RenderGraphBuilder { fn add_forward_pass(self) -> Self { - self.add_texture( - resource_name::texture::DEPTH, - TextureDescriptor { - size: wgpu::Extent3d { - depth: 1, - width: 2560, - height: 1440, - }, - array_layer_count: 1, - mip_level_count: 1, - sample_count: 1, - dimension: TextureDimension::D2, - format: wgpu::TextureFormat::Depth32Float, - usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + self.add_resource_provider(Box::new(FrameTexture::new(resource_name::texture::DEPTH, TextureDescriptor { + size: wgpu::Extent3d { + depth: 1, + width: 1, + height: 1, }, - ) + array_layer_count: 1, + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: wgpu::TextureFormat::Depth32Float, + usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, + }))) .add_pass( "main", PassDescriptor { diff --git a/src/render/render_graph_2/pipeline_layout.rs b/src/render/render_graph_2/pipeline_layout.rs index beb5eeb2e7..d34bb6216a 100644 --- a/src/render/render_graph_2/pipeline_layout.rs +++ b/src/render/render_graph_2/pipeline_layout.rs @@ -156,6 +156,7 @@ impl From for wgpu::TextureDimension { } } +#[derive(Copy, Clone)] pub struct TextureDescriptor { pub size: wgpu::Extent3d, pub array_layer_count: u32, diff --git a/src/render/render_graph_2/renderer.rs b/src/render/render_graph_2/renderer.rs index d099c5b4a7..9825681b3d 100644 --- a/src/render/render_graph_2/renderer.rs +++ b/src/render/render_graph_2/renderer.rs @@ -19,7 +19,7 @@ pub trait Renderer { fn process_render_graph(&mut self, render_graph: &mut RenderGraph, world: &mut World); // TODO: swap out wgpu::BufferUsage for non-wgpu type fn create_buffer_with_data(&mut self, name: &str, data: &[u8], buffer_usage: wgpu::BufferUsage); - fn create_texture(&mut self, name: &str, texture_descriptor: TextureDescriptor); + fn create_texture(&mut self, name: &str, texture_descriptor: &TextureDescriptor); fn get_dynamic_uniform_buffer_info(&self, name: &str) -> Option<&DynamicUniformBufferInfo>; fn get_dynamic_uniform_buffer_info_mut( &mut self, diff --git a/src/render/render_graph_2/resource_provider.rs b/src/render/render_graph_2/resource_provider.rs index f443f203cf..0b5d3e4f8b 100644 --- a/src/render/render_graph_2/resource_provider.rs +++ b/src/render/render_graph_2/resource_provider.rs @@ -1,5 +1,5 @@ use crate::{render::{ - render_graph_2::{resource_name, Renderer}, + render_graph_2::{resource_name, Renderer, TextureDescriptor}, ActiveCamera, Camera, Light, LightRaw, }, transform::prelude::Translation}; use bevy_transform::prelude::LocalToWorld; @@ -133,3 +133,39 @@ impl ResourceProvider for LightResourceProvider { } fn resize(&mut self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) {} } + +pub struct FrameTexture { + pub name: String, + pub descriptor: TextureDescriptor, +} + +impl FrameTexture { + pub fn new(name: &str, descriptor: TextureDescriptor) -> Self { + FrameTexture { + name: name.to_string(), + descriptor, + } + } + + pub fn update(&mut self, renderer: &mut dyn Renderer, world: &World) { + let window = world.resources.get::().unwrap(); + let window_size = window.inner_size(); + self.descriptor.size.width = window_size.width; + self.descriptor.size.height = window_size.height; + renderer.create_texture(&self.name, &self.descriptor); + } +} + +impl ResourceProvider for FrameTexture { + fn initialize(&mut self, renderer: &mut dyn Renderer, world: &mut World) { + self.update(renderer, world); + } + + fn update(&mut self, renderer: &mut dyn Renderer, world: &mut World) { + + } + + fn resize(&mut self, renderer: &mut dyn Renderer, world: &mut World, width: u32, height: u32) { + self.update(renderer, world); + } +} \ No newline at end of file diff --git a/src/render/render_graph_2/wgpu_renderer.rs b/src/render/render_graph_2/wgpu_renderer.rs index 297ea215f8..3388a43283 100644 --- a/src/render/render_graph_2/wgpu_renderer.rs +++ b/src/render/render_graph_2/wgpu_renderer.rs @@ -489,7 +489,7 @@ impl Renderer for WgpuRenderer { } for (name, texture_descriptor) in render_graph.queued_textures.drain(..) { - self.create_texture(&name, texture_descriptor); + self.create_texture(&name, &texture_descriptor); } let mut encoder = self.encoder.take().unwrap(); @@ -643,8 +643,9 @@ impl Renderer for WgpuRenderer { .insert(name.to_string(), info); } - fn create_texture(&mut self, name: &str, texture_descriptor: TextureDescriptor) { - let texture = self.device.create_texture(&texture_descriptor.into()); + fn create_texture(&mut self, name: &str, texture_descriptor: &TextureDescriptor) { + let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).into(); + let texture = self.device.create_texture(&descriptor); self.textures .insert(name.to_string(), texture.create_default_view()); }