1 unstable release
0.1.0 | Mar 22, 2020 |
---|
#1066 in Graphics APIs
53 downloads per month
1MB
32K
SLoC
isf
Parsing, deserialization and serialization of ISF - the Interactive Shader Format.
Implementation is as described under "The ISF Specification Vsn 2.0" part of the spec site.
The parse function can parse a given GLSL string to produce an Isf instance. The Isf type represents a fully structured representation of the format, including typed Inputs.
Tests
The repo includes all shaders from the "ISF Test/Tutorial filters" collection provided by the specification site along with all shaders within the "Vidvox/ISF-Files" repository for automated testing. These tests do a full roundtrip on every shader in the following steps:
- Read the GLSL string from file.
- Parse the GLSL string for the top-level dictionary.
- Deserialize the JSON to an
Isf
struct. - Serialize the
Isf
struct back to a JSON string. - Deserialize the new JSON string to an
Isf
struct again. - Assert the first
Isf
instance is identical to the second.
Thanks to the Vidvox crew for allowing us to include these tests in the repo for easy automated testing!
Example
Parsing a GLSL string to an ISF struct looks like this:
let isf = isf::parse(&glsl_str).unwrap();
See the Isf
struct docs to
get an idea of what you can do with it!
Here's a copy of the tests/roundtrip.rs
test as described above:
let test_files_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("test_files");
assert!(test_files_path.exists());
assert!(test_files_path.is_dir());
for entry in std::fs::read_dir(test_files_path).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
let ext = path.extension().and_then(|s| s.to_str());
if ext == Some("fs") || ext == Some("vs") {
let glsl_str = std::fs::read_to_string(&path).unwrap();
let isf = match isf::parse(&glsl_str) {
// Ignore non-ISF vertex shaders.
Err(isf::ParseError::MissingTopComment) if ext == Some("vs") => continue,
Err(err) => panic!("err while parsing {}: {}", path.display(), err),
Ok(isf) => isf,
};
let isf_string = serde_json::to_string_pretty(&isf).unwrap();
let isf2 = serde_json::from_str(&isf_string).unwrap();
assert_eq!(isf, isf2);
}
}
About
This crate has been developed as a step towards creating an ISF live-coding environment based on nannou, the creative coding framework.
Dependencies
~0.7–1.6MB
~35K SLoC