mod private
{
use crate::*;
#[ derive( Clone ) ]
pub struct BindGroupLayoutDescriptor
{
auto_bindings : bool,
visibility : u32,
entries: Vec< web_sys::GpuBindGroupLayoutEntry >
}
impl BindGroupLayoutDescriptor
{
pub fn new() -> Self
{
let auto_bindings = false;
let visibility = 0;
let entries = Vec::new();
BindGroupLayoutDescriptor
{
auto_bindings,
visibility,
entries
}
}
pub fn auto_bindings( mut self ) -> Self
{
self.auto_bindings = true;
self
}
pub fn all( self ) -> Self
{
self.fragment().compute().vertex()
}
pub fn fragment( mut self ) -> Self
{
self.visibility |= web_sys::gpu_shader_stage::FRAGMENT;
self
}
pub fn vertex( mut self ) -> Self
{
self.visibility |= web_sys::gpu_shader_stage::VERTEX;
self
}
pub fn compute( mut self ) -> Self
{
self.visibility |= web_sys::gpu_shader_stage::COMPUTE;
self
}
pub fn entry( mut self, entry : impl Into< web_sys::GpuBindGroupLayoutEntry > ) -> Self
{
self.entries.push( entry.into() );
self
}
pub fn entry_from_ty( mut self, ty : impl Into< BindingType > ) -> Self
{
let entry = BindGroupLayoutEntry::new().ty( ty );
self.entries.push( entry.into() );
self
}
pub fn create( self, device : &web_sys::GpuDevice ) -> Result< web_sys::GpuBindGroupLayout, WebGPUError >
{
layout::bind_group::create( device, &self.into() )
}
}
impl From< BindGroupLayoutDescriptor > for web_sys::GpuBindGroupLayoutDescriptor
{
fn from( mut value: BindGroupLayoutDescriptor ) -> Self
{
let mut binding : u32 = 0;
for entry in value.entries.iter_mut()
{
if value.auto_bindings
{
entry.set_binding( binding );
binding += 1;
}
entry.set_visibility( entry.get_visibility() | value.visibility );
}
let layout = web_sys::GpuBindGroupLayoutDescriptor::new( &value.entries.into() );
layout
}
}
}
crate::mod_interface!
{
exposed use
{
BindGroupLayoutDescriptor
};
}