[oden] Writable Textures and re-work TS API
Now we return Texture objects to make things a little bit more type-safe, at the cost of a small allocation (I hope!)
This commit is contained in:
parent
12cc715873
commit
89045ccbcc
7 changed files with 287 additions and 24 deletions
|
|
@ -7,15 +7,46 @@ pub struct Texture {
|
|||
}
|
||||
|
||||
impl Texture {
|
||||
// pub fn from_bytes(
|
||||
// device: &wgpu::Device,
|
||||
// queue: &wgpu::Queue,
|
||||
// bytes: &[u8],
|
||||
// label: &str,
|
||||
// ) -> Result<Self> {
|
||||
// let img = image::load_from_memory(bytes)?;
|
||||
// Ok(Self::from_image(device, queue, &img, Some(label)))
|
||||
// }
|
||||
pub fn new_writable(
|
||||
device: &wgpu::Device,
|
||||
width: u32,
|
||||
height: u32,
|
||||
label: Option<&str>,
|
||||
) -> Self {
|
||||
let size = wgpu::Extent3d {
|
||||
width,
|
||||
height,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label,
|
||||
size,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8UnormSrgb,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
});
|
||||
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Nearest,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
Self {
|
||||
texture,
|
||||
view,
|
||||
sampler,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_image(
|
||||
device: &wgpu::Device,
|
||||
|
|
@ -31,6 +62,7 @@ impl Texture {
|
|||
height: dimensions.1,
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label,
|
||||
size,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue