2022-10-20 13:47:43 +11:00
|
|
|
use crate::error::ParsePresetError;
|
2022-10-18 16:07:38 +11:00
|
|
|
use std::convert::Infallible;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
2022-10-20 13:47:43 +11:00
|
|
|
#[repr(i32)]
|
2022-10-20 16:59:15 +11:00
|
|
|
#[derive(Default, Debug)]
|
2022-10-18 16:07:38 +11:00
|
|
|
pub enum FilterMode {
|
2022-10-20 16:59:15 +11:00
|
|
|
#[default]
|
2022-10-20 13:47:43 +11:00
|
|
|
Linear = 0,
|
2022-10-18 16:07:38 +11:00
|
|
|
Nearest,
|
2022-10-20 13:47:43 +11:00
|
|
|
Unspecified,
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
2022-10-20 13:47:43 +11:00
|
|
|
#[repr(i32)]
|
2022-10-20 16:59:15 +11:00
|
|
|
#[derive(Default, Debug)]
|
2022-10-18 16:07:38 +11:00
|
|
|
pub enum WrapMode {
|
2022-10-20 16:59:15 +11:00
|
|
|
#[default]
|
2022-10-20 13:47:43 +11:00
|
|
|
ClampToBorder = 0,
|
2022-10-18 16:07:38 +11:00
|
|
|
ClampToEdge,
|
|
|
|
Repeat,
|
|
|
|
MirroredRepeat,
|
|
|
|
}
|
|
|
|
|
2022-10-20 13:47:43 +11:00
|
|
|
#[repr(i32)]
|
2022-10-20 16:59:15 +11:00
|
|
|
#[derive(Default, Debug)]
|
2022-10-18 16:07:38 +11:00
|
|
|
pub enum ScaleType {
|
2022-10-20 16:59:15 +11:00
|
|
|
#[default]
|
2022-10-20 13:47:43 +11:00
|
|
|
Input = 0,
|
2022-10-18 16:07:38 +11:00
|
|
|
Absolute,
|
2022-10-20 13:47:43 +11:00
|
|
|
Viewport,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ScaleFactor {
|
|
|
|
Float(f32),
|
|
|
|
Absolute(i32),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ScaleFactor {
|
|
|
|
fn default() -> Self {
|
|
|
|
ScaleFactor::Float(1.0f32)
|
|
|
|
}
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for WrapMode {
|
|
|
|
type Err = Infallible;
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
Ok(match s {
|
|
|
|
"clamp_to_border" => WrapMode::ClampToBorder,
|
|
|
|
"clamp_to_edge" => WrapMode::ClampToEdge,
|
|
|
|
"repeat" => WrapMode::Repeat,
|
|
|
|
"mirrored_repeat" => WrapMode::MirroredRepeat,
|
2022-10-20 13:47:43 +11:00
|
|
|
_ => WrapMode::ClampToBorder,
|
2022-10-18 16:07:38 +11:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromStr for ScaleType {
|
2022-10-20 13:47:43 +11:00
|
|
|
type Err = ParsePresetError;
|
2022-10-18 16:07:38 +11:00
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2022-10-20 13:47:43 +11:00
|
|
|
match s {
|
|
|
|
"source" => Ok(ScaleType::Input),
|
|
|
|
"viewport" => Ok(ScaleType::Viewport),
|
|
|
|
"absolute" => Ok(ScaleType::Absolute),
|
|
|
|
_ => Err(ParsePresetError::InvalidScaleType(s.to_string())),
|
|
|
|
}
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Scaling {
|
|
|
|
pub scale_type: ScaleType,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub factor: ScaleFactor,
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Scale2D {
|
2022-10-20 13:47:43 +11:00
|
|
|
pub valid: bool,
|
2022-10-18 16:07:38 +11:00
|
|
|
pub x: Scaling,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub y: Scaling,
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ShaderConfig {
|
2022-10-20 13:47:43 +11:00
|
|
|
pub id: usize,
|
2022-10-18 16:07:38 +11:00
|
|
|
pub name: String,
|
|
|
|
pub alias: String,
|
|
|
|
pub filter: FilterMode,
|
|
|
|
pub wrap_mode: WrapMode,
|
2022-10-20 17:26:21 +11:00
|
|
|
pub frame_count_mod: u32,
|
2022-10-18 16:07:38 +11:00
|
|
|
pub srgb_framebuffer: bool,
|
|
|
|
pub float_framebuffer: bool,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub feedback_pass: i32,
|
2022-10-18 16:07:38 +11:00
|
|
|
pub mipmap_input: bool,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub scaling: Scale2D,
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TextureConfig {
|
|
|
|
pub name: String,
|
|
|
|
pub path: PathBuf,
|
|
|
|
pub wrap_mode: WrapMode,
|
|
|
|
pub filter: FilterMode,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub mipmap: bool,
|
2022-10-18 16:07:38 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Parameter {
|
|
|
|
pub name: String,
|
|
|
|
pub value: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Preset {
|
|
|
|
// Everything is in Vecs because the expect number of values is well below 64.
|
|
|
|
pub shaders: Vec<ShaderConfig>,
|
|
|
|
pub textures: Vec<TextureConfig>,
|
2022-10-20 13:47:43 +11:00
|
|
|
pub parameters: Vec<Parameter>,
|
|
|
|
}
|