librashader/librashader-presets/src/preset.rs

92 lines
2 KiB
Rust
Raw Normal View History

use crate::error::ParsePresetError;
use std::convert::Infallible;
use std::path::PathBuf;
use std::str::FromStr;
2022-11-14 16:14:05 +11:00
use librashader::{FilterMode, WrapMode};
#[repr(i32)]
2022-10-21 13:52:34 +11:00
#[derive(Default, Copy, Clone, Debug)]
pub enum ScaleType {
#[default]
Input = 0,
Absolute,
Viewport,
}
2022-10-21 13:52:34 +11:00
#[derive(Copy, Clone, Debug)]
pub enum ScaleFactor {
Float(f32),
Absolute(i32),
}
impl Default for ScaleFactor {
fn default() -> Self {
ScaleFactor::Float(1.0f32)
}
}
impl FromStr for ScaleType {
type Err = ParsePresetError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"source" => Ok(ScaleType::Input),
"viewport" => Ok(ScaleType::Viewport),
"absolute" => Ok(ScaleType::Absolute),
_ => Err(ParsePresetError::InvalidScaleType(s.to_string())),
}
}
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
pub struct Scaling {
pub scale_type: ScaleType,
pub factor: ScaleFactor,
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
pub struct Scale2D {
pub valid: bool,
pub x: Scaling,
pub y: Scaling,
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
2022-10-22 12:04:00 +11:00
pub struct ShaderPassConfig {
2022-10-21 13:52:34 +11:00
pub id: i32,
pub name: PathBuf,
pub alias: Option<String>,
pub filter: FilterMode,
pub wrap_mode: WrapMode,
2022-10-20 17:26:21 +11:00
pub frame_count_mod: u32,
pub srgb_framebuffer: bool,
pub float_framebuffer: bool,
pub mipmap_input: bool,
pub scaling: Scale2D,
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
pub struct TextureConfig {
pub name: String,
pub path: PathBuf,
pub wrap_mode: WrapMode,
2022-10-21 13:52:34 +11:00
pub filter_mode: FilterMode,
pub mipmap: bool,
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
2022-10-22 12:04:00 +11:00
pub struct ParameterConfig {
pub name: String,
pub value: f32,
}
2022-10-21 13:52:34 +11:00
#[derive(Debug, Clone)]
2022-10-22 12:04:00 +11:00
pub struct ShaderPreset {
2022-10-21 13:52:34 +11:00
pub shader_count: i32,
pub feedback_pass: i32,
// Everything is in Vecs because the expect number of values is well below 64.
2022-10-22 12:04:00 +11:00
pub shaders: Vec<ShaderPassConfig>,
pub textures: Vec<TextureConfig>,
2022-10-22 12:04:00 +11:00
pub parameters: Vec<ParameterConfig>,
}