wgpu_mipmap/
core.rs

1use thiserror::Error;
2
3/// MipmapGenerator describes types that can generate mipmaps for a texture.
4pub trait MipmapGenerator {
5    /// Encodes commands to generate mipmaps for a texture.
6    ///
7    /// Expectations:
8    /// - `texture_descriptor` should be the same descriptor used to create the `texture`.
9    fn generate(
10        &self,
11        device: &wgpu::Device,
12        encoder: &mut wgpu::CommandEncoder,
13        texture: &wgpu::Texture,
14        texture_descriptor: &wgpu::TextureDescriptor,
15    ) -> Result<(), Error>;
16}
17
18/// An error that occurred during mipmap generation.
19#[derive(Debug, Error, PartialEq, Eq)]
20pub enum Error {
21    #[error("Unsupported texture usage `{0:?}`.\nYour texture usage must contain one of: 1. TextureUsage::STORAGE, 2. TextureUsage::OUTPUT_ATTACHMENT | TextureUsage::SAMPLED, 3. TextureUsage::COPY_SRC | TextureUsage::COPY_DST")]
22    UnsupportedUsage(wgpu::TextureUsage),
23    #[error(
24        "Unsupported texture dimension `{0:?}. You texture dimension must be TextureDimension::D2`"
25    )]
26    UnsupportedDimension(wgpu::TextureDimension),
27    #[error("Unsupported texture format `{0:?}`. Try using the render backend.")]
28    UnsupportedFormat(wgpu::TextureFormat),
29    #[error("Unsupported texture size. Texture size must be a power of 2.")]
30    NpotTexture,
31    #[error("Unknown texture format `{0:?}`.\nDid you mean to specify it in `MipmapGeneratorDescriptor::formats`?")]
32    UnknownFormat(wgpu::TextureFormat),
33}