Skip to main content

pebble/wgpu/
mod.rs

1pub mod cubemap;
2pub mod material;
3pub mod material_instance;
4pub mod samplers;
5pub mod textures;
6
7pub struct BindingEntry {
8    pub name: &'static str,
9    pub kind: BindingKind,
10}
11
12pub enum BindingKind {
13    Texture,
14    /// `texture_2d_array<f32>` in WGSL — a texture with multiple layers
15    /// sampled by index, e.g. a texture atlas or a per-instance layer
16    /// lookup. Bind the whole array as one resource; select the layer in
17    /// the shader.
18    TextureArray,
19    Sampler,
20    Buffer,
21    TextureCubemap,
22}
23
24impl BindingEntry {
25    pub fn texture(name: &'static str) -> Self {
26        Self {
27            name,
28            kind: BindingKind::Texture,
29        }
30    }
31
32    pub fn sampler(name: &'static str) -> Self {
33        Self {
34            name,
35            kind: BindingKind::Sampler,
36        }
37    }
38
39    pub fn buffer(name: &'static str) -> Self {
40        Self {
41            name,
42            kind: BindingKind::Buffer,
43        }
44    }
45
46    pub fn cubemap(name: &'static str) -> Self {
47        Self {
48            name,
49            kind: BindingKind::TextureCubemap,
50        }
51    }
52
53    pub fn texture_array(name: &'static str) -> Self {
54        Self {
55            name,
56            kind: BindingKind::TextureArray,
57        }
58    }
59
60    pub fn layout_entry(&self, binding: u32) -> wgpu::BindGroupLayoutEntry {
61        match self.kind {
62            BindingKind::Texture => wgpu::BindGroupLayoutEntry {
63                binding,
64                visibility: wgpu::ShaderStages::FRAGMENT,
65                ty: wgpu::BindingType::Texture {
66                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
67                    view_dimension: wgpu::TextureViewDimension::D2,
68                    multisampled: false,
69                },
70                count: None,
71            },
72            BindingKind::Sampler => wgpu::BindGroupLayoutEntry {
73                binding,
74                visibility: wgpu::ShaderStages::FRAGMENT,
75                ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
76                count: None,
77            },
78            BindingKind::Buffer => wgpu::BindGroupLayoutEntry {
79                binding,
80                visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
81                ty: wgpu::BindingType::Buffer {
82                    ty: wgpu::BufferBindingType::Uniform,
83                    has_dynamic_offset: false,
84                    min_binding_size: None,
85                },
86                count: None,
87            },
88            BindingKind::TextureCubemap => wgpu::BindGroupLayoutEntry {
89                binding,
90                visibility: wgpu::ShaderStages::FRAGMENT,
91                ty: wgpu::BindingType::Texture {
92                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
93                    view_dimension: wgpu::TextureViewDimension::Cube,
94                    multisampled: false,
95                },
96                count: None,
97            },
98            BindingKind::TextureArray => wgpu::BindGroupLayoutEntry {
99                binding,
100                visibility: wgpu::ShaderStages::FRAGMENT,
101                ty: wgpu::BindingType::Texture {
102                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
103                    view_dimension: wgpu::TextureViewDimension::D2Array,
104                    multisampled: false,
105                },
106                count: None,
107            },
108        }
109    }
110}