steamengine_renderer/
bind_group.rs

1use std::num::NonZero;
2
3use wgpu::{BindingResource, BindingType, BufferBindingType, SamplerBindingType, ShaderStages};
4
5/// this a builder for create a new bind group
6pub struct BindGroupEntryBuilder<'a> {
7    pub(crate) binding: u32,
8    pub(crate) visibility: ShaderStages,
9    pub(crate) ty: BindingType,
10    pub(crate) count: Option<NonZero<u32>>,
11    pub(crate) resource: Option<BindingResource<'a>>,
12}
13
14impl<'a> BindGroupEntryBuilder<'a> {
15    /// create a new builder with the binding number
16    pub fn new(binding: u32) -> Self {
17        Self {
18            binding,
19            visibility: ShaderStages::FRAGMENT,
20            ty: BindingType::Sampler(SamplerBindingType::Filtering),
21            count: None,
22            resource: None,
23        }
24    }
25    /// sets the visibility of the bind group
26    pub fn on(mut self, visibility: ShaderStages) -> Self {
27        self.visibility = visibility;
28        self
29    }
30    /// sets the type of the bind group
31    pub fn of(mut self, ty: BindingType) -> Self {
32        self.ty = ty;
33        self
34    }
35    /// sets the content of the bind group
36    pub fn with(mut self, resource: BindingResource<'a>) -> Self {
37        self.resource = Some(resource);
38        self
39    }
40    /// sets the count
41    pub fn has(mut self, count: NonZero<u32>) -> Self {
42        self.count = Some(count);
43        self
44    }
45    pub fn uniform(self) -> Self {
46        self.of(BindingType::Buffer {
47            ty: BufferBindingType::Uniform,
48            has_dynamic_offset: false,
49            min_binding_size: None,
50        })
51    }
52}