use crate::Framework;
pub mod buffers;
pub mod images;
pub trait BufOps<'fw, T>
where
T: bytemuck::Pod,
{
fn capacity(&self) -> u64 {
self.size() / std::mem::size_of::<T>() as u64
}
fn size(&self) -> u64;
fn as_binding_resource(&self) -> wgpu::BindingResource {
self.as_gpu_buffer().as_entire_binding()
}
fn as_gpu_buffer(&self) -> &wgpu::Buffer;
fn with_capacity(fw: &'fw Framework, capacity: u64) -> Self;
fn from_slice(fw: &'fw Framework, slice: &[T]) -> Self;
fn from_gpu_parts(fw: &'fw Framework, buf: wgpu::Buffer, size: u64) -> Self;
fn into_gpu_parts(self) -> (wgpu::Buffer, u64);
}
pub trait ImgOps<'fw> {
fn as_binding_resource(&self) -> wgpu::BindingResource;
fn as_gpu_texture(&self) -> &wgpu::Texture;
fn get_wgpu_extent3d(&self) -> wgpu::Extent3d;
fn dimensions(&self) -> (u32, u32);
fn new(fw: &'fw Framework, width: u32, height: u32) -> Self;
fn from_bytes(fw: &'fw Framework, data: &[u8], width: u32, height: u32) -> Self;
fn from_gpu_parts(
fw: &'fw Framework,
texture: wgpu::Texture,
dimensions: wgpu::Extent3d,
) -> Self;
fn into_gpu_parts(self) -> (wgpu::Texture, wgpu::Extent3d);
}
pub trait PixelInfo {
fn byte_size() -> usize;
fn wgpu_format() -> wgpu::TextureFormat;
fn wgpu_texture_sample() -> wgpu::TextureSampleType;
}
macro_rules! pixel_info_impl {
($($name:ident, $size:expr, $format:expr, $sample:expr, #[$doc:meta]);+) => {
use crate::primitives::PixelInfo;
$(
#[$doc]
pub struct $name;
impl PixelInfo for $name {
fn byte_size() -> usize {
$size
}
fn wgpu_format() -> wgpu::TextureFormat {
$format
}
fn wgpu_texture_sample() -> wgpu::TextureSampleType {
$sample
}
}
)+
};
}
pub mod pixels {
pixel_info_impl! {
Rgba8Uint, 4, wgpu::TextureFormat::Rgba8Uint, wgpu::TextureSampleType::Uint, #[doc = "Red, green, blue, and alpha channels. 8 bit integer per channel. Unsigned in shader."];
Rgba8UintNorm, 4, wgpu::TextureFormat::Rgba8Unorm, wgpu::TextureSampleType::Float { filterable: false }, #[doc = "Red, green, blue, and alpha channels. 8 bit integer per channel. [0, 255] converted to/from float [0, 1] in shader."];
Rgba8Sint, 4, wgpu::TextureFormat::Rgba8Sint, wgpu::TextureSampleType::Sint, #[doc = "Red, green, blue, and alpha channels. 8 bit integer per channel. Signed in shader."];
Rgba8SintNorm, 4, wgpu::TextureFormat::Rgba8Snorm, wgpu::TextureSampleType::Float { filterable: false }, #[doc = "Red, green, blue, and alpha channels. 8 bit integer per channel. [-127, 127] converted to/from float [-1, 1] in shader."]
}
}