use rust-embed for assets

This commit is contained in:
Lauri Räsänen 2023-01-27 21:45:08 +02:00
parent a99b018ec1
commit 8947398ad0
11 changed files with 142 additions and 32 deletions

View file

@ -1,13 +1,12 @@
use wgpu;
use regex::Regex;
use std::fs::read_to_string;
use crate::core::resources::load_string;
pub fn preprocess_wgsl(filename: &str) -> wgpu::ShaderSource {
let source_path = env!("CARGO_MANIFEST_DIR").to_owned() + "/src/shaders/wgsl/" + filename;
let source_path = "shaders/".to_owned() + filename;
println!("preprocess_wgsl: loading source {}", source_path);
let mut source =
read_to_string(&source_path)
.unwrap();
let mut source = load_string(&source_path);
let re = Regex::new(r"#include (.*?)\n").unwrap();
for cap in re.captures_iter(&source.clone()) {
@ -16,7 +15,7 @@ pub fn preprocess_wgsl(filename: &str) -> wgpu::ShaderSource {
full_path = full_path.replace(filename, &cap[1]);
println!("preprocess_wgsl: replacing {} with file {}", whole_match, full_path);
let nested_source = read_to_string(full_path).unwrap();
let nested_source = load_string(&full_path);
source = source.replace(whole_match, &nested_source);
}