Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for using shadergarden through standard input and piping #12

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ lexpr = "0.2.6"
include_dir = "0.6"
ffmpeg-next = { version = "4.4", optional = true }
structopt = "0.3"

[target.'cfg(unix)'.dependencies]
signal-hook = "0.3.14"
20 changes: 20 additions & 0 deletions src/lisp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ fn node(
)?;
Ok(Val::Node(node_id))
},
"shader-inline" => {
let (src, width, height, inputs) = shader(graph, env, iter)?;
let node_id = graph.add_shader(
&src,
inputs,
width as u32,
height as u32,
)?;
Ok(Val::Node(node_id))
},
"shader-param" => {
// get the shader we'll be running the transformations
// against
Expand Down Expand Up @@ -262,6 +272,16 @@ fn node(
)?;
Ok(Val::Node(node_id))
},
"shader-rec-inline" => {
let (src, width, height, inputs) = shader(graph, env, iter)?;
let node_id = graph.add_rec_shader(
&src,
inputs,
width as u32,
height as u32,
)?;
Ok(Val::Node(node_id))
},
"extern" => {
let (name, inputs) = external(graph, env, iter)?;
let adder = env.external(&name)?;
Expand Down
14 changes: 2 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ use glium::{
Surface,
};
use shadergarden::{
lisp,
map,
png,
reload,
util,
reload::watcher::ShaderGraphWatcher
};
use structopt::{
clap::AppSettings,
Expand Down Expand Up @@ -166,16 +165,7 @@ fn render(render: Render) {
);

// set up hot code reloading
let shader_dir = reload::ShaderDir::new_from_dir(args.project, lisp_config)
.expect("Could not load initial shader directory");
let mut graph =
lisp::graph_from_sexp(display.get_context(), shader_dir, map! {})
.map_err(|e| {
eprintln!("[fatal] Could not build initial graph:");
eprintln!("{}", e);
panic!();
})
.unwrap();
let mut graph = ShaderGraphWatcher::build_initial(display.get_context(), &args.project, &lisp_config).unwrap();

eprintln!("[info] Built initial graph");

Expand Down
12 changes: 4 additions & 8 deletions src/reload/shader_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,12 @@ impl ShaderDir {
}

/// Creates a new `ShaderDir` from a directory.
pub fn new_from_dir<T>(path: T, config: T) -> Result<ShaderDir, String>
pub fn new_from_dir<T>(path: T, get_lisp : impl Fn() -> Result<String, String>) -> Result<ShaderDir, String>
where
T: AsRef<Path>,
{
let lisp = fs::read_to_string(&config).map_err(|_| {
format!(
"Could not read `{}` in shader directory",
config.as_ref().to_str().unwrap()
)
})?;

let lisp = get_lisp()?;

let mut shaders = BTreeMap::new();
let files = fs::read_dir(path)
Expand Down Expand Up @@ -106,4 +102,4 @@ impl ShaderDir {

Ok(ShaderDir { lisp, shaders })
}
}
}
Loading