master
Tom Gowan 6 years ago
parent 4694d4eb1d
commit 6eca607ca3

@ -8,12 +8,9 @@ edition = "2018"
notify = "4"
shaderc = "0.3"
spirv-reflect = "0.2"
vulkano = "0.11"
vulkano = { git = "https://github.com/mitchmindtree/vulkano", branch = "nannou_patches" }
[dev-dependencies]
vulkano = "0.11"
vulkano = { git = "https://github.com/mitchmindtree/vulkano", branch = "nannou_patches" }
color-backtrace = "0.1"
difference = "2"
[patch.crates-io]
vulkano = { git = "https://github.com/mitchmindtree/vulkano", branch = "nannou_patches" }

@ -1,5 +1,6 @@
use crate::vk;
use vk::pipeline::shader::*;
pub use vk::pipeline::shader::ShaderInterfaceDef;
use vk::descriptor::descriptor::*;
use vk::descriptor::pipeline_layout::*;
use crate::reflection::LayoutData;

@ -1,12 +1,12 @@
use std::sync::mpsc;
use crate::error::Error;
use crate::layouts::Entry;
use crate::CompiledShaders;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use std::path::{Path, PathBuf};
use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender};
use std::thread;
use std::time::Duration;
use std::path::{Path, PathBuf};
use crate::layouts::Entry;
use crate::CompiledShaders;
use std::sync::mpsc::{Sender, Receiver};
use crate::error::Error;
pub struct Watch {
_handler: Handler,
@ -26,18 +26,24 @@ pub struct Message {
impl Watch {
pub fn new<T>(vertex: T, fragment: T) -> Self
where
where
T: AsRef<Path>,
{
let (handler, rx) = create_watch(vertex.as_ref().to_path_buf(), fragment.as_ref().to_path_buf());
Watch{_handler: handler, rx}
{
let (handler, rx) = create_watch(
vertex.as_ref().to_path_buf(),
fragment.as_ref().to_path_buf(),
);
Watch {
_handler: handler,
rx,
}
}
}
impl Loader {
fn create(vertex: PathBuf, fragment: PathBuf) -> (Self, Receiver<Result<Message, Error>>) {
let (tx, rx) = mpsc::channel();
let loader = Loader{
let (tx, rx) = mpsc::channel();
let loader = Loader {
vertex,
fragment,
tx,
@ -50,8 +56,8 @@ impl Loader {
match crate::load(&self.vertex, &self.fragment) {
Ok(shaders) => {
let entry = crate::parse(&shaders);
self.tx.send(Ok(Message{ shaders, entry })).ok()
},
self.tx.send(Ok(Message { shaders, entry })).ok()
}
Err(e) => self.tx.send(Err(e)).ok(),
};
}
@ -72,8 +78,10 @@ impl Drop for Handler {
}
}
fn create_watch(vert_path: PathBuf, frag_path: PathBuf) -> (Handler, mpsc::Receiver<Result<Message, Error>>) {
fn create_watch(
vert_path: PathBuf,
frag_path: PathBuf,
) -> (Handler, mpsc::Receiver<Result<Message, Error>>) {
let (notify_tx, notify_rx) = mpsc::channel();
let (thread_tx, thread_rx) = mpsc::channel();
let mut watcher: RecommendedWatcher =
@ -86,14 +94,15 @@ fn create_watch(vert_path: PathBuf, frag_path: PathBuf) -> (Handler, mpsc::Recei
.watch(&frag_path, RecursiveMode::NonRecursive)
.expect("failed to add fragment shader to notify");
let (loader, rx) = Loader::create(vert_path, frag_path);
let handle = thread::spawn(move || 'watch_loop: loop {
if let Ok(_) = thread_rx.try_recv() {
break 'watch_loop;
}
if let Ok(notify::DebouncedEvent::Create(_)) = notify_rx.recv_timeout(Duration::from_secs(1)) {
if let Ok(notify::DebouncedEvent::Create(_)) =
notify_rx.recv_timeout(Duration::from_secs(1))
{
loader.reload();
}
});

Loading…
Cancel
Save