pebble-engine 0.9.5

A modular, ECS-style graphics/app framework for Rust.
Documentation
pub mod cubemap;
pub mod material;
pub mod material_instance;
pub mod samplers;
pub mod textures;

pub struct BindingEntry {
    pub name: &'static str,
    pub kind: BindingKind,
}

pub enum BindingKind {
    Texture,
    /// `texture_2d_array<f32>` in WGSL — a texture with multiple layers
    /// sampled by index, e.g. a texture atlas or a per-instance layer
    /// lookup. Bind the whole array as one resource; select the layer in
    /// the shader.
    TextureArray,
    Sampler,
    /// `sampler_comparison` in WGSL — a sampler used with
    /// `textureSampleCompare`, e.g. shadow-map testing. Distinct from a
    /// regular [`Sampler`](BindingKind::Sampler) binding at the wgpu level
    /// (`SamplerBindingType::Comparison` vs `Filtering`); pair with a
    /// [`SamplerKind`](crate::wgpu::samplers::SamplerKind) comparison
    /// variant (e.g. `CompareLess`) when building the actual sampler.
    ComparisonSampler,
    Buffer,
    TextureCubemap,
}

impl BindingEntry {
    pub fn texture(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::Texture,
        }
    }

    pub fn sampler(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::Sampler,
        }
    }

    pub fn buffer(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::Buffer,
        }
    }

    pub fn cubemap(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::TextureCubemap,
        }
    }

    pub fn texture_array(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::TextureArray,
        }
    }

    pub fn comparison_sampler(name: &'static str) -> Self {
        Self {
            name,
            kind: BindingKind::ComparisonSampler,
        }
    }

    pub fn layout_entry(&self, binding: u32) -> wgpu::BindGroupLayoutEntry {
        match self.kind {
            BindingKind::Texture => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::FRAGMENT,
                ty: wgpu::BindingType::Texture {
                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
                    view_dimension: wgpu::TextureViewDimension::D2,
                    multisampled: false,
                },
                count: None,
            },
            BindingKind::Sampler => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::FRAGMENT,
                ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                count: None,
            },
            BindingKind::Buffer => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::VERTEX_FRAGMENT,
                ty: wgpu::BindingType::Buffer {
                    ty: wgpu::BufferBindingType::Uniform,
                    has_dynamic_offset: false,
                    min_binding_size: None,
                },
                count: None,
            },
            BindingKind::TextureCubemap => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::FRAGMENT,
                ty: wgpu::BindingType::Texture {
                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
                    view_dimension: wgpu::TextureViewDimension::Cube,
                    multisampled: false,
                },
                count: None,
            },
            BindingKind::TextureArray => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::FRAGMENT,
                ty: wgpu::BindingType::Texture {
                    sample_type: wgpu::TextureSampleType::Float { filterable: true },
                    view_dimension: wgpu::TextureViewDimension::D2Array,
                    multisampled: false,
                },
                count: None,
            },
            BindingKind::ComparisonSampler => wgpu::BindGroupLayoutEntry {
                binding,
                visibility: wgpu::ShaderStages::FRAGMENT,
                ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison),
                count: None,
            },
        }
    }
}