mirror of
https://github.com/bevyengine/bevy
synced 2024-11-24 21:53:07 +00:00
FrameTexture resource providers
This commit is contained in:
parent
8c831845f9
commit
aab7034e99
5 changed files with 56 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::render::render_graph_2::{
|
use crate::render::render_graph_2::{
|
||||||
resource_name, PassDescriptor, RenderGraphBuilder, RenderPassColorAttachmentDescriptor,
|
resource_name, PassDescriptor, RenderGraphBuilder, RenderPassColorAttachmentDescriptor,
|
||||||
RenderPassDepthStencilAttachmentDescriptor, TextureDescriptor, TextureDimension,
|
RenderPassDepthStencilAttachmentDescriptor, TextureDescriptor, TextureDimension,
|
||||||
|
FrameTexture,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait ForwardPassBuilder {
|
pub trait ForwardPassBuilder {
|
||||||
|
@ -9,13 +10,11 @@ pub trait ForwardPassBuilder {
|
||||||
|
|
||||||
impl ForwardPassBuilder for RenderGraphBuilder {
|
impl ForwardPassBuilder for RenderGraphBuilder {
|
||||||
fn add_forward_pass(self) -> Self {
|
fn add_forward_pass(self) -> Self {
|
||||||
self.add_texture(
|
self.add_resource_provider(Box::new(FrameTexture::new(resource_name::texture::DEPTH, TextureDescriptor {
|
||||||
resource_name::texture::DEPTH,
|
|
||||||
TextureDescriptor {
|
|
||||||
size: wgpu::Extent3d {
|
size: wgpu::Extent3d {
|
||||||
depth: 1,
|
depth: 1,
|
||||||
width: 2560,
|
width: 1,
|
||||||
height: 1440,
|
height: 1,
|
||||||
},
|
},
|
||||||
array_layer_count: 1,
|
array_layer_count: 1,
|
||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
|
@ -23,8 +22,7 @@ impl ForwardPassBuilder for RenderGraphBuilder {
|
||||||
dimension: TextureDimension::D2,
|
dimension: TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Depth32Float,
|
format: wgpu::TextureFormat::Depth32Float,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
},
|
})))
|
||||||
)
|
|
||||||
.add_pass(
|
.add_pass(
|
||||||
"main",
|
"main",
|
||||||
PassDescriptor {
|
PassDescriptor {
|
||||||
|
|
|
@ -156,6 +156,7 @@ impl From<TextureDimension> for wgpu::TextureDimension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct TextureDescriptor {
|
pub struct TextureDescriptor {
|
||||||
pub size: wgpu::Extent3d,
|
pub size: wgpu::Extent3d,
|
||||||
pub array_layer_count: u32,
|
pub array_layer_count: u32,
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub trait Renderer {
|
||||||
fn process_render_graph(&mut self, render_graph: &mut RenderGraph, world: &mut World);
|
fn process_render_graph(&mut self, render_graph: &mut RenderGraph, world: &mut World);
|
||||||
// TODO: swap out wgpu::BufferUsage for non-wgpu type
|
// 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_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(&self, name: &str) -> Option<&DynamicUniformBufferInfo>;
|
||||||
fn get_dynamic_uniform_buffer_info_mut(
|
fn get_dynamic_uniform_buffer_info_mut(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{render::{
|
use crate::{render::{
|
||||||
render_graph_2::{resource_name, Renderer},
|
render_graph_2::{resource_name, Renderer, TextureDescriptor},
|
||||||
ActiveCamera, Camera, Light, LightRaw,
|
ActiveCamera, Camera, Light, LightRaw,
|
||||||
}, transform::prelude::Translation};
|
}, transform::prelude::Translation};
|
||||||
use bevy_transform::prelude::LocalToWorld;
|
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) {}
|
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::<winit::window::Window>().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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -489,7 +489,7 @@ impl Renderer for WgpuRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, texture_descriptor) in render_graph.queued_textures.drain(..) {
|
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();
|
let mut encoder = self.encoder.take().unwrap();
|
||||||
|
@ -643,8 +643,9 @@ impl Renderer for WgpuRenderer {
|
||||||
.insert(name.to_string(), info);
|
.insert(name.to_string(), info);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_texture(&mut self, name: &str, texture_descriptor: TextureDescriptor) {
|
fn create_texture(&mut self, name: &str, texture_descriptor: &TextureDescriptor) {
|
||||||
let texture = self.device.create_texture(&texture_descriptor.into());
|
let descriptor: wgpu::TextureDescriptor = (*texture_descriptor).into();
|
||||||
|
let texture = self.device.create_texture(&descriptor);
|
||||||
self.textures
|
self.textures
|
||||||
.insert(name.to_string(), texture.create_default_view());
|
.insert(name.to_string(), texture.create_default_view());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue