use std::sync::Arc;
pub struct CubeRenderTarget {
pub side: u32,
pub color_texture: wgpu::Texture,
pub face_views: Vec<wgpu::TextureView>,
pub cube_view: wgpu::TextureView,
pub depth_texture: wgpu::Texture,
pub depth_view: wgpu::TextureView,
pub format: wgpu::TextureFormat,
}
pub struct RenderTarget {
pub width: u32,
pub height: u32,
pub color_texture: wgpu::Texture,
pub color_view: wgpu::TextureView,
pub depth_texture: wgpu::Texture,
pub depth_view: wgpu::TextureView,
pub format: wgpu::TextureFormat,
}
impl RenderTarget {
pub(crate) fn depth_view_clone(&self) -> wgpu::TextureView {
self.depth_texture
.create_view(&wgpu::TextureViewDescriptor::default())
}
pub fn new_cube(
device: &Arc<wgpu::Device>,
side: u32,
format: wgpu::TextureFormat,
) -> CubeRenderTarget {
let size = wgpu::Extent3d {
width: side.max(1),
height: side.max(1),
depth_or_array_layers: 6,
};
let srgb_variant = format.add_srgb_suffix();
let extra_formats = if srgb_variant != format {
vec![srgb_variant]
} else {
vec![]
};
let color_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("threers cube rt color"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &extra_formats,
});
let mut face_views = Vec::with_capacity(6);
for face in 0..6_u32 {
let v = color_texture.create_view(&wgpu::TextureViewDescriptor {
label: Some("threers cube face view"),
dimension: Some(wgpu::TextureViewDimension::D2),
base_array_layer: face,
array_layer_count: Some(1),
..Default::default()
});
face_views.push(v);
}
let cube_view = color_texture.create_view(&wgpu::TextureViewDescriptor {
label: Some("threers cube combined view"),
dimension: Some(wgpu::TextureViewDimension::Cube),
format: Some(srgb_variant),
..Default::default()
});
let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("threers cube rt depth"),
size: wgpu::Extent3d {
width: side,
height: side,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Depth32Float,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});
let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
CubeRenderTarget {
side,
color_texture,
face_views,
cube_view,
depth_texture,
depth_view,
format,
}
}
pub fn new(
device: &Arc<wgpu::Device>,
width: u32,
height: u32,
format: wgpu::TextureFormat,
) -> Self {
let size = wgpu::Extent3d {
width: width.max(1),
height: height.max(1),
depth_or_array_layers: 1,
};
let srgb_variant = format.add_srgb_suffix();
let extra_formats = if srgb_variant != format {
vec![srgb_variant]
} else {
vec![]
};
let color_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("threers render target color"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC,
view_formats: &extra_formats,
});
let color_view = color_texture.create_view(&wgpu::TextureViewDescriptor::default());
let depth_texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("threers render target depth"),
size,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Depth32Float,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TEXTURE_BINDING
| wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
});
let depth_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default());
Self {
width,
height,
color_texture,
color_view,
depth_texture,
depth_view,
format,
}
}
}