use crate::camera::Camera;
use crate::gpu::GpuContext;
pub struct RenderTarget {
pub texture: wgpu::Texture,
pub view: wgpu::TextureView,
width: u32,
height: u32,
}
impl RenderTarget {
pub fn new(gpu: &GpuContext, label: &str) -> Self {
let texture = gpu.device.create_texture(&wgpu::TextureDescriptor {
label: Some(label),
size: wgpu::Extent3d {
width: gpu.width(),
height: gpu.height(),
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: gpu.config.format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Self {
texture,
view,
width: gpu.width(),
height: gpu.height(),
}
}
pub fn ensure_size(&mut self, gpu: &GpuContext, label: &str) {
if self.width != gpu.width() || self.height != gpu.height() {
*self = Self::new(gpu, label);
}
}
}
pub struct RenderContext<'a> {
pub gpu: &'a GpuContext,
pub encoder: &'a mut wgpu::CommandEncoder,
pub time: f32,
pub camera: &'a Camera,
}