From 25f0cd31c4d1c26623fe4d84e82f71a7231b2b2a Mon Sep 17 00:00:00 2001 From: chyyran Date: Tue, 18 Oct 2022 01:07:38 -0400 Subject: [PATCH] presets: initial structs for representing presets --- .gitignore | 1 + src/.idea/.gitignore | 8 +++ src/.idea/modules.xml | 8 +++ src/.idea/src.iml | 11 +++ src/.idea/vcs.xml | 6 ++ src/Cargo.lock | 7 ++ src/librashader-presets/src/lib.rs | 15 +--- src/librashader-presets/src/preset.rs | 100 ++++++++++++++++++++++++++ 8 files changed, 143 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100644 src/.idea/.gitignore create mode 100644 src/.idea/modules.xml create mode 100644 src/.idea/src.iml create mode 100644 src/.idea/vcs.xml create mode 100644 src/Cargo.lock create mode 100644 src/librashader-presets/src/preset.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8fda6b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/src/target/ diff --git a/src/.idea/.gitignore b/src/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/src/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml new file mode 100644 index 0000000..f669a0e --- /dev/null +++ b/src/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/.idea/src.iml b/src/.idea/src.iml new file mode 100644 index 0000000..c8a0e01 --- /dev/null +++ b/src/.idea/src.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/.idea/vcs.xml b/src/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/src/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Cargo.lock b/src/Cargo.lock new file mode 100644 index 0000000..127d8fd --- /dev/null +++ b/src/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "librashader-presets" +version = "0.1.0" diff --git a/src/librashader-presets/src/lib.rs b/src/librashader-presets/src/lib.rs index 7d12d9a..663d783 100644 --- a/src/librashader-presets/src/lib.rs +++ b/src/librashader-presets/src/lib.rs @@ -1,14 +1,3 @@ -pub fn add(left: usize, right: usize) -> usize { - left + right -} +mod preset; -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } -} +pub use preset::*; diff --git a/src/librashader-presets/src/preset.rs b/src/librashader-presets/src/preset.rs new file mode 100644 index 0000000..f58e632 --- /dev/null +++ b/src/librashader-presets/src/preset.rs @@ -0,0 +1,100 @@ +use std::collections::HashSet; +use std::convert::Infallible; +use std::path::PathBuf; +use std::str::FromStr; + +#[repr(C)] +pub enum FilterMode { + Linear, + Nearest, + Unspecified +} + +#[repr(C)] +pub enum WrapMode { + ClampToBorder, + ClampToEdge, + Repeat, + MirroredRepeat, +} + +#[repr(C)] +pub enum ScaleType { + Input, + Absolute, + Viewport +} + +impl FromStr for WrapMode { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + Ok(match s { + "clamp_to_border" => WrapMode::ClampToBorder, + "clamp_to_edge" => WrapMode::ClampToEdge, + "repeat" => WrapMode::Repeat, + "mirrored_repeat" => WrapMode::MirroredRepeat, + _ => WrapMode::ClampToBorder + }) + } +} + +impl FromStr for ScaleType { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + Ok(match s { + "source" => ScaleType::Input, + "viewport" => ScaleType::Viewport, + "absolute" => ScaleType::Absolute, + _ => ScaleType::Input + }) + } +} + +pub enum ScaleFactor { + Float(f32), + Absolute(i32) +} + +pub struct Scaling { + pub scale_type: ScaleType, + pub factor: ScaleFactor +} + +pub struct Scale2D { + pub x: Scaling, + pub y: Scaling +} + +pub struct ShaderConfig { + pub name: String, + pub alias: String, + pub filter: FilterMode, + pub wrap_mode: WrapMode, + pub frame_count_mod: usize, + pub srgb_framebuffer: bool, + pub float_framebuffer: bool, + pub mipmap_input: bool, + pub scaling: Scale2D +} + +pub struct TextureConfig { + pub name: String, + pub path: PathBuf, + pub wrap_mode: WrapMode, + pub filter: FilterMode, + pub mipmap: bool +} + +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, + pub textures: Vec, + pub parameters: Vec +} \ No newline at end of file