mod private
{
use crate::*;
#[ derive( Clone ) ]
pub struct TextureDescriptor< 'a >
{
usage : u32,
size : [ u32; 3 ],
format : GpuTextureFormat,
label : Option< &'a str >,
dimension : Option< GpuTextureDimension>,
mip_level : Option< u32 >,
sample_count : Option< u32 >,
view_formats : Vec< GpuTextureFormat >
}
impl< 'a > TextureDescriptor< 'a >
{
pub fn new() -> Self
{
let format = web_sys::GpuTextureFormat::Rgba8unormSrgb;
let usage = 0;
let mip_level = None;
let sample_count = None;
let dimension = None;
let label = None;
let view_formats = Vec::new();
let size = [ 0, 0, 0 ];
TextureDescriptor
{
usage,
size,
format,
mip_level,
sample_count,
view_formats,
dimension,
label
}
}
pub fn size( mut self, size : [ u32; 3 ] ) -> Self
{
self.size = size;
self
}
pub fn format( mut self, format : GpuTextureFormat ) -> Self
{
self.format = format;
self
}
pub fn label( mut self, label : &'a str ) -> Self
{
self.label = Some( label );
self
}
pub fn mip_level( mut self, mip_level : u32 ) -> Self
{
self.mip_level = Some( mip_level );
self
}
pub fn sample_count( mut self, sample_count : u32 ) -> Self
{
self.sample_count = Some( sample_count );
self
}
pub fn dimension( mut self, dimension : GpuTextureDimension ) -> Self
{
self.dimension = Some( dimension );
self
}
pub fn view_formats( mut self, formats : &[ web_sys::GpuTextureFormat ] ) -> Self
{
self.view_formats.extend_from_slice( &formats );
self
}
pub fn copy_dst( mut self ) -> Self
{
self.usage |= web_sys::gpu_texture_usage::COPY_DST;
self
}
pub fn copy_src( mut self ) -> Self
{
self.usage |= web_sys::gpu_texture_usage::COPY_SRC;
self
}
pub fn render_attachment( mut self ) -> Self
{
self.usage |= web_sys::gpu_texture_usage::RENDER_ATTACHMENT;
self
}
pub fn storage_binding( mut self ) -> Self
{
self.usage |= web_sys::gpu_texture_usage::STORAGE_BINDING;
self
}
pub fn texture_binding( mut self ) -> Self
{
self.usage |= web_sys::gpu_texture_usage::TEXTURE_BINDING;
self
}
pub fn create
(
self,
device : &web_sys::GpuDevice
) -> Result< web_sys::GpuTexture, WebGPUError >
{
texture::create( device, &self.into() )
}
}
impl From< TextureDescriptor< '_ > > for web_sys::GpuTextureDescriptor
{
fn from( value: TextureDescriptor< '_ > ) -> Self
{
let desc = web_sys::GpuTextureDescriptor::new
(
value.format,
&Vec::from( value.size ).into(),
value.usage
);
if let Some( v ) = value.mip_level { desc.set_mip_level_count( v ); }
if let Some( v ) = value.sample_count { desc.set_sample_count( v ); }
if let Some( v ) = value.dimension { desc.set_dimension( v ); }
if let Some( v ) = value.label { desc.set_label( v ); }
if value.view_formats.len() > 0
{
let view_formats : Vec< u32 > = value.view_formats.into_iter().map( | f | f as u32 ).collect();
desc.set_view_formats( &view_formats.into() );
}
desc
}
}
}
crate::mod_interface!
{
exposed use
{
TextureDescriptor
};
}