steamengine_renderer/
bind_group.rs1use std::num::NonZero;
2
3use wgpu::{BindingResource, BindingType, BufferBindingType, SamplerBindingType, ShaderStages};
4
5pub 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 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 pub fn on(mut self, visibility: ShaderStages) -> Self {
27 self.visibility = visibility;
28 self
29 }
30 pub fn of(mut self, ty: BindingType) -> Self {
32 self.ty = ty;
33 self
34 }
35 pub fn with(mut self, resource: BindingResource<'a>) -> Self {
37 self.resource = Some(resource);
38 self
39 }
40 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}